After performing this action, I end up with an array that organizes the data by month and day of the date, but not by year. This grouping is done to calculate the maximum, minimum, and average values for each available data point.
The issue arises from the fact that the array contains 2-3 values for a specific day and month under the key value of the date. Each of these indices holds an array of length one, which references an object containing the necessary data point (level). The object includes three attributes: date, id (which is always null), and level as a float.
I am looking for a way to either directly store the object within those indices or allow _.each to access the level attribute.
Any suggestions?
var groupedData = _.groupBy(data, "date");
var groupedLevels = _.groupBy(groupedData, function (points, date) {
var dateParsed = parseDate(date);
var month = dateParsed.getMonth();
var day = dateParsed.getDate();
var monthDay = month + "-" + day;
return monthDay;
});
_.each(groupedLevels, function (points, date) {
var levels = _.map(_.pluck(points, "level"), parseFloat);
minimum.push([ date, R.min(levels) ]);
maximum.push([ date, R.max(levels);
var averageLevel = R.sum(levels) / levels.length;
average.push([date, averageLevel]);
})
The original input data looks like this:
[ { date: "2009-01-01",
id: null,
level: "0.08",
},
// ...
]
Currently, groupedData appears as follows:
{ "2009-01-01":
[ { date: "2009-01-01",
id: null,
level: "0.08"
}
],
// ...
}
An example structure of groupedLevels is shown below:
{ "0-1":
[ [ { date: "2009-01-01".
id: null,
level: "0.08"
}
],
// ...
],
// ...
}
My goal is to eliminate the arrays of length one and directly store the object instead.