-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaggregate.py
More file actions
64 lines (58 loc) · 1.61 KB
/
aggregate.py
File metadata and controls
64 lines (58 loc) · 1.61 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
from typing import Iterable, Tuple, Dict
from models import SingleEvent, AggregatedCourse
def make_key(e:SingleEvent) -> Tuple[str, str, str, str, Tuple[int, int], int,int]:
return (
e.kcmc,
e.jxcdmc,
e.jxhjmc,
e.teaxms,
(e.ps, e.pe),
e.xq,
e.zc
)
def seek_key(e:SingleEvent) -> Tuple[str, str, str, str, Tuple[int, int], int,int]:
return (
e.kcmc,
e.jxcdmc,
e.jxhjmc,
e.teaxms,
(e.ps, e.pe),
e.xq,
e.zc-1
)
def aggregate(events: Iterable[SingleEvent]) -> Tuple[Dict, list[AggregatedCourse]]:
index: Dict[Tuple[str, str, str, str, Tuple[int, int], int,int], AggregatedCourse] = {}
Course: Dict[str, int] = {}
idcount = 0
for e in events:
key = seek_key(e)
week = e.zc
ac = index.get(key)
id = Course.get(e.kcmc)
key_old = key
key = make_key(e)
if ac is None:
if id is None:
id = idcount
Course[e.kcmc] = id
idcount += 1
ac = AggregatedCourse(
id=id,
kcmc=e.kcmc,
jxcdmc=e.jxcdmc,
jxhjmc=e.jxhjmc,
teaxms=e.teaxms,
xq=e.xq,
xs=e.xs,
qssj=e.qssj,
jssj=e.jssj,
pe=e.pe,
ps=e.ps,
zc=list()
)
index[key] = ac
else:
index[key] = index.pop(key_old)
ac = index.get(key)
ac.add_zc(week)
return Course,list(index.values())