@@ -24,12 +24,21 @@ def termsAttended(certification=None, username=None):
2424
2525def termsMissed (certification = None , username = None ):
2626 '''
27- Populate the maximum amount of certification a student can miss based on class classification
27+ Calculate how many certification-eligible terms a student has missed based on their class level
28+ and attendance record.
29+
30+ Logic:
31+ - Each class level is expected to participate in 2 terms per year.
32+ - If the user is currently in their final spring term (e.g., Spring of senior year),
33+ they are expected to have completed all terms: missedTerms = (level + 1) * 2.
34+ - Otherwise, assume they’ve had one fewer term to attend: missedTerms = ((level + 1) * 2) - 1.
35+ - If the user's classification is None, assume just 1 expected term.
36+ - Subtract the number of terms the student has attended from the expected total to get the missed count.
2837 '''
29- sh = 0
3038 classLevel = ["Freshman" , "Sophomore" , "Junior" , "Senior" ]
3139 currentTerm = g .current_term
3240 currentDescription = currentTerm .description
41+
3342 # looking into a scenario where the current term is summer so that we can reassigned the current term variable to the next term
3443 if currentTerm .isSummer == True :
3544 currentDescription = f'Fall { currentTerm .year } '
@@ -45,8 +54,10 @@ def termsMissed(certification=None, username=None):
4554 missedTerms = ((level + 1 ) * 2 ) - 1
4655 elif str (user .rawClassLevel ) == "None" :
4756 missedTerms = 1
57+
4858 attendedTerms = termsAttended (certification , username )
4959 missedTerms = missedTerms - len (attendedTerms )
60+
5061 return missedTerms
5162
5263def getCertRequirementsWithCompletion (* , certification , username ):
@@ -85,7 +96,7 @@ def getCertRequirements(certification=None, username=None):
8596
8697 # we have to add the is not null check so that `cert.requirement` always exists
8798 reqList = reqList .where (Certification .id == certification , CertificationRequirement .id .is_null (False ))
88- certs = []
99+ certificationList = []
89100 for cert in reqList :
90101 if username :
91102 cert .requirement .completed = bool (cert .__dict__ ['completed' ])
@@ -94,25 +105,29 @@ def getCertRequirements(certification=None, username=None):
94105 cert .requirement .missedTerms = termsMissed (cert .requirement .id , username )
95106 cert .requirement .attendedTerms = len (termsAttended (cert .requirement .id , username ))
96107 cert .requirement .attendedDescriptions = termsAttended (cert .requirement .id , username )
97- certs .append (cert .requirement )
108+ certificationList .append (cert .requirement )
98109
99110 # the .distinct() doesn't work efficiently, so we have to manually go through the list and removed duplicates that exist
100- newCerts = []
101- certsIndex = 0
102- for cert in certs :
103- if certs [certsIndex ] not in newCerts :
104- newCerts .append (certs [certsIndex ])
105- certsIndex += 1
106- certs = newCerts
107- return certs
111+ validCertification = set ()
112+ certificationIndex = 0
113+
114+ for cert in certificationList :
115+ if certificationList [certificationIndex ] not in validCertification :
116+ validCertification .add (certificationList [certificationIndex ])
117+ certificationIndex += 1
118+
119+ certificationList = list (validCertification )
120+
121+ return certificationList
108122
109- certs = {}
123+ certificationDict = {}
110124 for cert in reqList :
111- if cert .id not in certs .keys ():
112- certs [cert .id ] = {"data" : cert , "requirements" : []}
125+ if cert .id not in certificationDict .keys ():
126+ certificationDict [cert .id ] = {"data" : cert , "requirements" : []}
113127 if getattr (cert , 'requirement' , None ):
114- certs [cert .id ]["requirements" ].append (cert .requirement )
115- return certs
128+ certificationDict [cert .id ]["requirements" ].append (cert .requirement )
129+
130+ return certificationDict
116131
117132def updateCertRequirements (certId , newRequirements ):
118133 """
0 commit comments