diff --git a/app/app/data.py b/app/app/data.py index 62e44b4..88e22be 100644 --- a/app/app/data.py +++ b/app/app/data.py @@ -1233,6 +1233,16 @@ def duration_text_from_minutes(minutes: int) -> str: return f"{minutes // 60}小时{minutes % 60}分" +def duration_text_from_hours(hours: float) -> str: + total_minutes = int(round(float(hours or 0) * 60)) + sign = "-" if total_minutes < 0 else "" + return f"{sign}{duration_text_from_minutes(abs(total_minutes))}" + + +def duration_text_map(values: dict[str, float]) -> dict[str, str]: + return {key: duration_text_from_hours(value) for key, value in values.items()} + + def duration_minutes_from_time_range(time_range: str) -> int | None: if not time_range: return None @@ -2718,12 +2728,20 @@ def summarize_records(records: list[ClassRecord]) -> dict: by_student[record.student] += record.duration_hours by_teacher[record.teacher] += record.duration_hours by_subject[record.subject] += record.duration_hours + students = dict(sorted((key, round(value, 2)) for key, value in by_student.items())) + teachers = dict(sorted((key, round(value, 2)) for key, value in by_teacher.items())) + subjects = dict(sorted((key, round(value, 2)) for key, value in by_subject.items())) + total_hours = round(sum(record.duration_hours for record in records), 2) return { "count": len(records), - "total_hours": round(sum(record.duration_hours for record in records), 2), - "students": dict(sorted((key, round(value, 2)) for key, value in by_student.items())), - "teachers": dict(sorted((key, round(value, 2)) for key, value in by_teacher.items())), - "subjects": dict(sorted((key, round(value, 2)) for key, value in by_subject.items())), + "total_hours": total_hours, + "total_duration": duration_text_from_hours(total_hours), + "students": students, + "students_duration": duration_text_map(students), + "teachers": teachers, + "teachers_duration": duration_text_map(teachers), + "subjects": subjects, + "subjects_duration": duration_text_map(subjects), } @@ -2736,12 +2754,20 @@ def summarize_public_records(records: list[ClassRecord], teachers: list[Teacher] by_student[record.student] += record.duration_hours by_teacher[display_names.get(record.teacher, record.teacher)] += record.duration_hours by_subject[record.subject] += record.duration_hours + students = dict(sorted((key, round(value, 2)) for key, value in by_student.items())) + teachers_summary = dict(sorted((key, round(value, 2)) for key, value in by_teacher.items())) + subjects = dict(sorted((key, round(value, 2)) for key, value in by_subject.items())) + total_hours = round(sum(record.duration_hours for record in records), 2) return { "count": len(records), - "total_hours": round(sum(record.duration_hours for record in records), 2), - "students": dict(sorted((key, round(value, 2)) for key, value in by_student.items())), - "teachers": dict(sorted((key, round(value, 2)) for key, value in by_teacher.items())), - "subjects": dict(sorted((key, round(value, 2)) for key, value in by_subject.items())), + "total_hours": total_hours, + "total_duration": duration_text_from_hours(total_hours), + "students": students, + "students_duration": duration_text_map(students), + "teachers": teachers_summary, + "teachers_duration": duration_text_map(teachers_summary), + "subjects": subjects, + "subjects_duration": duration_text_map(subjects), } @@ -2798,9 +2824,13 @@ def account_to_dict(account: Account) -> dict: return { "student_id": account.student_id, "student": account.student, - "payments": [{"date": payment.date, "hours": payment.hours} for payment in account.payments], + "payments": [ + {"date": payment.date, "hours": payment.hours, "duration": duration_text_from_hours(payment.hours)} + for payment in account.payments + ], "payments_count": len(account.payments), "remaining": account.remaining, + "remaining_duration": duration_text_from_hours(account.remaining), "account_status": account.account_status, "note": account.note, } diff --git a/app/app/static/accounts.html b/app/app/static/accounts.html index 5a0214c..41a268b 100644 --- a/app/app/static/accounts.html +++ b/app/app/static/accounts.html @@ -4,7 +4,7 @@