-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (73 loc) · 2.6 KB
/
main.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
82
83
84
85
86
87
import os
from read_excel import read_excel
from empty_time_table import empty_table
from create_directory import create_directory
from create_file import create_file
from copy import deepcopy
count_of_time_table = 0
def clean_output():
path = f"{os.getcwd()}/output/"
file_list = os.listdir(path)
for file in file_list:
if file.endswith("placeholder"):
continue
os.remove(path + file)
print("Output cleaning finished!")
def get_next_time(class_time):
num = int(class_time[0:2])
alphabet = class_time[2:]
if alphabet == "A":
alphabet = "B"
elif alphabet == "B":
num += 1
alphabet = "A"
return "%02d%s" % (num, alphabet)
def add_time_table(init_time_table, class_data, num):
global count_of_time_table
for name, value in class_data[num].items():
for day_and_time in value:
is_success = True
times = day_and_time.split(',')
time_table = deepcopy(init_time_table)
now_time_table = deepcopy(time_table)
is_conflict = False
for time in times:
class_day = time[0:1]
class_start, class_end = time[1:].split('~')
class_time = class_start
while True:
if time_table[class_day][class_time] != "":
is_conflict = True
break
time_table[class_day][class_time] = name
if class_time == class_end:
break
class_time = get_next_time(class_time)
if is_conflict:
is_success = False
break
else:
now_time_table = deepcopy(time_table)
if is_success:
if num + 1 < len(class_data):
add_time_table(now_time_table, class_data, num + 1)
else:
count_of_time_table += 1
print(f"{count_of_time_table}.xlsx generated!")
now_time_table.to_excel(f"output/{count_of_time_table}.xlsx")
def generate_time_table():
create_directory()
create_file()
clean_output()
class_data = read_excel()
if len(class_data) == 0:
print("No excel found!")
else:
add_time_table(empty_table(), class_data, 0)
if count_of_time_table == 0:
print("Can't generate timetable!")
else:
print(f"{count_of_time_table} timetable generated!")
input("Press Enter to finish...")
if __name__ == "__main__":
generate_time_table()