@@ -27,35 +27,33 @@ let censusChart = function ($rootScope, $timeout) {
27
27
return ;
28
28
}
29
29
30
- // Gets the "CURRENT" snapshot of the given property (e.g. currentEnrolledCount, maxEnrollmentCount)
31
- var getCurrentCensusForProperty = function ( property ) {
30
+ var getCensusProperty = function ( property ) {
32
31
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 ;
34
34
} ) ;
35
35
36
36
var censusByTermCode = { } ;
37
+ let propertyTotalByTermCode = { } ;
37
38
38
39
sequenceFilteredCensus . forEach ( function ( courseCensus ) {
39
40
censusByTermCode [ courseCensus . termCode ] ? censusByTermCode [ courseCensus . termCode ] . push ( courseCensus ) : censusByTermCode [ courseCensus . termCode ] = [ courseCensus ] ;
40
41
} ) ;
41
42
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 ;
45
43
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 ] ;
48
47
return accumulator ;
49
- } , baseCensusObj ) ;
48
+ } , 0 ) ;
50
49
}
51
50
52
51
var lastFiveYears = Array . from ( [ 4 , 3 , 2 , 1 , 0 ] , function ( k ) { return moment ( ) . year ( ) - k ; } ) ; // eslint-disable-line no-undef
53
52
54
53
return lastFiveYears . map ( function ( year ) {
55
54
var termCode = year + ( scope . term . termCode + '' ) . slice ( - 2 ) ;
56
- var courseCensus = censusByTermCode [ termCode ] ;
57
55
58
- return courseCensus ? courseCensus [ property ] : 0 ;
56
+ return propertyTotalByTermCode [ termCode ] || 0 ;
59
57
} ) ;
60
58
} ;
61
59
@@ -72,7 +70,7 @@ let censusChart = function ($rootScope, $timeout) {
72
70
borderColor : "rgba(179,181,198,1)" ,
73
71
pointBackgroundColor : "rgba(179,181,198,1)" ,
74
72
pointBorderColor : "#fff" ,
75
- data : getCurrentCensusForProperty ( "maxEnrollmentCount" )
73
+ data : getCensusProperty ( "maxEnrollmentCount" )
76
74
} ,
77
75
{
78
76
label : "Enrollment" ,
@@ -81,7 +79,7 @@ let censusChart = function ($rootScope, $timeout) {
81
79
borderColor : "rgba(200,181,150,1)" ,
82
80
pointBackgroundColor : "rgba(200,181,150,1)" ,
83
81
pointBorderColor : "#fff" ,
84
- data : getCurrentCensusForProperty ( "currentEnrolledCount" )
82
+ data : getCensusProperty ( "currentEnrolledCount" )
85
83
}
86
84
] ;
87
85
0 commit comments