Beispiel #1
0
def prepare_data(root, semester, group_by: Type[_DBObject]):
    data = []
    year = None
    for user in root:
        user_name = user.short_name()
        lessons = Lesson.of(user)

        groups = set(group_by.of(user))

        for lesson in lessons:
            if (lesson.semester == semester or (isinstance(semester, (set, list)) and lesson.semester in semester)) \
                    and lesson.completed:
                year = lesson.date.year
                lesson_visitation = set(Visitation.of(lesson)) & set(Visitation.of(user))
                lesson_students = set(Student.of(lesson)) & set(Student.of(user))
                for item in list(set(group_by.of(lesson)) & groups):
                    data.append({
                        'user': user_name,
                        'visit': len(set(Visitation.of(item)) & lesson_visitation),
                        'total': len(set(Student.of(item)) & lesson_students),
                        'date': lesson.date,
                        'group_by': item.short_name(),
                        'day': lesson.date.timetuple().tm_yday,
                        'week': lesson.week
                    })
    return data, year
Beispiel #2
0
    def __init__(self, file_name, group, discipline, session):
        file = xlrd.open_workbook(file_name)
        self.file = file.sheet_by_index(0)

        assert set([g.name for g in group]) == set(self.group_name())
        assert discipline.name.lower() == self.discipline_name().lower()

        lessons = lessons_of(group, discipline)
        year = sorted(lessons, key=lambda x: x.date)[0].date.year

        student_of_group = Student.of(group)

        for col in range(3, self.file.ncols):
            if self.file.cell(1, col).value in ['', None]:
                print((1, col), 'is None')
                break

            date = self.get_date(col, year)
            lesson = list(filter(lambda x: x.date == date, lessons))
            if len(lesson) == 0:
                continue
            lesson = lesson[0]

            for row in range(self.file.nrows):
                student = self.get_student(row, student_of_group)
                if student is None:
                    break
                print('new_visit', student, lesson)
                Visitation.get_or_create(session,
                                         student_id=student.id,
                                         lesson_id=lesson.id)
Beispiel #3
0
 def user_start_lesson(self, status):
     students = Student.of(self.group.current())
     lesson = self.lesson.current()
     self.visit_marker = MarkVisitProcess(
         students, lesson, error_callback=self.lesson_finished.emit)
     self.visit_marker.new_visit.connect(self.table.new_visit)
     self.lesson_started.emit(lesson)
Beispiel #4
0
 def check_groups(self, groups: List[Group]):
     for index, group in enumerate(groups):
         existing_group = self.session.query(Group).filter(
             Group.name == group.name).first()
         if existing_group is not None:
             students = Student.of(existing_group)
             if len(students) > 0:
                 self._apply_group(existing_group.name,
                                   existing_group.students)
Beispiel #5
0
 def get_student(text):
     full_name = self.full_name_regex.findall(text)
     if full_name is not None and len(full_name) > 0 and full_name[0] != '':
         splited = full_name[0].split(' ')
         student = Student.get_or_create(
             last_name=splited[0],
             first_name=splited[1],
             middle_name=splited[2] if len(splited) >= 3 else ''
         )
         if self.group not in student.groups:
             student.groups.append(self.group)
         return student
Beispiel #6
0
        def show_stats():
            visits = Visitation.of(lesson)
            students = Student.of(lesson)

            if lesson.completed:
                msg = f"Посетило {len(visits)} из {len(students)} ({round(len(visits) * 100 / (len(students)))}%)."
            else:
                msg = "Занятие не проведено."
            QMessageBox().information(
                self,
                "Статистика",
                msg
            )
Beispiel #7
0
    def post(self, data: dict, auth: Auth, **kwargs):
        session = auth.session()

        group = session.query(Group).filter_by(**data,
                                               _is_deleted=False).first()
        if group is not None:
            students = Student.of(group)

            return {
                'name': group.name,
                'id': group.id,
                'students': sorted(students, key=lambda x: x.full_name())
            }
        else:
            raise NoDataError(f"группа с параметрами ({data}) не найдена")
