2013-03-07 11:07:59 -05:00
|
|
|
/**
|
|
|
|
Get the y value of a report data point by its index. Negative indexes start from the end.
|
|
|
|
|
|
|
|
@method reportValueY
|
|
|
|
@for Handlebars
|
|
|
|
**/
|
|
|
|
Handlebars.registerHelper('valueAtDaysAgo', function(property, i) {
|
|
|
|
var data = Ember.Handlebars.get(this, property);
|
|
|
|
if( data ) {
|
2013-03-12 10:38:54 -04:00
|
|
|
var wantedDate = Date.create(i + ' days ago', 'en').format('{yyyy}-{MM}-{dd}');
|
2013-03-09 15:53:30 -05:00
|
|
|
var item = data.find( function(d, i, arr) { return d.x === wantedDate; } );
|
2013-03-07 11:07:59 -05:00
|
|
|
if( item ) {
|
|
|
|
return item.y;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sum the given number of data points from the report, starting at the most recent.
|
|
|
|
|
|
|
|
@method sumLast
|
|
|
|
@for Handlebars
|
|
|
|
**/
|
|
|
|
Handlebars.registerHelper('sumLast', function(property, numDays) {
|
|
|
|
var data = Ember.Handlebars.get(this, property);
|
|
|
|
if( data ) {
|
2013-03-12 10:38:54 -04:00
|
|
|
var earliestDate = Date.create(numDays + ' days ago', 'en');
|
2013-03-07 11:07:59 -05:00
|
|
|
var sum = 0;
|
|
|
|
data.each(function(d){
|
|
|
|
if(Date.create(d.x) >= earliestDate) {
|
|
|
|
sum += d.y;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
});
|