Пример #1
0
 def __init__(self, prof_id, name="", telephone=''):
     self.prof_id = str(prof_id)
     self.name = name
     self.telephone = str(telephone)
     self.schedule = []
     self.time_preferred = tt.Timetable()
     self.time_not_possible = tt.Timetable()
Пример #2
0
def run_flask(week):
    today = datetime.datetime.now().strftime("%A")
    try:
        tt = Timetable.read_db(timetable_db)
        return "<head><link rel='stylesheet' href='static/style.css'</link></head>" + Timetable.get_day(
            tt, today, int(week)).return_html()
    except TypeError:
        tt = Timetable.get_timetable(school, user, password)
        Timetable.write_db(tt, timetable_db)
        return "<head><link rel='stylesheet' href='static/style.css'</link></head>" + Timetable.get_day(
            tt, today, int(week)).return_html()
Пример #3
0
 def __init__(self,
              course_id,
              title,
              course_type='',
              major=' ',
              week_start='',
              week_end='',
              class_list=[],
              taught_by_profs=[],
              period_required=tt.Timetable(),
              location='',
              scheduled_manually=False,
              should_be_scheduled=False):
     self.course_type = course_type
     self.course_id = str(course_id)
     self.title = title
     self.class_list = class_list
     self.week_start = week_start
     self.week_end = week_end
     self.location = location
     self.taught_by_profs = taught_by_profs
     for prof in taught_by_profs:
         self.taught_by_profs.append(prof)
     self.period_required = period_required
     self.period_allocated = []
     self.scheduled_manually = scheduled_manually
     self.should_be_scheduled = should_be_scheduled
     self.major = major
     self.groups = []
     self.weeks = ['0' for _ in range(30)]
Пример #4
0
    def read_all(self):
        # self.users = [User().restore(origin) for origin in IO.FileIO.read_json("users.json")]
        self.timetable = Timetable.Timetable().restore(
            IO.FileIO.read_json("data/timetable.json"))
        self.feedback = [
            Feedback().restore(origin)
            for origin in IO.FileIO.read_json("data/feedback.json")
        ]

        u_t = IO.FileIO.read_json("data/users.json")
        self.users = {int(key): User().restore(u_t[key]) for key in list(u_t)}
        return self
Пример #5
0
 def __init__(self):
     try:
         self.read_all()
         print("Read!")
     except FileNotFoundError:
         print("Files not found. Updating...")
         self.users = {0: User() for _ in range(0)}
         self.feedback = [Feedback() for _ in range(0)]
         self.timetable = Timetable.Timetable()
         update_timetable.t_update(self.timetable)
         self.write_all()
         print("Updated!")
Пример #6
0
def Timetable(message):
    import Timetable
    print(message.chat.id)
    try:
        check(str(message.chat.id))
        bot.send_message(message.chat.id,
                         Timetable.Ttable(str(message.chat.id)))
    except:
        bot.send_message(message.chat.id, "Неверные данные")
        bot.send_message(message.chat.id,
                         "Введите свой логин и пароль от элжура через пробел")
        bot.register_next_step_handler(message, Srart)
Пример #7
0
def do_what_user_wants():
    user = api.login(Sensitive.e_mail, Sensitive.password)
    user_info = user.json()
    input_str = user_info['full_name']
    input_tokens = input_str.split()
    if input_tokens[0] == 'bus':
        rides = []
        pushMessage = ''
        is_bus_station = True # looks, if there are any buses at given station
        start = "CasparDavidFriedrichStrasse" # default value
        if len(input_tokens) > 1:
    	    start = input_tokens[1]
            start = start.encode('utf-8')
            try:
                rides = Timetable.get_list(start)
                if rides == []:
                    pushMessage = "No bus station " + input_tokens[1] +"!"
                    is_bus_station = False

            except:
                pushMessage = "No bus station " + input_tokens[1] +"!"
                is_bus_station = False
            if len(input_tokens) == 3 and is_bus_station:
                rides = filter_buses(rides, input_tokens[2])
                if rides == []:
                    pushMessage = "No busline " + input_tokens[2] + " at "\
                                + input_tokens[1] +"!"
        else:
            rides = Timetable.get_list(start)
        print(rides)
        if(pushMessage == ""):
            for ride in rides:
                pushMessage += "{line} to {destination}: {time}Min, \n"\
                    .format(line = ride[0], destination = ride[1], time = ride[2])

            pushMessage = pushMessage[:-3] # delete last comma
        change_push_message(pushMessage)
        c.perform()
        print("Message sent!\n")
