-
Notifications
You must be signed in to change notification settings - Fork 0
/
routine.py
74 lines (58 loc) · 2.06 KB
/
routine.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
from flask import jsonify
def make_index(x, y):
return (x * 10) + y
class Routine:
def __init__(self):
pass
def generator(table, checker_list, name, day, ctype, time):
conflict = False
time_map = {
"8:00": 0,
"9:25": 1,
"10:50": 2,
"12:15": 3,
"1:40": 4,
"3:05": 5,
"4:30": 6,
}
if ctype == "theory":
day_to_index = {"sun": (0, 2), "mon": (1, 3)}
if day in day_to_index:
day1, day2 = day_to_index[day]
if time in time_map:
idx = time_map[time]
in1 = make_index(day1, idx)
in2 = make_index(day2, idx)
if in1 not in checker_list and in2 not in checker_list:
table[day1][idx] = name
table[day2][idx] = name
checker_list.extend([in1, in2])
else:
conflict = True
elif ctype == "lab":
day_to_index = {"sun": 0, "mon": 1, "tue": 2, "wed": 3, "thu": 4}
time_map = {
"8:00": 0,
"9:25": 1,
"10:50": 2,
"12:15": 3,
"1:40": 4,
"3:05": 5,
}
# Ensure day and time are valid
if day in day_to_index and time in time_map:
day1 = day_to_index[day]
idx = time_map[time]
in1 = make_index(day1, idx)
in2 = make_index(day1, idx + 1)
if in1 not in checker_list and in2 not in checker_list:
table[day1][idx] = name
table[day1][idx + 1] = name
checker_list.extend([in1, in2])
else:
conflict = True
# return jsonify(table)
if conflict:
return jsonify({"table": table, "conflict": True})
else:
return jsonify({"table": table, "conflict": False})