Given a collection of events, aggregate their duration weekly. Fill gaps to contain every week since the earliest event.
Users have meetings.
Duration Aggregated Weekly
The following aggregation matches any documents that belong to a user, groups and sorts them by year and week number, then counts and sums their durations.
The code above will miss any week without data. It’s easier to fill those in Ruby by iterating over weeks, starting with the current week and finishing with the week of the oldest available data.
See weekly_meetings.rb for a complete implementation.