Пример #8
0
def check_update_system():
    import Timetable
    import IO
    import time

    s_t = time.time()
    t = Timetable.Timetable()
    # b = t.update()
    b = update_timetable.t_update(t)
    print(b, time.time() - s_t)
    if b:
        s_t = time.time()
        IO.FileIO.write_json("data/tt.json", t)
        print("Written", time.time() - s_t)
        s_t = time.time()
        t.restore(IO.FileIO.read_json("data/tt.json"))
        IO.FileIO.write_json("data/tt1.json", t)
        # input()
        print(time.time() - s_t)
    else:
        print("update failed")
Пример #9
0
 def createPop(self):
     pop = []
     for i in range(self.initN):
         pop.append(Timetable(self.teachers, self.subjects, self.roomN))
     return pop
Пример #10
0
    def generate_school_timetable(self, profs, courses, class_list, break_time,
                                  settings):
        def arrange_regular():
            pass

        # Step 1: initialization & checking
        wait = og.show_waiting_message()
        conflicts = []
        for pid in profs.keys():
            profs[pid].schedule = []  # Clear all schedule
            for i in range(self.week_num):
                profs[pid].schedule.append(
                    tt.Timetable(title=profs[pid].name +
                                 l.timetable_of_week[settings.language] +
                                 str(i)))
                # in Prof.schedule, for Timetable[i][j],
                # 0: not occupied;
                # not possible: the prof required not to teach in this period(set in Prof info page;
                # break time: the period is in break time, thus not allocated with any courses;
                # [course_id, [classId]]: teach Course with course_id to Class(es) with classId(s)in this period

        for cid in class_list.keys():
            class_list[cid].schedule = []  # Clear all schedule
            for i in range(self.week_num):
                class_list[cid].schedule.append(
                    tt.Timetable(title=class_list[cid].classId +
                                 l.timetable_of_week[settings.language] +
                                 str(i)))
                # in Class.schedule, for Timetable[i][j],
                # 0: not occupied;
                # break time: the period is in break time, thus not allocated with any courses;
                # [course_id, [prof_id]]: be taught Course with course_id by Prof(s) with prof_id(s) in this period

        # Step 2: negate all break time in schedule, so that it can't be used
        for pid in profs.keys():  # set break time in profs' info
            cur = profs[pid].schedule
            for w in range(self.week_num):
                err = cur[w].update_based_on(break_time, ['0'], ['0', '1'],
                                             '1', 'break time')
                if err: print(err)

        for cid in class_list.keys():  # set break time in classes' info
            cur = class_list[cid].schedule
            for w in range(self.week_num):
                err = cur[w].update_based_on(break_time, ['0'], ['0', '1'],
                                             '1', 'break time')
                if err: print(err)

        # Step 3: negate all time not possible in profs' schedule
        for pid in profs.keys():
            tnp = profs[pid].time_not_possible
            for w in range(self.week_num):
                err = profs[pid].schedule[w].update_based_on(
                    tnp, ['0', 'break time'], ['0', '1'], '1',
                    'time not possible')
                if err: print(err)

        # Step 4: take all Courses that should be scheduled
        courses_to_be_allocated = {}
        courses_manually = []
        for cid in courses.keys():
            if courses[cid].should_be_scheduled and not courses[
                    cid].scheduled_manually:
                courses_to_be_allocated[cid] = courses[cid]
        for cid in courses.keys():
            if courses[cid].should_be_scheduled and courses[
                    cid].scheduled_manually:
                courses_manually.append(courses[cid])

        # Step 5: check Courses
        for c in courses_manually:
            if not c.groups:
                err.append(c.title +
                           " hasn't been assigned with any classes or profs")
            if c.period_required.all_zeros():
                err.append(
                    c.title +
                    ' is set to manually distributed, but no periods are given'
                )
            if not ('1' in c.weeks):
                err.append(c.title + ': no weeks are set')
        for cid in courses_to_be_allocated.keys():
            c = courses_to_be_allocated[cid]
            if not c.groups:
                err.append(c.title +
                           " hasn't been assigned with any classes or profs")
            if not ('1' in c.weeks):
                err.append(c.title + ': no weeks are set')
        if err: print(err)

        # Step 6: pre-distribute courses that are set manually
        for c in courses_manually:
            print('allocating ', c.title)
            for w in range(30):
                if c.weeks[w] == 0 or c.weeks[w] == '0':
                    continue
                for g in c.groups:
                    for cl in g[0]:
                        err = class_list[cl].schedule[w].check(
                            c.period_required, '0', '1')
                        class_list[cl].schedule[w].change(
                            c.period_required,
                            [c.course_id, [i for i in g[1]]], '1')
                        if err:
                            print(err)

                    for p in g[1]:
                        err = profs[p].schedule[w].check(
                            c.period_required, '0', '1')
                        profs[p].schedule[w].change(
                            c.period_required,
                            [c.course_id, [i for i in g[0]]], '1')
                        if err:
                            print(err)

        # Step 7: allocate courses

        # Courses to groups
        groups = []
        for cid in courses_to_be_allocated.keys():
            c = courses_to_be_allocated[cid]
            for g in c.groups:
                cur_group = Group.Group(c.course_id, g[1], g[0])
                groups.append(cur_group)

        # i)Select courses that have profs with time preference (first group of Courses)

        # to be implemented

        # ii)Select courses that have profs with time not possible (second group of Courses)
        second = []
        for i in range(len(groups))[::-1]:
            cur_prof_id_list = groups[i].prof_id_list
            for cur_prof_id in cur_prof_id_list:
                if profs[cur_prof_id].get_time_impossible_as_list():
                    second.append(groups[i])
                    groups.pop(i)

        err = []
        if settings.arranging_rule == 0:  # if set to priority to periods that are most empty
            print(
                'Allocating courses with priority to periods that are most empty in a week'
            )
        elif settings.arranging_rule == 1:  # if set to closely pack
            print('Allocating courses: closely pack everything')
            for i in range(len(second)):
                cur_prof_id_list = second[i].prof_id_list
                cur_class_id_list = second[i].class_id_list
                weeks = courses[second[i].course_id].weeks
                first_period_is_chosen, second_period_is_chosen = False, False

                for date in range(7):
                    for period in range(12):
                        if not op.profs_are_available(profs, cur_prof_id_list,
                                                      weeks, period, date):
                            continue
                        elif not oc.classes_are_available(
                                class_list, cur_class_id_list, weeks, period,
                                date):
                            continue
                        else:
                            first_period_is_chosen = True
                            first_period = (period, date)
                            for d in range(date + 2, 7):
                                for p in range(12):
                                    if not op.profs_are_available(
                                            profs, cur_prof_id_list, weeks, p,
                                            d):
                                        continue
                                    elif not oc.classes_are_available(
                                            class_list, cur_class_id_list,
                                            weeks, p, d):
                                        continue
                                    else:
                                        second_period_is_chosen = True
                                        second_period = (p, d)
                                        break
                                if second_period_is_chosen:
                                    break

                        if first_period_is_chosen and second_period_is_chosen:
                            break
                    if first_period_is_chosen and second_period_is_chosen:
                        break

                if not (first_period_is_chosen and second_period_is_chosen):
                    err.append(courses[second[i].course_id].title +
                               'cannot be arranged')
                else:
                    for pid in cur_prof_id_list:
                        op.change(profs, pid, weeks, first_period[0],
                                  first_period[1],
                                  [second[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [second[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0],
                                  second_period[1],
                                  [second[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [second[i].course_id, cur_class_id_list])

                    for cid in cur_class_id_list:
                        oc.change(class_list, cid, weeks, first_period[0],
                                  first_period[1],
                                  [second[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [second[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0],
                                  second_period[1],
                                  [second[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [second[i].course_id, cur_prof_id_list])

        # iii)Allocate the remaining courses according to rules
        err = []
        if settings.arranging_rule == 0:  # if set to priority to periods that are most empty
            print(
                'Allocating courses with priority to periods that are most empty in a week'
            )
        elif settings.arranging_rule == 1:  # if set to closely pack
            print('Allocating courses: closely pack everything')
            for i in range(len(groups)):
                cur_prof_id_list = groups[i].prof_id_list
                cur_class_id_list = groups[i].class_id_list
                weeks = courses[groups[i].course_id].weeks
                first_period_is_chosen, second_period_is_chosen = False, False

                for date in range(7):
                    for period in range(12):
                        if not op.profs_are_available(profs, cur_prof_id_list,
                                                      weeks, period, date):
                            continue
                        elif not oc.classes_are_available(
                                class_list, cur_class_id_list, weeks, period,
                                date):
                            continue
                        else:
                            first_period_is_chosen = True
                            first_period = (period, date)
                            for d in range(date + 2, 7):
                                for p in range(12):
                                    if not op.profs_are_available(
                                            profs, cur_prof_id_list, weeks, p,
                                            d):
                                        continue
                                    elif not oc.classes_are_available(
                                            class_list, cur_class_id_list,
                                            weeks, p, d):
                                        continue
                                    else:
                                        second_period_is_chosen = True
                                        second_period = (p, d)
                                        break
                                if second_period_is_chosen:
                                    break

                        if first_period_is_chosen and second_period_is_chosen:
                            break
                    if first_period_is_chosen and second_period_is_chosen:
                        break

                if not (first_period_is_chosen and second_period_is_chosen):
                    err.append(courses[groups[i].course_id].title +
                               'cannot be arranged')
                else:
                    for pid in cur_prof_id_list:
                        op.change(profs, pid, weeks, first_period[0],
                                  first_period[1],
                                  [groups[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [groups[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0],
                                  second_period[1],
                                  [groups[i].course_id, cur_class_id_list])
                        op.change(profs, pid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [groups[i].course_id, cur_class_id_list])

                    for cid in cur_class_id_list:
                        oc.change(class_list, cid, weeks, first_period[0],
                                  first_period[1],
                                  [groups[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, first_period[0] + 1,
                                  first_period[1],
                                  [groups[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0],
                                  second_period[1],
                                  [groups[i].course_id, cur_prof_id_list])
                        oc.change(class_list, cid, weeks, second_period[0] + 1,
                                  second_period[1],
                                  [groups[i].course_id, cur_prof_id_list])

        else:
            og.show_error_message('Bad arranging rule parameter: mode ' +
                                  str(settings.arranging_rule) + ' not define')
        if err:
            print(err)

        self.is_generated = True
        wait.destroy()
        og.show_succeed_message()
Пример #11
0
 def __init__(self, major, week_num=30):
     self.major = major
     self.weekly_schedule = [tt.Timetable() for _ in range(week_num)]
Пример #12
0
 def clear_time_preference(self):
     self.time_preferred = tt.Timetable()
     self.time_not_possible = tt.Timetable()
Пример #13
0
 def get(self, school, class_, student):
     timetable = Timetable.get(school, class_, student)
     response = make_response(timetable, 200)
     response.headers["content-type"] = "text/calendar"
     return response
Пример #14
0
 def __init__(self, course_id, prof_id_list, class_id_list):
     self.course_id = course_id
     self.prof_id_list = prof_id_list
     self.class_id_list = class_id_list
     self.timetable = tt.Timetable()