I have an array containing objects structured like this:
{
"date":"11/11/2014",
"time":"17.20.37",
"car":"396",
"driver":"Jenny",
"from":"Old Office",
"destination":"Log WH",
"pax":"3","comment":"",
"commenttime":"",
"arrival":"17.20.48",
"inserted":true,
"cancelled":"",
"duration":"00:00:11"
}
As I accumulate more data, my goal is to display statistics based on this information. For example:
November 2014 Car: 1, Number of trips: X, Time spent on the road: Y Car: 2, Number of trips: X, Time spent on the road: Y ...
October 2014 Car: 4, Number of trips: X, Time spent on the road: Y Car: 2, Number of trips: X, Time spent on the road: Y ...
I've managed to list unique month/year combinations in this way:
angular.forEach($scope.recordlist, function(record) {
var month = moment(record.date, 'DD-MM-YYYY').format('MMMM YYYY');
monthDict[month] = monthDict[month] || [];
monthDict[month].push(record);
});
for (record in monthDict) {
for (item in monthDict[record]) {
monthDict[record][item]['month'] = moment(record.date).format('MMMM YYYY');
}
};
$scope.monthlist = monthDict;
console.log($scope.monthlist);
This results in the following object structure:
Object
November 2014: Array[5]
0: Object
arrival: "17.21.27"
cancelled: ""
car: "396"
comment: ""
commenttime: ""
date: "11/11/2014"
destination: "Gumbo Market"
driver: "Erik"
duration: "00:00:17"
from: "Luna House"
inserted: true
month: "November 2014"
pax: "3"
time: "17.21.10"
totalduration: "00:00:38"
totaldurationdriver: "00:00:17"
Object1:
Object2:
Object3:
Object4:
October 2014: Array[1]
0: Object
...
In the view, I present it as follows:
<div ng-repeat="(key,val) in monthlist">
<div class="row msf-top-row">
<div class="col-md-12">
{{key}}
</div>
</div>
</div>
This already generates a list of unique months derived from the original object list.
Now, since each array in monthlist represents a trip, I want to apply a similar filtering process to extract unique properties within each month/year object. This will allow me to list the cars that were driven in each month, the number of trips taken by each car, and the total time spent on the road for each car (totalduration = "HH.mm.ss").
In essence, I aim to filter unique elements from a previously filtered list of unique elements.
Any guidance on how to approach this? My mind is racing just thinking about it..