Ejemplo n.º 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
Ejemplo n.º 2
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
     ])
Ejemplo n.º 3
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}")
Ejemplo n.º 4
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
            )
Ejemplo n.º 5
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()
Ejemplo n.º 6
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
                 ])
Ejemplo n.º 7
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()