def timetable(): form = TimetableForm() if form.validate_on_submit(): subject = Timetable(body=form.subject.data) db.session.add(subject) db.session.commit() flash('Subject is changed') homework = Timetable(body=form.homework.data) db.session.add(homework) db.session.commit() flash('Homework is changed') return render_template('timetable.html', title='Расписание', form=form)
def signin(): ''' Vigenère cipher algorithm to encode URL. How to decode? When program request this page, it will carrier key which to use decode. ''' get_current_classes() classes = list(r.hgetall("simultaneously").values()) fake_id = request.args.get('rfid_id') secret = request.args.get('secret') rfid_id = decode(secret, fake_id)[2:-1] for class_ in reversed(classes): curr_class = Class.query.filter_by(class_id=class_.decode('utf-8')).first_or_404() print(curr_class) students = curr_class.get_student().all() for student in students: if student.rfid_id == rfid_id: log_info = Timetable(time_class_name=curr_class.class_name, time_class_id=curr_class.class_id, time_student_id=student.student_id, time_time=datetime.now(), active=True) db.session.add(log_info) db.session.commit() return student.student_name return rfid_id
def import_data(self): timetable_list = [] classes = pd.read_csv( os.path.join(self.raw_data_directory, 'classes.csv')) for i in range(1, 5): timetable = pd.read_csv( os.path.join(self.raw_data_directory, 'timetable{}.csv'.format(i))) timeslots = [] mod_code_list = [] for index, row in timetable.iterrows(): day = row['day'] start_time = row['start_time'].split(':') end_time = row['end_time'].split(':') module_code = row['module_code'] class_ = classes.loc[classes['mod_code'] == module_code] class_row = class_.iloc[0] #print(class_row) name = class_row['name'] number_taking = int(class_row['number_taking']) class_id = int(class_row['id']) class_object = Class(mod_name=name, mod_code=module_code, number_taking=number_taking) start_time_hour = int(start_time[0]) end_time_hour = int(end_time[0]) st_time = datetime(year=2017, day=1, month=1, hour=start_time_hour) end_time = datetime(year=2017, day=1, month=1, hour=end_time_hour) timeslot = Timeslot(day=day, start_time=st_time, end_time=end_time, module_code=module_code, class_=class_object) timeslots.append(timeslot) #timetable = Timetable(id=id, timeslots = timeslots) timetable = Timetable(timeslots=timeslots) timetable_list.append(timetable) self.objects = timetable_list
def setUp(self): db.create_all() db.session.add(Subject(codename='math', name='Математика', _aliases='матеша,матан,алгебра')) db.session.add(Subject(codename='history', name='История', _aliases='истор')) db.session.add(Task(subject_codename='math', date=date(2020, 3, 4), text='тестовое задание с математики')) for i in range(14): db.session.add(Timetable(subjects='math', is_work_day=True)) db.session.add(User(id=45345234, username='******', name='Админ', status='super_admin')) db.session.add(User(id=64564562, username='******', name='Человек', status='user')) db.session.commit() self.login()
def generate_timetable(self): fake_class = Class.query.filter_by(class_name="LAST").first() class_name = fake_class.class_name class_id = fake_class.class_id names = self.get_name() for i in range(0, 20): year = 2018 month = random.randint(8, 12) day = random.randint(1, 28) hour = random.randint(7, 21) for j in range(0, 50): student = Student.query.filter_by(student_name=names[j]).first() active = random.randint(0, 1) t = Timetable(time_class_name=class_name, time_class_id=class_id, time_student_id=student.student_id, time_time=self.generate_random_time(year,month,day,hour), active=active) db.session.add(t) length = len(Timetable.query.filter_by(time_class_name=class_name).all()) return length
def post_result(class_name): class_ = Class.query.filter_by(class_name=class_name).first_or_404() students = class_.get_student().all() today_str = datetime.now().strftime('%Y-%m-%d') today_format = datetime.strptime(today_str, "%Y-%m-%d") for student in students: curr_log_info = record(class_.class_id, student.student_id, today_format) if curr_log_info is None: write_log_info = Timetable(time_class_name=class_.class_name, time_class_id=class_.class_id, time_student_id=student.student_id, time_time=datetime.now(), active=False) db.session.add(write_log_info) db.session.commit() return redirect(url_for('get_class', class_name=current_user.class_name))
def generateTimetable(names): fake_class = Class.query.filter_by(class_name="TEST").first() class_name = fake_class.class_name class_id = fake_class.class_id for i in range(0, 20): year = 2018 month = random.randint(8, 12) day = random.randint(1, 28) hour = random.randint(7, 21) for j in range(0, 50): student = Student.query.filter_by(student_name=names[j]).first() active = random.randint(0, 1) t = Timetable(time_class_name=class_name, time_class_id=class_id, time_student_id=student.student_id, time_time=generateRandomTime(year, month, day, hour), active=active) db.session.add(t) db.session.commit()