From 718ece60e8b7546131c9e891eb5cefb481bde7bc Mon Sep 17 00:00:00 2001 From: murraydr Date: Wed, 25 Oct 2023 14:14:08 -0400 Subject: [PATCH] Added more comments --- README.md | 2 +- driver.py | 4 ++-- helperFunctions.py | 1 + lastUpdatedToken.txt | 2 +- reset.py | 14 ++++++++------ sectionViewWindow.py | 6 +++--- substitutionApprovalWindow.py | 12 +++++++----- substitutionHistoryWindow.py | 6 +++--- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 945ddeb..d3f5288 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The system also provides graphical interfaces for various common forms of inform The system can also automatically send emails to the relevant person(s). -The limitation of this system is that it doesn't run "in the background" it must be run on an instructor's PC and have the results pulled and pushed to/from Git each time. +The limitation of this system is that it doesn't run "in the background" it must be run on an instructor's PC and have the results pulled and pushed from/to Git each time. ## Installing and configuring for the first time diff --git a/driver.py b/driver.py index 4d049a5..249ac59 100644 --- a/driver.py +++ b/driver.py @@ -6,9 +6,9 @@ import helperFunctions as HF import scheduledPayrollWindow as PWin -#TODO demonstrate workflow with git +#TODO make development branch for code testing withotu altering "real" databases +#TODO remove blankArchivedSubRequests.csv by instead using the method used on substitutionRequestForm.csv in reset.py -#TODO document steps of start-of-semester initialization #TODO do error checking within while loop (update text color / valid status) # IMPOSSIBLE: pysimplegui does not allow for changing of the layout object after the window is created, diff --git a/helperFunctions.py b/helperFunctions.py index c1d5ace..863d052 100644 --- a/helperFunctions.py +++ b/helperFunctions.py @@ -80,6 +80,7 @@ def getDatesFromSection(sec): dates = list(secD.loc[secD["Section"]==sec]["Date"]) return dates +#Get the current and original data associated with a given section def getAllDataForSection(sec): secD = pd.read_csv(sectionDatabaseFilename,dtype=str,index_col=False) secDOrig = pd.read_csv(sectionDatabaseFilename[:-4]+"_Orig.csv",dtype=str,index_col=False) diff --git a/lastUpdatedToken.txt b/lastUpdatedToken.txt index b2af217..7d217d7 100644 --- a/lastUpdatedToken.txt +++ b/lastUpdatedToken.txt @@ -1 +1 @@ -2023-10-25 13:00:16.622945 \ No newline at end of file +2023-10-25 14:08:29.863050 \ No newline at end of file diff --git a/reset.py b/reset.py index 9380fe5..23f8ea8 100644 --- a/reset.py +++ b/reset.py @@ -6,22 +6,24 @@ import pandas as pd #Note that this script doesn't work inside protected Windows folders (such as "Documents") - +#Generate a 4 digit password that they must type in as a sort of ultimate "confirmation" requirement password="Reset{:04d}".format(random.randint(0,10000)) inStr=input('Are you sure? Type "'+password+'" to reset the state of the databases and files to the "start-of-semester-state"\nThis action cannot be undone!\n') if inStr==password: - subprocess.call(['cmd','/c',"python sectionCSVHelper.py"],shell=True) - shutil.copy("sectionsDatabase.csv", "sectionsDatabase_Orig.csv") - shutil.copy("startOfSemesterInputs\\blankArchivedSubRequests.csv","archivedSubRequests.csv") - with open("lastUpdatedToken.txt", 'w') as f: + subprocess.call(['cmd','/c',"python sectionCSVHelper.py"],shell=True)#run sectionCSVHelper + shutil.copy("sectionsDatabase.csv", "sectionsDatabase_Orig.csv")#copy the newly generated sections database to the _orig file for reference by the section viewer + shutil.copy("startOfSemesterInputs\\blankArchivedSubRequests.csv","archivedSubRequests.csv")# copy the blank archive over to the real one (to put the column headers in place) + with open("lastUpdatedToken.txt", 'w') as f:# set the lastUpdatedToken to a date in the past so that all requests are "more recent" f.write("2022-10-04 15:15:51.231447") + #Read the requests log and write only the first line of it back (to clear all other lines) with open('substitutionRequestForm.csv', 'r') as fin: data = fin.read().splitlines(True) with open('substitutionRequestForm.csv', 'w') as fout: fout.writelines(data[:1]) + #Set all the 'counts' to zero for all staff. stfD = pd.read_csv("staffDatabase.csv",dtype=str,index_col=False) stfD['Approved Substitutions'].values[:]=0 stfD['Accepted Substitutions'].values[:]=0 @@ -32,4 +34,4 @@ if inStr==password: else: - print('You typed somethinge other than "Reset'+password+'". Exiting') \ No newline at end of file + print('You typed somethinge other than '+password+'. Exiting') \ No newline at end of file diff --git a/sectionViewWindow.py b/sectionViewWindow.py index 4326475..e606819 100644 --- a/sectionViewWindow.py +++ b/sectionViewWindow.py @@ -34,11 +34,11 @@ def secViewWin(defaultFont): #get the data sec=values['-SECTION-'] - output,output2=HF.getAllDataForSection(sec) + output,output2=HF.getAllDataForSection(sec)#output is the current status, output2 is the beginning of semester status output=output.values.tolist() output2=output2.head(1).values.tolist()[0] - #Print the normal schedule + #Print the normal, unchanged schedule as it exists at the beginning of the semester window["-OUTPUT-"].print("Normally Scheduled: "+str(output2[2])+" @ "+str(output2[3]),text_color='black') normalNames=[] for ID in output2[4:]: @@ -48,7 +48,7 @@ def secViewWin(defaultFont): #Print a linebreak window["-OUTPUT-"].print("-"*160,text_color='black') - #print the schedule for each week + #print the schedule for each week, one week per row window["-OUTPUT-"].print("Currently Scheduled:",text_color='black') for line in output: names=[] diff --git a/substitutionApprovalWindow.py b/substitutionApprovalWindow.py index 6e23588..f47271b 100644 --- a/substitutionApprovalWindow.py +++ b/substitutionApprovalWindow.py @@ -99,7 +99,7 @@ def subAppWin(staffDatabaseFilename,secDFilename,subRequestsFilename,subRequests row=[sg.Column([[sg.Checkbox('',size=(1,1)),sg.Checkbox('',size=(1,1)),sg.Checkbox('',size=(1,1)),sg.Checkbox('',size=(1,1))],[sg.Input("INST. REASON",size=(12,1),key="-INPUT_REASON_"+str(i)+"-")]])] if request[6]!="": - color='#FF9999' + color='#FF9999'#reddish, contrasts well with the dark grey-blue background else: color='white' for i in range(len(textVals)): @@ -147,7 +147,7 @@ def subAppWin(staffDatabaseFilename,secDFilename,subRequestsFilename,subRequests if event == 'Ok': valid=True - dialogShown = False #Do not show multiple error dialogues even if there are multiple problems. + dialogShown = False #Do not show multiple error dialogues even if there are multiple problems (to avoid spamming popup boxes) #If two responses are both checked in ANY single line, then it is not valid input if True in [True for i, j, k, l in zip(approveValues, acceptValues, rejectValues, cancelValues) if ((i and j) or (i and k) or (j and k) or (i and l) or (j and l) or (k and l))]: @@ -219,7 +219,7 @@ def subAppWin(staffDatabaseFilename,secDFilename,subRequestsFilename,subRequests dates=subRequests[i][3].split(';') newID=subRequests[i][4] for date in dates: - for period in periods: + for period in periods:#"outer product" of the dates and sections, every permutation of the selected options is counted separately for tallying if "HR" in period: amount = 0.5 else: @@ -229,14 +229,16 @@ def subAppWin(staffDatabaseFilename,secDFilename,subRequestsFilename,subRequests #HF.incrementSubCount is for tracking how many subs this person requested and what their outcome was if newID !="": HF.incrementSubCount(newID,4,amount=amount)#Also track how many sub requests were filled by each person - if approveValues[i]: + if approveValues[i]:# this could be unindented one level, but it's technically more performant to not check if we already know its false HF.incrementSubCount(oldID,0,amount=amount) - if acceptValues[i]: + if acceptValues[i]:# this could be unindented one level, but it's technically more performant to not check if we already know its false HF.incrementSubCount(oldID,1,amount=amount) if rejectValues[i]: HF.incrementSubCount(oldID,2,amount=amount) if cancelValues[i]: HF.incrementSubCount(oldID,3,amount=amount) + + #Adding to either trimmed or resolved only happens once per request, unlike the earlier steps which are once per date*section if (not approveValues[i] and not acceptValues[i] and not rejectValues[i] and not cancelValues[i]): trimmedSubrequests.append(subRequests[i][:-1])#Trimmed requests is the list of requests that had no action taken and thus must be re-added to the list of pending requests else: diff --git a/substitutionHistoryWindow.py b/substitutionHistoryWindow.py index ffb861a..2a41746 100644 --- a/substitutionHistoryWindow.py +++ b/substitutionHistoryWindow.py @@ -45,13 +45,13 @@ def subHisWin(subRequestsArchiveFilename,defaultFont): window['OUTPUT'].update(value=name+" was not found in any names in the staff database.") else: netID=netIDs[0] - name=HF.IDToName(netID)#convert ID back to get full name + name=HF.IDToName(netID)#convert ID back to full name extraNamesStr="" if len(netIDs)>1: names = [HF.IDToName(i) for i in netIDs[:]] window['OUTPUT'].update(value="Multiple matches found: ["+", ".join(names)+"]") else: - #Enable the incrementing buttons once a single valid name is found + #Re-enable the incrementing buttons once a single valid name is found window['+APP'].Update(disabled=False) window['-APP'].Update(disabled=False) window['+ACC'].Update(disabled=False) @@ -121,7 +121,7 @@ def subHisWin(subRequestsArchiveFilename,defaultFont): try: numDays=int(inputStr) except: - numDays=7 + numDays=7 #default to 7 days if the input isn't valid timeStr=datetime.now() currDate=timeStr-timedelta(hours=4,minutes=0) pastDate=timeStr-timedelta(hours=4+24*numDays,minutes=0)