I am having a bit of trouble designing a new feature at the moment. It is part of a resource management system. I was wondering if anyone has experience doing anything similar.
I'll try to explain:
Resource: a Person, Place, or Thing
Availability Template (AT): allows you to define a standard availability pattern for a type of resource. e.g.: Mon-Fri 9-5.
Resource Additional Availability (AA): allows you to define one-off availability for a resource. e.g.: Bob's overtime 10-3 on Saturdays.
Resource Availability Exclusions (AE): allows you to define when a resource is not available. e.g: Room 4 is cleaned between 4-5 on Fridays.
It's easy enough to check whether or not a resource is available at a point in time: Availability = (AT(rID, time) || AA(rID, time)) && !AE(rID, time).
But I need to be able to query a resource's availability over a time period. i.e.: "Is Room 4 available at 9am for 2 hours on Thursday?".
So far, I have created an algorithm that "samples" the availability at a specific interval over the time period. However, this means that the returned availability lags the actual availability and some information might be missed.
E.g.: if I sample the availability every 15 minutes between 9 and 11, it would miss an exclusion between 9:05 and 9:10.
I could use a very small sampling period (eg: 1 minute) but that might not be performant and overall it is still quite an ugly brute-force approach.
Are there any standard patterns or algorithms for this type of problem?