jeudi 26 février 2015

How to efficiently determine when changes occur in event lists


We have a system that stores event information. There is a primary list of events as well as a secondary list, these may overlap. Secondary lists are combined with the primary based on 3 main rules.



  1. Default - only displayed when no events are current

  2. Events - only displayed when primary events are current

  3. Override - displayed in stead of events


A new 3rd party system we have to integrate with means we need to get each of the different states throughout the days of what events/secondary events should be showing. Eg, from 9-5 these events are current based on the timings/ rules, but then after 5 these events are current based on the timings and rules.


A simple example


Primary Events



  1. Event alpha | 10:30 - 14:30

  2. Event bravo | 14:00 - 16:00

  3. Event charlie | 18:30 - 20:00


Secondary Events



  1. Event zulu | 00:00 - 23:59 | default

  2. Event yankee | 09:00 - 11:00 | default

  3. Event xray | 09:00 - 11:30 | events

  4. Event whiskey | 19:00 - 19:15 | override


Just on this very small example this would result as the following lists that we would need to generate


00:00-09:00 Event zulu


09:00-10:30 Event zulu Event yankee


10:30-11:30 Event alpha Event xray


11:30-14:00 Event alpha


14:00-14:30 Event alpha Event bravo


14:30-16:00 Event bravo


16:00-18:30 Event zulu


18:30-19:00 Event charlie


19:00-19:15 Event whiskey


19:15-20:00 Event charlie


20:00-23:59 Event zulu


This is a tiny example in production there is usually hundreds to thousands of events over many days. At present the only end points deal with this problem dynamically on the fly, this third party system requires we provide the data in this way.


It's all written in php, and we have the primary and secondary event lists in an array each.


What is the most efficient way of making these lists ?


We have considered doing a minute by minute check, but this seems horribly inefficient and I'm hoping there is a better way.





Aucun commentaire:

Enregistrer un commentaire