I have a list of Map objects that look something like this:
year => 2016, month => 10, day => 11, count => 123 I have an element for every day in the range of startDate < endDate.
I want to be able to reduce these elements into different temporal groupings based on the interval between startDate and endDate. If the difference between startDate and endDate is greater than 4 years, I want to group them into years. If the difference is less than four years, but greater than a year, I want to group them into months. If it's less than a year, but greater than a month, I want to group into weeks. Anything less than a month, no grouping necessary.
When I say "group" I mean I want to sum up the count elements for everything that belongs to a particular year (using the first example above), and return a single map for each year that looks like this:
year => 2016, month => 1 day => 1 count => 9897 I know there must be an elegant way to accomplish this, but I'm having a difficult time wrapping my brain around the logic.