Skip to content
AnotherKamila edited this page Dec 7, 2014 · 6 revisions

Aim: allow to conveniently specify who should be allowed to open which door at what times.

Do not read this yet, it will all change (for the better) once I know what I am doing.

Also, it is out of date and speaks of irrelevant stuff. See Controller Behavior if you have nothing better to do.

Model:

(TODO come up with an awesome one)

What the door gets

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 }

Deciding algorithm:

  • 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"

Implementation

Map

Probably stored as a hash table, or maybe a sorted association list (+ binary search) if incremental updates aren't needed. The values won't actually be the data itself, but pointers to shared structures, because e.g. almost all students will share the same access.

Time Intervals

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.

Clone this wiki locally