Temporal Projections

Does anyone have any views on the best way to approach creating projections that aggregate based on time?

For example say I have events being stored for each visit to a url. How can I write a projection that enables plotting the number of visits per unit time say 5 mins?

Do I create a projection that holds an ever expanding array of 5 minute counts? or as a flavor of this create a stream of events (say one event per day) which contain an array of the 5 min values? I would have to deal with the present (would need to hold off emitting an event until a 5 min window is complete).

Do I create a new stream for each 5 min period and then one to reduce them into a single projection?

Is it an option to persist a timing event every 5 seconds and aggregate all events between timing events?

Cheers

Matt

Have you considered adding an event that represents time? Eg a one minute passed event?

Hi Greg, would you mind elaborating? I think I see what you are suggesting but an example would help.

Cheers

Matt

Matt,

What if you store as a projection state only visits for the last time unit and emit an event into output stream every time you encounter an event from another (next) time unit. The event that triggered write will for a new projection state for the next time period.

The outlined approach will not write zeros for periods of silence, brut as Greg suggested you can fix it by writing a TimeUnitPassed event every 5 minutes or so.

-yuriy

Thanks for the reply Yuriy. I will give this approach a try. A couple of questions:

If I changed my mind and wanted 1 minute resolution what would my options be? Is it possible to create a new stream of 1 min events and then use fromStream(x,y) to combine? Do you have any examples of using fromStream(x,y,z)?

Cheers

Matt

Matt,

  1. you can either reprocess all the data into similar streams with higher resolution, or if you start with 1 minute you easily aggregate them into 5 minute resolution with another projection.

  2. note that actual syntax is

fromStreams([“stream1”, “stream2”])

i.e.: the name is plural fromStreams and it takes single array argument

  1. I think I miss the idea of combining 1-min and 5-min resolution streams.

-yuriy