feat(theme/preview): improve test pages

This commit is contained in:
2026-08-16 16:30:27 +02:00
parent 3f42226013
commit 2f9f560c84
3 changed files with 50 additions and 17 deletions

View File

@@ -19,6 +19,7 @@ class ThemePreviewData {
required this.messages,
required this.tests,
required this.grades,
required this.chartGrades,
required this.omissions,
required this.omissionBarSegments,
required this.omissionExcusedCount,
@@ -38,6 +39,7 @@ class ThemePreviewData {
final List<MessageCacheModel> messages;
final List<TestCacheModel> tests;
final List<GradeCacheModel> grades;
final List<GradeCacheModel> chartGrades;
final List<OmissionCacheModel> omissions;
final List<OmissionState?> omissionBarSegments;
final int omissionExcusedCount;
@@ -208,6 +210,31 @@ class ThemePreviewData {
_grade(509, matematika, 5, midnight.subtract(const Duration(days: 15))),
];
final sept = DateTime(
day.month >= DateTime.september ? day.year : day.year - 1,
DateTime.september,
15,
);
final chartSpanDays = day.difference(sept).inDays.clamp(1, 365);
const chartValues = [
1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
4, 4, 3, 3, 4, 4, 4, 4, 5, 5,
5, 4, 4, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
];
final chartGrades = [
for (var i = 0; i < chartValues.length; i++)
_grade(
700 + i,
matematika,
chartValues[i],
sept.add(
Duration(days: (i * chartSpanDays / (chartValues.length - 1)).round()),
),
),
];
final omissions = [
_omission(
601,
@@ -318,6 +345,7 @@ class ThemePreviewData {
messages: messages,
tests: [homeTest],
grades: grades,
chartGrades: chartGrades,
omissions: omissions,
omissionBarSegments: omissionBarSegments,
omissionExcusedCount: 2,
@@ -380,8 +408,9 @@ class ThemePreviewData {
int id,
SubjectCacheModel subject,
int value,
DateTime at,
) {
DateTime at, {
int? weightPercentage = 100,
}) {
final grade = GradeCacheModel()
..cacheKey = id
..createdAt = at
@@ -391,7 +420,7 @@ class ThemePreviewData {
..valueType = "Osztalyzat"
..writtenAt = at
..numericValue = value
..weightPercentage = 100
..weightPercentage = weightPercentage
..textValue = value.toString()
..teacherName = "Tanár";
grade.subject.value = subject;

View File

@@ -167,9 +167,9 @@ class ThemePreviewHomeGrades extends StatelessWidget {
),
),
const SizedBox(height: 20),
GradeChart(grades: allGrades),
GradeChart(grades: preview.chartGrades, plotRawValues: true),
const SizedBox(height: 10),
GradeSummaryBar(grades: allGrades, l10n: data.l10n),
GradeSummaryBar(grades: preview.chartGrades, l10n: data.l10n),
const SizedBox(height: 20),
Expanded(
child: ListView(

View File

@@ -13,10 +13,12 @@ import 'package:flutter/material.dart';
class GradeChart extends StatefulWidget {
final List<GradeCacheModel> grades;
final bool halfYearFallback;
final bool plotRawValues;
GradeChart({
super.key,
required List<GradeCacheModel> grades,
this.halfYearFallback = true,
this.plotRawValues = false,
}) : grades = grades.where((g) => g.hasClassicValue()).toList()
..sort((a, b) => a.writtenAt.compareTo(b.writtenAt));
@@ -49,19 +51,21 @@ class _GradeChartState extends State<GradeChart> {
void _computeSpots() {
spots = [];
for (var i = 0; i < widget.grades.length; i++) {
final grade = widget.grades[i];
if (!grade.shouldIncludeInAverage()) {
continue;
if (!widget.plotRawValues) {
for (var i = 0; i < widget.grades.length; i++) {
final grade = widget.grades[i];
if (!grade.shouldIncludeInAverage()) {
continue;
}
final partialAvg = widget.grades
.take(i + 1)
.getSubjectAverage(halfYearFallback: widget.halfYearFallback);
spots.add(
DateSpot(spots.length.toDouble(), partialAvg!, grade.writtenAt),
);
}
final partialAvg = widget.grades
.take(i + 1)
.getSubjectAverage(halfYearFallback: widget.halfYearFallback);
spots.add(
DateSpot(spots.length.toDouble(), partialAvg!, grade.writtenAt),
);
}
if (spots.isEmpty) {