auto-schedule-pro-v2: add schedule.kpi.ua to schedule-v2 converter
This commit is contained in:
parent
982eb7208a
commit
fa8f3ebdf5
96
modules/auto-schedule-pro-v2/lessons-to-schedule-v2.py
Normal file
96
modules/auto-schedule-pro-v2/lessons-to-schedule-v2.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class Lesson:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def read_from_schedule_pair(self, p):
|
||||||
|
self.time = p["time"].rsplit(':', 1)[0]
|
||||||
|
self.name = p["name"]
|
||||||
|
self.teacher = p["teacherName"]
|
||||||
|
self.type = p["tag"]
|
||||||
|
|
||||||
|
self.selectable = False
|
||||||
|
self.link = ""
|
||||||
|
self.nolink = True
|
||||||
|
|
||||||
|
def get_packable_object(self):
|
||||||
|
return {
|
||||||
|
"name": self.name,
|
||||||
|
"teacher": self.teacher,
|
||||||
|
"link": self.link,
|
||||||
|
"type": self.type,
|
||||||
|
"selectable": self.selectable,
|
||||||
|
"nolink": self.nolink
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def day_to_lesson_pool(pairs):
|
||||||
|
pool = []
|
||||||
|
|
||||||
|
for p in pairs:
|
||||||
|
l = Lesson()
|
||||||
|
l.read_from_schedule_pair(p)
|
||||||
|
pool.append(l)
|
||||||
|
|
||||||
|
return pool
|
||||||
|
|
||||||
|
def lesson_pool_to_objs(pool):
|
||||||
|
times = []
|
||||||
|
|
||||||
|
for i in (list(map(int, (i.time.split(':')))) for i in pool):
|
||||||
|
if i not in times:
|
||||||
|
times.append(i)
|
||||||
|
|
||||||
|
times.sort(key = lambda x: x[0] * 60 + x[1])
|
||||||
|
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for i in times:
|
||||||
|
lesson_timestamp = f"{i[0]:02}:{i[1]:02}"
|
||||||
|
required_timestamp = f"{i[0]}:{i[1]}"
|
||||||
|
|
||||||
|
objs_dup = (j.get_packable_object() for j in pool if j.time == lesson_timestamp)
|
||||||
|
objs = []
|
||||||
|
|
||||||
|
for i in objs_dup:
|
||||||
|
if i not in objs:
|
||||||
|
objs.append(i)
|
||||||
|
|
||||||
|
if len(objs) == 0:
|
||||||
|
continue
|
||||||
|
elif len(objs) == 1:
|
||||||
|
result[required_timestamp] = list(objs)[0]
|
||||||
|
else:
|
||||||
|
result[required_timestamp] = list(objs)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def process_week(week):
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for weekday in ["Пн", "Вв", "Ср", "Чт", "Пт"]:
|
||||||
|
day_pool = day_to_lesson_pool(next(filter(lambda l: l['day'] == weekday, week))['pairs'])
|
||||||
|
result.append(lesson_pool_to_objs(day_pool))
|
||||||
|
|
||||||
|
result.append({})
|
||||||
|
result.append({})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
ext_schedule = json.load(open(sys.argv[1], 'r'))
|
||||||
|
|
||||||
|
int_schedule = []
|
||||||
|
|
||||||
|
int_schedule += process_week(ext_schedule["scheduleFirstWeek"])
|
||||||
|
int_schedule += process_week(ext_schedule["scheduleSecondWeek"])
|
||||||
|
|
||||||
|
print(json.dumps(int_schedule, ensure_ascii = False, indent = 4))
|
Loading…
x
Reference in New Issue
Block a user