Skip to content

Commit

Permalink
fix activities avgAvg and avgSum displays and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bretdavidson committed Jul 8, 2014
1 parent ebfb913 commit eeadcb6
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 187 deletions.
4 changes: 4 additions & 0 deletions analysis/reports/lib/php/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,10 @@ private function calculateAvg($countHash, $params)
{
$countHash['activitiesAvgAvg'][$activityID] = $activity['avg'] / $activity['divisor'];
}
elseif ($activity['avg'] / $activity['divisor'] === 0)
{
$countHash['activitiesAvgAvg'][$activityID] = 0;
}
}

// dailyHourSummary averages
Expand Down
91 changes: 24 additions & 67 deletions analysis/reports/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -49612,10 +49612,12 @@ angular.module('sumaAnalysis').factory('processTimeSeriesData', [
Friday: 5,
Saturday: 6
};
// Calculate percentage based on number and divisor
function calcPct(count, total) {
var pct = count / total * 100;
return _.isNaN(pct) ? 0 : pct.toFixed(2);
}
// Get counts of children recursively
function calcCount(obj, coll, prop) {
var hasChildren;
hasChildren = _.filter(coll, function (item) {
Expand All @@ -49633,69 +49635,42 @@ angular.module('sumaAnalysis').factory('processTimeSeriesData', [
return sum + num;
});
}
// Build array for locations/activities bar chart
function buildArray(source, response, total, trunc, pct) {
return _.filter(_.map(_.cloneDeep(source), function (o) {
o.name = o.title;
// Truncate flag
if (trunc) {
o.count = _.isNumber(response[o.id]) ? response[o.id].toFixed(2) : null;
} else {
if (o.type === 'activityGroup') {
o.count = null;
} else {
o.count = _.isNumber(response[o.id]) ? response[o.id] : null;
}
}
if (o.count !== null) {
o.percent = calcPct(o.count, total);
} else {
o.percent = null;
o.count = _.isNumber(response[o.id]) ? response[o.id] : null;
}
// Percentage flag
if (pct) {
o.count = o.percent;
o.count = calcPct(o.count, total);
}
return o;
}), function (obj) {
return obj.count !== null;
return obj.type !== 'activityGroup' && obj.count !== null;
});
}
// Build array for locations/activities table
function buildTableArray(source, response, total, flag) {
var counts;
counts = _.map(_.cloneDeep(source), function (loc) {
loc.name = loc.title;
loc.count = _.isNumber(response[loc.id]) ? response[loc.id] : null;
return loc;
counts = _.map(_.cloneDeep(source), function (o) {
o.name = o.title;
o.count = _.isNumber(response[o.id]) ? response[o.id] : null;
return o;
});
// Calculate counts for children
return _.map(counts, function (loc, index, coll) {
loc.count = calcCount(loc, coll, flag);
loc.percent = calcPct(loc.count, total);
return loc;
});
}
function insertNoActs(source, total, mode) {
var obj = {}, noActs;
noActs = _.find(source, function (item, key) {
return key === '_No Activity';
return _.map(counts, function (o, index, coll) {
o.count = calcCount(o, coll, flag);
o.percent = calcPct(o.count, total);
return o;
});
if (noActs) {
obj.name = 'No Activity';
obj.depth = 0;
obj.percent = (noActs / total * 100).toFixed(2);
if (mode === 'pct') {
obj.count = (noActs / total * 100).toFixed(2);
}
if (mode === 'sum') {
obj.count = noActs;
}
if (mode === 'avg') {
obj.count = noActs.toFixed(2);
}
return obj;
}
return false;
}
function processData(response, activities, locations, zeroCounts) {
var noActsSum, noActsAvgSum, noActsAvgAvg, counts, divisor;
var counts, divisor;
// Convert response into arrays of objects
counts = {};
// Configure divisor for avg/pct calculations
Expand All @@ -49707,17 +49682,17 @@ angular.module('sumaAnalysis').factory('processTimeSeriesData', [
// CSV
counts.csv = response.csv;
// Total Sum
counts.total = [{ count: response.total }];
counts.total = response.total;
// Total Counts
counts.totalCounts = [{ count: response.zeroDivisor }];
counts.totalCounts = response.zeroDivisor;
// Total Zero Counts
counts.totalZeroCounts = [{ count: response.zeroCounts }];
counts.totalZeroCounts = response.zeroCounts;
// Total Avg Sum
counts.totalAvgSum = [{ count: response.totalAvgSum }];
counts.totalAvgSum = response.totalAvgSum;
// Total AvgAvg
counts.totalAvgAvg = [{ count: response.totalAvgAvg }];
counts.totalAvgAvg = response.totalAvgAvg;
// Days with Observations
counts.daysWithObservations = [{ count: response.daysWithObservations }];
counts.daysWithObservations = response.daysWithObservations;
// Locations related data
counts.locationsTable = buildTableArray(locations, response.locationsSum, divisor, 'parent');
counts.locationsSum = buildArray(locations, response.locationsSum, divisor);
Expand All @@ -49730,21 +49705,6 @@ angular.module('sumaAnalysis').factory('processTimeSeriesData', [
counts.activitiesAvgSum = buildArray(activities, response.activitiesAvgSum, response.total, true);
counts.activitiesAvgAvg = buildArray(activities, response.activitiesAvgAvg, response.total, true);
counts.activitiesPct = buildArray(activities, response.activitiesSum, response.total, false, true);
// Handle insertion of no activity values
noActsSum = insertNoActs(response.activitiesSum, response.total, 'sum');
if (noActsSum) {
counts.activitiesSum.push(noActsSum);
counts.activitiesTable.push(noActsSum);
counts.activitiesPct.push(insertNoActs(response.activitiesSum, response.total, 'pct'));
}
noActsAvgSum = insertNoActs(response.activitiesAvgSum, response.total, 'avg');
if (noActsAvgSum) {
counts.activitiesAvgSum.push(noActsAvgSum);
}
noActsAvgAvg = insertNoActs(response.activitiesAvgAvg, response.total, 'avg');
if (noActsAvgAvg) {
counts.activitiesAvgAvg.push(noActsAvgAvg);
}
// Period Sum
counts.periodSum = _.sortBy(_.map(response.periodSum, function (element, index) {
return {
Expand Down Expand Up @@ -49872,9 +49832,6 @@ angular.module('sumaAnalysis').factory('processTimeSeriesData', [
return {
get: function (response, acts, locs, params) {
var dfd = $q.defer();
acts = _.filter(acts, function (act) {
return act.id !== 'all';
});
locs = _.filter(locs, function (loc) {
return loc.id !== 'all';
});
Expand Down
4 changes: 2 additions & 2 deletions analysis/reports/scripts/scripts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion analysis/reports/scripts/scripts.min.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions analysis/reports/views/timeSeries.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ <h3>Initiative Filters</h3>
<h3>Summary Data</h3>
<div>
<h4>Total Sum</h4>
<p>{{data.total[0].count | countFormat}}</p>
<p>{{data.total | countFormat}}</p>
<h4>Total # of Counts</h4>
<p>{{data.totalCounts[0].count | countFormat}}</p>
<p>{{data.totalCounts | countFormat}}</p>
<h4>Total # of Zero Counts</h4>
<p>{{data.totalZeroCounts[0].count | countFormat}}</p>
<p>{{data.totalZeroCounts | countFormat}}</p>
<h4>Avg of Sums</h4>
<p>{{data.totalAvgSum[0].count.toFixed(2) | countFormat}}</p>
<p>{{data.totalAvgSum.toFixed(2) | countFormat}}</p>
<h4>Avg of Avgs</h4>
<p>{{data.totalAvgAvg[0].count.toFixed(2) | countFormat}}</p>
<p>{{data.totalAvgAvg.toFixed(2) | countFormat}}</p>
<h4>Days with Observations</h4>
<p>{{data.daysWithObservations[0].count | countFormat}} (includes zero counts)</p>
<p>{{data.daysWithObservations | countFormat}} (includes zero counts)</p>
</div>
<div>
<h4>Totals by Location</h4>
Expand Down
4 changes: 4 additions & 0 deletions analysis/src/lib/php/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,10 @@ private function calculateAvg($countHash, $params)
{
$countHash['activitiesAvgAvg'][$activityID] = $activity['avg'] / $activity['divisor'];
}
elseif ($activity['avg'] / $activity['divisor'] === 0)
{
$countHash['activitiesAvgAvg'][$activityID] = 0;
}
}

// dailyHourSummary averages
Expand Down

0 comments on commit eeadcb6

Please sign in to comment.