@@ -203,10 +203,11 @@ func gradesAggregation(flag string, c *gin.Context) {
203203 {Key : "subject_prefix" , Value : prefix },
204204 {Key : "course_number" , Value : number },
205205 }
206- // Parse the queried document into the sample course
206+
207207 err = courseCollection .FindOne (ctx , sampleCourseFind ).Decode (& sampleCourse )
208- // If the error is not that there is no matching documents, throw an internal server error
209208 if err != nil && ! errors .Is (err , mongo .ErrNoDocuments ) {
209+ // If the error is not that there is no matching documents,
210+ // throw an internal server error
210211 respondWithInternalError (c , err )
211212 return
212213 }
@@ -216,24 +217,25 @@ func gradesAggregation(flag string, c *gin.Context) {
216217 typeRegexes := [14 ]string {"0[0-9][0-9]" , "0W[0-9]" , "0H[0-9]" , "0L[0-9]" , "5H[0-9]" , "1[0-9][0-9]" , "2[0-9][0-9]" , "3[0-9][0-9]" , "5[0-9][0-9]" , "6[0-9][0-9]" , "7[0-9][0-9]" , "HN[0-9]" , "HON" , "[0-9]U[0-9]" }
217218 typeStrings := [14 ]string {"0xx" , "0Wx" , "0Hx" , "0Lx" , "5Hx" , "1xx" , "2xx" , "3xx" , "5xx" , "6xx" , "7xx" , "HNx" , "HON" , "xUx" }
218219
219- var branches []bson.D // for without section pipeline
220- var withSectionBranches []bson.D // for with section pipeline
220+ var branches [14 ]bson.D // for without-section pipeline
221+ var withSectionBranches [14 ]bson.D // for with-section pipeline
222+
221223 for i , typeRegex := range typeRegexes {
222- branches = append ( branches , bson.D {
224+ branches [ i ] = bson.D {
223225 {Key : "case" , Value : bson.D {{Key : "$regexMatch" , Value : bson.D {
224226 {Key : "input" , Value : "$sections.section_number" },
225227 {Key : "regex" , Value : typeRegex },
226228 }}}},
227229 {Key : "then" , Value : typeStrings [i ]},
228- })
230+ }
229231
230- withSectionBranches = append ( withSectionBranches , bson.D {
232+ withSectionBranches [ i ] = bson.D {
231233 {Key : "case" , Value : bson.D {{Key : "$regexMatch" , Value : bson.D {
232234 {Key : "input" , Value : "$section_number" },
233235 {Key : "regex" , Value : typeRegex },
234236 }}}},
235237 {Key : "then" , Value : typeStrings [i ]},
236- })
238+ }
237239 }
238240
239241 // Stage to look up sections
@@ -293,7 +295,7 @@ func gradesAggregation(flag string, c *gin.Context) {
293295 {Key : "ix" , Value : "$ix" },
294296 }
295297 if flag == "section_type" {
296- // add section_type to _id to group grades by both academic_session and section_type
298+ // Add section_type to _id to group grades by both academic_session and section_type
297299 groupID = append (groupID , bson.E {Key : "section_type" , Value : "$section_type" })
298300 }
299301 groupGradesStage := bson.D {
@@ -320,7 +322,7 @@ func gradesAggregation(flag string, c *gin.Context) {
320322 // Stage to group grade distribution
321323 var groupDistributionID any = "$_id.academic_session"
322324 if flag == "section_type" {
323- // add the section-type criteria
325+ // Add the section-type criteria
324326 groupDistributionID = bson.D {
325327 {Key : "academic_section" , Value : "$_id.academic_session" },
326328 {Key : "section_type" , Value : "$_id.section_type" },
0 commit comments