Beispiel #8
0
    def __init__(self, lesson: Lesson, student: Student):
        super().__init__()
        self.lesson = lesson
        self.student = student
        self.remove_file_on_close: List[Path] = []

        self.setWindowModality(Qt.ApplicationModal)
        self.setMinimumSize(450, 250)

        self.r = VisitationLossReason.get(lesson.session(),
                                          lesson_id=lesson.id,
                                          student_id=student.id)

        self.grid = QGridLayout()

        self.setWindowTitle("Добавить причину пропуска")

        self.grid.addWidget(QLabel('Студент'), 0, 0, 1, 2)
        student_name_label = QLabel(student.short_name())
        student_name_label.setObjectName('InfoLabel')
        self.grid.addWidget(student_name_label, 0, 2, 1, 2)

        self.grid.addWidget(QLabel('Занятие'), 1, 0, 1, 2)
        lesson_name_label = QLabel(name(lesson))
        lesson_name_label.setObjectName('InfoLabel')
        self.grid.addWidget(lesson_name_label, 1, 2, 1, 2)

        self.reason = QMComboBox(LossReason)
        self.grid.addWidget(QLabel('Причина'), 2, 0, 1, 2)
        self.grid.addWidget(self.reason, 2, 2, 1, 2)

        self.file_attach = QAttachFile('rb', ('pdf', 'docx', 'img'))
        self.grid.addWidget(self.file_attach, 3, 0, 2, 4)

        self.grid.addWidget(QAccentCancelButtons(self._accept, self.close), 5,
                            0, 1, 4)

        self.setLayout(self.grid)

        if self.r is not None:
            self.reason.setCurrent(self.r.reason)
            if self.r.file is not None:
                file_path = writeTempFile(self.r.file, self.r.file_ext)
                self.file_attach.set_file(file_path)
                self.remove_file_on_close.append(file_path)
Beispiel #9
0
    def setData(self, lessons, groups):
        if groups is None or len(groups) == 0 or lessons is None or len(
                lessons) == 0:
            return

        students = sorted(Student.of(groups), key=lambda x: x.full_name())
        model = VisitModel(lessons, students)
        self.new_visit.connect(model.on_new_visit)
        self.lesson_start.connect(model.on_lesson_start)
        self.view.setModel(model)

        percent_vertical_model = PercentVerticalModel(lessons, students)
        percent_vertical_model.mimic(self.view.model())
        self.view_show_color_rate.connect(
            percent_vertical_model.view_show_color_rate)
        self.percent_vertical_view.setModel(percent_vertical_model)

        percent_horizontal_model = PercentHorizontalModel(lessons, students)
        percent_horizontal_model.mimic(self.view.model())
        self.percent_horizontal_view.setModel(percent_horizontal_model)

        model.item_changed.connect(percent_horizontal_model.data_updated)
        model.item_changed.connect(percent_vertical_model.data_updated)
        self.view.select_row.connect(model.select_row)
