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.
- Default – only displayed when no events are current
- Events – only displayed when primary events are current
- 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
- Event alpha | 10:30 – 14:30
- Event bravo | 14:00 – 16:00
- Event charlie | 18:30 – 20:00
Secondary Events
- Event zulu | 00:00 – 23:59 | default
- Event yankee | 09:00 – 11:00 | default
- Event xray | 09:00 – 11:30 | events
- 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.
3
So heres what I did in the end, rather than looping through each minute of each day and checking what should be showing I created a list of all the start and stop times (in one single list) then removed duplicates and sorted them in order.
This way I can just cycled through that array and that will give me the start/end times when things change.