-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_history.py
32 lines (30 loc) · 1.17 KB
/
analyze_history.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
import ujson
import os
from datetime import datetime
files = os.listdir("output/parsed_courses")
for file in files:
with open("output/parsed_courses/" + file, "r") as f:
data = ujson.load(f)
for crn, course in data.items():
all_events = []
for type in ["added", "removed", "modified"]:
for instant in course[type]:
all_events.append((datetime.fromisoformat(instant["timestamp"]), type))
all_events.sort()
is_present = False
for event in all_events:
if event[1] == "added":
if is_present:
print(course)
raise Exception("Adding twice " + crn + " " + file)
is_present = True
elif event[1] == "removed":
if not is_present:
print(course)
raise Exception("Removing before adding " + crn + " " + file)
is_present = False
elif event[1] == "modified":
if not is_present:
print(course)
raise Exception("Modifying before adding " + crn + " " + file)
print("All courses are consistent")