-
Notifications
You must be signed in to change notification settings - Fork 0
Data Model
Aim: allow to conveniently specify who should be allowed to open which door at what times.
(TODO come up with an awesome one)
The server will pre-compile the above into the following record for each door (and distribute it to the controllers):
for each door:
map of CardId -> { allowList :: [TimeSpec], denyList :: [TimeSpec] } where
timeSpec = { from [hh:mm], to [hh:mm], onWeekdays :: Bool, onWeekends :: Bool, onHolidays :: Bool }
- if this ISIC is not in the map: return "Denied"
- traverse this ISIC's
allowList; if a matching time entry is not found, return "Denied" - traverse this ISIC's
denyList; if a matching time entry is found, return "Denied" - return "Allowed"
Probably stored as a hash table, or maybe a sorted association list (+ binary search) if incremental updates aren't needed.
Assumption: People are lazy => there will not be many distinct time intervals set up.
Idea: Imagine the time intervals look e.g. like this:
Allow: |=================| |===========|
Allow: |====| |========|
Deny : |------|
Project all start and end times:
|...|....|.|..|...|....|....|...|.......|
Store one bit for each of these new intervals: should we allow entry during this time interval?
| 1 | 0 |0| 1| 1 | 0 | 1 | 1 | 1 |
Compile the allowList and denyList into three separate bitmasks like this (one for week days, one for weekends, one for holidays) according to the above algorithm. Also store the corresponding times. When querying whether a door should be opened, a simple binary search tells you which bit to look at; open the door iff it is set.