From e1936f63f5165c4cc5a5f881ccacbaf499510978 Mon Sep 17 00:00:00 2001 From: Gregory Bell Date: Fri, 26 Jan 2024 20:42:37 -0700 Subject: [PATCH] The fixes that i promised --- FileHelpers/excelLoaders.py | 8 ++------ Grade/grade.py | 20 +++++++++++--------- main.py | 6 +++++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/FileHelpers/excelLoaders.py b/FileHelpers/excelLoaders.py index 9860a5f..eb2a1c1 100644 --- a/FileHelpers/excelLoaders.py +++ b/FileHelpers/excelLoaders.py @@ -59,7 +59,6 @@ def loadSpecialCases(): """ specialCasesDF = loadExcel(DEFAULT_SPECIAL_CASES_SEARCH_PATH, promptIfError=False, directoriesToCheck=["./"]) - specialCasesDF = specialCasesDF.astype({"CWID": str}) if specialCasesDF.empty: print("Failed to automatically load special cases file. Please enter file name") @@ -89,12 +88,9 @@ def loadSpecialCases(): return createEmptySpecialCasesSheet() # We want to non-destructively get the multipass so that it is easier to use the spreadsheet later - specialCasesDF['multipass'] = "" - - # Get multipass from email - for i, row in specialCasesDF.iterrows(): - specialCasesDF.at[i, 'multipass'] = row['CWID'] + specialCasesDF['multipass'] = specialCasesDF["CWID"] + specialCasesDF['multipass'] = specialCasesDF['multipass'].apply(lambda x: f"{x:.0f}") # Set the date to be a date # specialCasesDF['new_due_date'] = pd.to_datetime(specialCasesDF['new_due_date']) diff --git a/Grade/grade.py b/Grade/grade.py index d496610..ab31464 100644 --- a/Grade/grade.py +++ b/Grade/grade.py @@ -147,14 +147,16 @@ def validateAndUpdateStatusAssignments(_gradescopeDF: pd.DataFrame, elif _specialCasesDF.loc[currentSpecialCase, 'handled'].values[0] != "": continue - if _specialCasesDF.loc[currentSpecialCase, 'extension_type'] in _statusAssignmentsDF['trigger'].values: + indexToAccess = len(_specialCasesDF.loc[currentSpecialCase, 'extension_type'].values) - 1 + + if _specialCasesDF.loc[currentSpecialCase, 'extension_type'].values[indexToAccess] in _statusAssignmentsDF['trigger'].values: # Create a bool mask for the current status assignment score for the student and the correct trigger currentStatusAssignment = \ (_statusAssignmentScoresDF['multipass'] == row['multipass']) & \ (_statusAssignmentScoresDF['status_assignment_id'] == (_statusAssignmentsDF.loc[_statusAssignmentsDF['trigger'] == - _specialCasesDF.loc[currentSpecialCase, 'extension_type'].values[0], - 'id'].values[0])) + _specialCasesDF.loc[currentSpecialCase, 'extension_type'].values[indexToAccess], + 'id'].values[indexToAccess])) # Check to make sure that the student actually has a value for the status assignment # This should only happen if the student dropped, or recently added and does not yet have a score # for the assignment, either way, it will require manual intervention. @@ -165,8 +167,8 @@ def validateAndUpdateStatusAssignments(_gradescopeDF: pd.DataFrame, "Unable to process triggered special case: No status assignment found for student" # if the student requested more of an extension than they were entitled to - elif _statusAssignmentScoresDF.loc[currentStatusAssignment, 'student_score'].values[0] < \ - _specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[0]: + elif _statusAssignmentScoresDF.loc[currentStatusAssignment, 'student_score'].values[indexToAccess] < \ + _specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[indexToAccess]: _specialCasesDF.loc[currentSpecialCase, 'handled'] = "FALSE" _specialCasesDF.loc[currentSpecialCase, 'grader_notes'] = \ @@ -178,14 +180,14 @@ def validateAndUpdateStatusAssignments(_gradescopeDF: pd.DataFrame, f"Automatically Approved on {datetime.date.today().strftime('%m-%d-%y')}" _statusAssignmentScoresDF.loc[currentStatusAssignment, 'student_score'] -= \ - _specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[0] + _specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[indexToAccess] _specialCasesDF.loc[currentSpecialCase, 'approved_by'] = "AUTOMATIC APPROVAL" - extensionMessage: str = p.plural(_specialCasesDF.loc[currentSpecialCase, 'extension_type'].values[0], - _specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[0]) + extensionMessage: str = p.plural(_specialCasesDF.loc[currentSpecialCase, 'extension_type'].values[indexToAccess], + _specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[indexToAccess]) _gradescopeDF.at[i, 'lateness_comment'] = \ - f"Extended with {_specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[0]} " + \ + f"Extended with {_specialCasesDF.loc[currentSpecialCase, 'extension_days'].values[indexToAccess]} " + \ f"{extensionMessage}" return _gradescopeDF, _specialCasesDF, _statusAssignmentScoresDF diff --git a/main.py b/main.py index f619461..7d0da47 100644 --- a/main.py +++ b/main.py @@ -29,7 +29,11 @@ async def main(): and "bartik_username" in loadedConfig.keys() \ and "bartik_password" in loadedConfig.keys() \ and "bartik_course" in loadedConfig.keys(): - bartik = Bartik(loadedConfig["bartik_url"], loadedConfig["bartik_username"], loadedConfig["bartik_password"], loadedConfig['bartik_course']) + try: + bartik = Bartik(loadedConfig["bartik_url"], loadedConfig["bartik_username"], loadedConfig["bartik_password"], loadedConfig['bartik_course']) + except: + print("Failed to connect to bartik") + bartik = None operation = mainMenu() if not await operation(canvas=canvas, azure=azure, bartik=bartik, latePenalty=loadedConfig['late_penalties']):