-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathruncomparison.py
81 lines (66 loc) · 2.8 KB
/
runcomparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
""" a script that is used to compare 2 years in the archive (or with the current active year) """
import argparse
from contextlib import suppress
import json
from sys import exit
from data.processors.models import Course
parser = argparse.ArgumentParser()
parser.add_argument(
"--target",
type=str,
help="the year to be compared",
)
parser.add_argument(
"--source",
type=str,
help=""" optional - if a year is selected, compare to that year in the archive """,
)
try:
args = parser.parse_args()
except argparse.ArgumentError:
parser.print_help()
exit(0)
def check_in_fixes(cname: str, ls: list[tuple[str,str]], error: str) -> None:
""" mutates the list given to add the course name if it is in manual fixes"""
with suppress(FileNotFoundError):
with open(f"data/processors/manual_fixes/{cname[0:4]}Fixes.py", "r", encoding="utf8") as file:
if f"CONDITIONS[\"{cname}\"]" in file.read():
ls.append((cname, error))
def main():
""" runs the comparison between a target and a source year """
source_course_location = (
"data/final_data/coursesProcessed.json"
if args.source is None
else f"data/final_data/archive/processed/{args.source}.json"
)
target_course_location = f"data/final_data/archive/processed/{args.target}.json"
with open(source_course_location, "r", encoding="utf8") as f:
source_courses: dict[str, Course] = json.loads(f.read())
with open(target_course_location, "r", encoding="utf8") as f:
target_courses: dict[str, Course] = json.loads(f.read())
all_source = set(source_courses.keys())
all_target = set(target_courses.keys())
courses_in_manual: list[tuple[str, str]] = []
print("removed:")
for removed in sorted(all_target - all_source):
check_in_fixes(removed, courses_in_manual, "\t\t- removed")
print(f"\t- {removed}")
print("added:")
for added in sorted(all_source - all_target):
check_in_fixes(added, courses_in_manual, f"\t\t- added: \"{source_courses[added]['raw_requirements']}\"")
print(f"\t- {added}")
print("changed:")
for coursename in sorted(all_source.intersection(all_target)):
target_course = target_courses[coursename]["raw_requirements"]
source_course = source_courses[coursename]["raw_requirements"]
if target_course != source_course:
print()
print(f"\t{coursename}:")
check_in_fixes(coursename, courses_in_manual, f"\t\t- from: \"{target_course}\"\n\t\t- to: \"{source_course}\"")
print(f"\t\t - from: \"{target_course}\"")
print(f"\t\t - to: \"{source_course}\"")
print("inFixes:")
for added, error in sorted(courses_in_manual):
print(f"\t- {added}: \n{error}")
if __name__ == "__main__":
main()