Beispiel #10
0
    def __init__(self, file: str, start_day: datetime, professor: Professor, session: ISession):
        self.document = xlrd.open_workbook(filename=file)
        self.sheet = self.document.sheet_by_index(0)

        self.session: ISession = session

        group_regex = self.group_regex.findall(self.sheet.cell(*self.GROUP_CELL).value)
        if len(group_regex):
            group_name = group_regex[0]
            group = Group.get_or_create(self.session, name=group_name)
        else:
            raise ValueError('group is not found')

        discipline_regex = self.discipline_regex.findall(self.sheet.cell(*self.DISCIPLINE_CELL).value)
        if len(discipline_regex):
            discipline_name = discipline_regex[0]
            discipline = Discipline.get_or_create(self.session, name=discipline_name)
        else:
            raise ValueError('discipline is not found')

        self.students = list()
        for row in range(self.FULL_NAME_START_ROW, self.sheet.nrows):
            full_name = self.sheet.cell(row, self.TIME_START_COL).value
            if full_name not in [None, '']:
                student_regex = self.student_regex.findall(full_name)
                if len(student_regex):
                    if len(student_regex) == 2:
                        student = Student.get_or_create(self.session,
                                                        last_name=student_regex[0],
                                                        first_name=student_regex[1])
                    else:
                        student = Student.get_or_create(self.session,
                                                        last_name=student_regex[0],
                                                        first_name=student_regex[1],
                                                        middle_name=student_regex[2])
                    if student.id is None:
                        student.groups.append(group)

                    card_id = Get.card_id(self.sheet.cell(row, self.CARD_COL).value)
                    if card_id not in [None, ''] and card_id != student.card_id:
                        student.card_id = card_id

                    self.students.append(student)
            else:
                break

        self.lessons = list()
        for col in range(self.TIME_START_COL, self.sheet.ncols):
            lesson_index = self.sheet.cell(self.LESSON_INDEX_ROW, col).value
            if lesson_index not in [None, '']:
                date_regex = self.day_regex.findall(self.sheet.cell(self.DAY_ROW, col).value)
                if len(date_regex):
                    date_regex = date_regex[0]
                    month = int(date_regex[1])
                    day = int(date_regex[0])
                else:
                    raise ValueError(f'{self.sheet.cell(self.DAY_ROW, col).value} is not acceptable date format')

                time_regex = self.day_regex.findall(self.sheet.cell(self.TIME_ROW, col).value)
                if len(time_regex):
                    time_regex = time_regex[0]
                    hours = int(time_regex[0])
                    minutes = int(time_regex[1])
                else:
                    raise ValueError(f'{self.sheet.cell(self.TIME_ROW, col).value} is not acceptable time format')

                time = datetime(start_day.year, month, day, hours, minutes)

                kwargs = dict(room_id='', type=Lesson.Type.Practice)
                if discipline.id is None:
                    lesson = Lesson.new(self.session, date=time, professor_id=professor.id, **kwargs)
                    lesson.discipline = discipline
                    lesson.groups.append(group)
                else:
                    lesson = Lesson.get_or_create(
                        self.session,
                        date=time,
                        professor_id=professor.id,
                        discipline_id=discipline.id,
                        **kwargs)
                    if group not in lesson.groups:
                        lesson.groups.append(group)
                self.lessons.append(lesson)
            else:
                break

        self.discipline = discipline
        self.group = group
        self.session.commit()
        professor.session().expire_all()
Beispiel #11
0
 def _get_students(self, lesson_groups, groups):
     students = Student.of(lesson_groups)
     if groups is not None:
         students &= Student.of(groups)
     return students
Beispiel #12
0
from DataBase2 import Student
from Domain.Plot.plot import plot

if __name__ == '__main__':
    plot(Student.get(id=22))
Beispiel #13
0
        item.setCheckState(Qt.Unchecked)
        item.setSizeHint(QSize(self.width(), 25))

    def setItems(self, items):
        for item in items:
            self.addItem(item)

    def clear(self):
        super().clear()
        self.setModel(QStandardItemModel(self))
        self.items = []
        if self.with_all:
            self.addItem('All')

    # def addItem(self, *__args):
    #     model: QStandardItemModel = self.model()
    #     model.appendRow()


if __name__ == '__main__':
    app = QApplication(sys.argv)

    widget = CheckableComboBox()
    for st in Student.of(Professor.get(id=1)):
        widget.addItem(st)

    widget.show()
    widget.checked.connect(lambda x: print(widget.current()))

    sys.exit(app.exec_())
Beispiel #14
0
    def test_table_name_student(self):
        from DataBase2 import Student
        student = Student()

        self.assertEqual('Student', Values.Get.table_name(student))
Beispiel #15
0
        percent_vertical_model = PercentVerticalModel(lessons, students)
        percent_vertical_model.mimic(self.view.model())
        self.view_show_color_rate.connect(
            percent_vertical_model.view_show_color_rate)
        self.percent_vertical_view.setModel(percent_vertical_model)

        percent_horizontal_model = PercentHorizontalModel(lessons, students)
        percent_horizontal_model.mimic(self.view.model())
        self.percent_horizontal_view.setModel(percent_horizontal_model)

        model.item_changed.connect(percent_horizontal_model.data_updated)
        model.item_changed.connect(percent_vertical_model.data_updated)
        self.view.select_row.connect(model.select_row)
        # self.view.select_row.connect(percent_vertical_model.select_row)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    auth = Auth.log_in('VAE', '123456')
    group = Group.of(auth.user)[0]

    v = VisitTableWidget()
    v.setData(Lesson.of(group), Student.of(group))

    v.view.selectColumn(2)

    v.show()

    sys.exit(app.exec_())