This is a modification of a previously asked question (In javascript, how do I extract the month from date string "yyyy-mm-dd" or timeStamp?), which was solved nicely by @mhodges.
Because of the nature of the modification, I thought it would be appropriate to just create a new question.
I have a database with certain logged events as json objects, each one with it's own JS millisecond timestamp and also a date string in the format "yyyy-mm-dd", as well as a minutes entry.
I'd like to use the timestamp as input into an algorithm which will count how many logs were entered in a given month and year.
I would also like the algorithm to sum the cumulative number of minutes were logged in a given month and year.
For example,
log1: {
Date:"2017-05-24",
TimeStamp:1495612800,
Minutes: 15},
log2: {
Date:"2017-05-19",
TimeStamp:1495180800,
Minutes: 45},
log3: {
Date:"2017-04-24",
TimeStamp:1493020800,
Minutes:30},
log4: {
Date:"2016-08-15",
TimeStamp:1471248000,
Minutes:75}
In this example, the algorithm would count that there are two logs in the month of May 2017, one log in the month of April 2017 and one log in the month of August 2016.
The algorithm would also return a sum of 60 minutes in the month of May 2017, 30 minutes in the month of April 2017 and 75 minutes in August 2016.
Any help with modifying the solution that @mhodges provided previously (see (In javascript, how do I extract the month from date string "yyyy-mm-dd" or timeStamp?)), into the appropriate nested output would be greatly appreciated!
I am having trouble modifying @mhodges solution to achieve it, but envision something like this:
{
"2016":{
"8": {
occurrences: 1,
minutes: 75
}
},
"2017":{
"4": {
occurrences: 1,
minutes: 30
},
"5": {
occurrences: 2,
minutes: 60
}
}
}
Thanks