-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofdata.py
More file actions
77 lines (68 loc) · 1.44 KB
/
profdata.py
File metadata and controls
77 lines (68 loc) · 1.44 KB
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
import json
with open('profs.json') as f:
profs = json.load(f)
#profs = __import__("profs").profs
def contains(s,e,v):
return v >= s and v <= e
def overlap(s1,e1,s2,e2):
return any([
contains(s1,e1,s2),
contains(s1,e1,e2),
contains(s2,e2,s1),
contains(s2,e2,e1),
])
# it's a database now!
classes = []
chours = []
phours = []
for i,p in enumerate(profs):
p['id'] = i
for j,cls in enumerate(p['classes']):
cls['id'] = len(classes)
cls['profid'] = i
classes.append(cls)
for day in cls['days']:
chours.append((cls['id'],cls['room'],day,cls['start'],cls['end']))
for day,hs in [*p['hours'].items()]:
for h in hs:
phours.append((i,day.upper(),h['start'],h['end']))
p['hours'][day.upper()] = p['hours'][day]
del p['hours'][day]
timetravel = set()
overlaps = set()
for h1 in chours:
for h2 in chours:
if h1 == h2:
continue
i1,r1,d1,s1,e1 = h1
i2,r2,d2,s2,e2 = h2
if r1 != r2 or d1 != d2:
continue
if overlap(int(s1),int(e1),int(s2),int(e2)):
#print(h1,h2,'overlap',classes[i1]['code'],profs[classes[i1]['profid']]['room'],classes[i2]['code'],profs[classes[i2]['profid']]['room'])
overlaps.add((i1,i2))
for h in chours:
i,r,d,s,e = h
if int(e) < int(s):
timetravel.add(i)
#print(h)
"""
profs = [prof]
prof = {
'name': str
'title': str
'email': str
'phone': str
'room': room
'classes': [class]
'hours': hours
}
class = {
'code': str
'sec': str
'days': [day]
'start': time
'end': time
'room': room
}
"""