Files
zvk2_public/tests/zvk/plugins/commands/test_timetable.py
2019-03-15 15:02:19 +04:00

57 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
from datetime import datetime
from zvk.misc.timetable_pb2 import Timetable
import zipfile
import numpy as np
def test_read_timetable_pb():
zfile = zipfile.ZipFile('relics/6407-2.ftt')
timetable_pb_bytes = zfile.read('timetable.pb')
timetable = Timetable.FromString(timetable_pb_bytes)
term_start = datetime.fromtimestamp(timetable.properties.term_start / 1000)
weeks_count = timetable.properties.weeks_count
def convert_weeks(s):
if s == 'a':
return list(range(1, weeks_count + 1))
if s == 'o':
return list(range(1, weeks_count + 1, 2))
if s == 'e':
return list(range(2, weeks_count + 1, 2))
if s.startswith('c'):
return list(map(int, s[1:].split(',')))
raise Exception(f'Bad week identifier {s}')
timetable_dict = {
'term_start': term_start.timestamp(),
'weeks_count': weeks_count,
'lessons': []
}
for lesson in timetable.lesson:
timetable_dict['lessons'].append({
'day': lesson.day,
'time': [lesson.time[:4], lesson.time[4:]],
'weeks': convert_weeks(lesson.weeks),
'subject': timetable.subject[lesson.subject_id - 1].name,
'kind': timetable.kind[lesson.kind_id - 1].name,
'place': timetable.place[lesson.place_id - 1].name,
'teachers': [timetable.teacher[teacher_id - 1].name
for teacher_id in lesson.teacher_id]
})
timetable_json = json.dumps(timetable_dict)
print(timetable_json)
assert 'Дегтярев А. А.' in np.sum([
i['teachers']
for i in timetable_dict['lessons']
])