Esempio n. 1
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)
Esempio n. 2
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
Esempio n. 3
0
 def count_visits(self, row: int) -> int:
     """
     Возвращает количество посещений для указанной строки
     :param row: индекс строки
     :return: колчиество посещений
     """
     return len([
         item for item in Visitation.of(self.lessons)
         if item.student_id == self.students[row].id
     ])
Esempio n. 4
0
 def __show_student_summary(self, student, professor, discipline):
     lessons = list(
         filter(lambda x: x.completed,
                Lesson.intersect(professor, discipline, student)))
     visitation = Visitation.journal(student, lessons)
     QMessageBox().information(
         self, "Информация",
         f'Студент {student.full_name()} {agree_to_gender("посетил", student.full_name())} '
         f'{len(visitation)} из {len(lessons)} {agree_to_number("занятий", len(lessons))} '
         f'({round(len(visitation) / len(lessons) * 100 if len(visitation) else 0)})'
         + (' превысив допустимое количество пропусков.'
            if len(visitation) < len(lessons) - 3 else '.'))
Esempio n. 5
0
def debug(user):
    """
    Исправляет все отрицаительные идентификаторы обратно на положительные
    :param user:
    :return:
    """
    count = 0
    for visit in Visitation.of(user):
        if visit.id < 0:
            count += 1
            visit.id *= -1
            user.session().commit()
    logging.getLogger("synch").info(f"debug wrong id count={count}")
Esempio n. 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
            )
Esempio n. 7
0
    def headerData(self, p_int, orientation, role=None):
        if role == Qt.DisplayRole:
            if orientation == Qt.Vertical:
                return self.students[p_int].short_name()
            if orientation == Qt.Horizontal:
                return rept(self.lessons[p_int])
        if role == self.CardIdRole:
            if orientation == Qt.Vertical:
                return self.students[p_int].card_id
        if role == Qt.SizeHintRole:
            if orientation == Qt.Vertical:
                return QVariant()
            if orientation == Qt.Horizontal:
                return QVariant(QSize(COLUMN_WIDTH, HEADER_HEIGHT))
        if role == Qt.BackgroundColorRole:
            if orientation == Qt.Vertical:
                s = Settings.inst().colors

                if not Validate.card_id(self.students[p_int].card_id):
                    return QColor(s.missing_card)

                total = len([l for l in self.lessons if l.completed])
                visit = len([
                    item for item in Visitation.of(self.lessons)
                    if item.student_id == self.students[p_int].id
                ])

                # если количество пропусков меньше 3х - студент хороший
                if total <= visit + 3:
                    return QColor(s.good_student)

                # если пропусков больше половины - студент плохой
                elif visit / total < 0.5 if total > 0 else False:
                    return QColor(s.bad_student)

                return [Color.primary_light, Color.secondary_light
                        ][Validate.card_id(self.students[p_int].card_id)]
            if orientation == Qt.Horizontal:
                if self.current_lesson == self.lessons[p_int]:
                    return Color.primary
                else:
                    return QVariant()
        if role == self.ValueRole:
            if orientation == Qt.Horizontal:
                return self.lessons[p_int]
            if orientation == Qt.Vertical:
                return self.students[p_int]
        if role == Qt.ToolTipRole:
            if orientation == Qt.Horizontal:
                return self.lessons[p_int].repr()
Esempio n. 8
0
 def test_visitation(self):
     self.assertEqual(
         {
             '_created': None,
             '_deleted': None,
             '_is_deleted': None,
             '_updated': None,
             'id': 1,
             'lesson': None,
             'lesson_id': 3,
             'student': None,
             'student_id': 6
         },
         JsonParser.read(
             JsonParser.dump(Visitation(id=1, lesson_id=3, student_id=6))))
Esempio n. 9
0
 def data(self, index: QModelIndex, role=None):
     lesson = self.lessons[index.column()]
     if index.isValid():
         if role == Qt.DisplayRole:
             visitations = Visitation.of(lesson)
             if index.row() == 0:
                 return round(100 / len(self.students) * len([
                     item for item in visitations
                     if item.student in self.students
                 ])) if len(self.students) else 0
             if index.row() == 1:
                 return len([
                     item for item in visitations
                     if item.student in self.students
                 ])
Esempio n. 10
0
        def request_type_of_uncompliting_lessons(lesson):
            def delete_all():
                visitations: List[Visitation] = lesson.visitations
                for visit in visitations:
                    visit.delete()

                lesson.completed = False
                lesson.session().commit()

            def save_all():
                lesson.completed = False
                lesson.session().commit()

            if len(Visitation.of(lesson, with_deleted=False)) == 0:
                save_all()
            else:
                self.request = QRequestUncompleteLesson(lesson)
                self.request.save_all.connect(save_all)
                self.request.delete_all.connect(delete_all)
                self.request.show()
Esempio n. 11
0
    def __init__(self, professor=None, groups=None, disciplines=None):
        lessons = Lesson.of(professor)
        if groups is not None:
            lessons &= Lesson.of(groups)
        if disciplines is not None:
            lessons &= Lesson.of(disciplines)

        self.rows: List[row] = []
        for lesson in lessons:
            students = self._get_students(lesson.groups, groups)

            for student in students:
                visitation = Visitation.get(professor.session(),
                                            student_id=student.id,
                                            lesson_id=lesson.id)
                status = 0 if not visitation else 1
                self.rows.append(
                    row(Vector(status, int(lesson.completed)), lesson,
                        student))

        self.data: Dict[Any, List[row]] = {}
        self.ignored = []
Esempio n. 12
0
    def setData(self, index: QModelIndex, value, role=None):
        if role == Qt.EditRole:
            item = self.itemData(index)
            if value == True:
                if item is None:
                    student = self.students[index.row()]
                    lesson = self.lessons[index.column()]
                    session = inspect(student).session
                    visit = Visitation.new(student_id=student.id,
                                           lesson_id=lesson.id)

                    session.add(visit)

                    session.commit()

                    session.expire(lesson)
                    session.expire(student)
                else:
                    item._is_deleted = False
            else:
                item.delete()
                item.session().commit()

            self.item_changed.emit(index.row(), index.column())
Esempio n. 13
0
 def test_visitation_simple(self):
     visit = Visitation(id=6, lesson_id=4, student_id=12)
     self.assertEqual(visit._dict(),
                      JsonParser.read(JsonParser.dump(visit)))
Esempio n. 14
0
 def mark_visit(student):
     visit = Visitation.get_or_create(self.session, student_id=student.id, lesson_id=self.lesson.id)
     self.session.commit()
     self.session.expire(student)
     self.session.expire(self.lesson)
     self.new_visit.emit(visit, student, self.lesson)