diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-13 18:00:17 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-13 18:00:17 +1100 |
| commit | 98cef5e9a772602d42acfcf233838c760424db9a (patch) | |
| tree | 5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp3311/2/trans | |
initial commit
Diffstat (limited to 'comp3311/2/trans')
| -rwxr-xr-x | comp3311/2/trans | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/comp3311/2/trans b/comp3311/2/trans new file mode 100755 index 0000000..f530676 --- /dev/null +++ b/comp3311/2/trans @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +# COMP3311 21T3 Ass2 ... print a transcript for a given student + +import sys +import psycopg2 +import re +from helpers import getStudent, getStudentCourses, doesGradeAddRule +from helpers import doesGradeAddUOC, doesGradeAddWAM, getGradeString + +# define any local helper functions here + +### set up some globals + +usage = f"Usage: {sys.argv[0]} zID" +db = None + +### process command-line args + +argc = len(sys.argv) +if argc < 2: + print(usage) + exit(1) +zid = sys.argv[1] +if zid[0] == 'z': + zid = zid[1:8] +digits = re.compile("^\d{7}$") +if not digits.match(zid): + print(f"Invalid student ID {zid}") + exit(1) + +# manipulate database + +try: + db = psycopg2.connect("dbname=mymyunsw") + stuInfo = getStudent(db,zid) + if not stuInfo: + print(f"Invalid student ID {zid}") + exit() + + student = getStudent(db, zid) + print(f"{zid} {student[1]}, {student[2]}") + + total_uoc = 0; + total_wam_num = 0; + total_wam_den = 0; + for (CourseCode, Term, SubjectTitle, Mark, Grade, UOC) in getStudentCourses(db, zid): + total_uoc += UOC if doesGradeAddUOC(Grade) else 0 + total_wam_num += UOC * (Mark if Mark != None else 0) + total_wam_den += UOC if doesGradeAddWAM(Grade) else 0 + + mark_str = Mark if Mark != None else "-" + uoc_str = " " + getGradeString(Grade) if getGradeString(Grade) != "Xuoc" else f"{UOC:2d}uoc" + print(f"{CourseCode} {Term} {SubjectTitle :<32s}{mark_str :>3} {Grade :>2s} {uoc_str}") + + # Avoid division by zero. + print(f"UOC = {total_uoc}, WAM = {total_wam_num / total_wam_den if total_wam_den != 0 else 0 :.1f}"); + +except Exception as err: + print("DB error: ", err) +finally: + if db: + db.close() + |
