Skip to content

Commit 4354856

Browse files
committed
count Laboratory sections as one
1 parent 0f3b024 commit 4354856

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

app/course/directives/censusChart.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,33 @@ let censusChart = function ($rootScope, $timeout) {
2727
return;
2828
}
2929

30-
// Gets the "CURRENT" snapshot of the given property (e.g. currentEnrolledCount, maxEnrollmentCount)
31-
var getCurrentCensusForProperty = function (property) {
30+
var getCensusProperty = function (property) {
3231
var sequenceFilteredCensus = scope.census.filter(function(courseCensus) {
33-
return courseCensus.sequenceNumber.includes(scope.sequencePattern);
32+
const isLaboratory = courseCensus.scheduleCode === 'C'; // count Laboratory sections as one course
33+
return courseCensus.sequenceNumber.includes(scope.sequencePattern) || isLaboratory;
3434
});
3535

3636
var censusByTermCode = {};
37+
let propertyTotalByTermCode = {};
3738

3839
sequenceFilteredCensus.forEach(function(courseCensus) {
3940
censusByTermCode[courseCensus.termCode] ? censusByTermCode[courseCensus.termCode].push(courseCensus) : censusByTermCode[courseCensus.termCode] = [courseCensus];
4041
});
4142

42-
for (var termCode in censusByTermCode) {
43-
var baseCensusObj = censusByTermCode[termCode].length > 0 ? JSON.parse(JSON.stringify(censusByTermCode[termCode][0])) : null;
44-
baseCensusObj[property] = 0;
4543

46-
censusByTermCode[termCode] = censusByTermCode[termCode].reduce(function(accumulator, currentValue) {
47-
accumulator[property] += currentValue[property];
44+
for (const termCode in censusByTermCode) {
45+
propertyTotalByTermCode[termCode] = censusByTermCode[termCode].reduce(function(accumulator, currentValue) {
46+
accumulator += currentValue[property];
4847
return accumulator;
49-
}, baseCensusObj);
48+
}, 0);
5049
}
5150

5251
var lastFiveYears = Array.from([4, 3, 2, 1, 0], function (k) { return moment().year() - k; }); // eslint-disable-line no-undef
5352

5453
return lastFiveYears.map(function(year) {
5554
var termCode = year + (scope.term.termCode + '').slice(-2);
56-
var courseCensus = censusByTermCode[termCode];
5755

58-
return courseCensus ? courseCensus[property] : 0;
56+
return propertyTotalByTermCode[termCode] || 0;
5957
});
6058
};
6159

@@ -72,7 +70,7 @@ let censusChart = function ($rootScope, $timeout) {
7270
borderColor: "rgba(179,181,198,1)",
7371
pointBackgroundColor: "rgba(179,181,198,1)",
7472
pointBorderColor: "#fff",
75-
data: getCurrentCensusForProperty("maxEnrollmentCount")
73+
data: getCensusProperty("maxEnrollmentCount")
7674
},
7775
{
7876
label: "Enrollment",
@@ -81,7 +79,7 @@ let censusChart = function ($rootScope, $timeout) {
8179
borderColor: "rgba(200,181,150,1)",
8280
pointBackgroundColor: "rgba(200,181,150,1)",
8381
pointBorderColor: "#fff",
84-
data: getCurrentCensusForProperty("currentEnrolledCount")
82+
data: getCensusProperty("currentEnrolledCount")
8583
}
8684
];
8785

0 commit comments

Comments
 (0)