Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adding grades to a term and enhance grade logic. #1436

Merged
merged 163 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 162 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
6682143
Add basic NavigationItem for grades
nilsreichardt Mar 12, 2024
fb53134
WIP: Grades system
nilsreichardt Mar 12, 2024
7db9984
Create simple test.
Jonas-Sander Mar 13, 2024
76d86ef
Create GradesTestController and use it in tests.
Jonas-Sander Mar 13, 2024
dd2c2aa
Add test for average note of multiple subjects.
Jonas-Sander Mar 13, 2024
a730568
Add term to second test
Jonas-Sander Mar 13, 2024
b46b484
Add term to first test.
Jonas-Sander Mar 13, 2024
ce087b8
Add test 'create two different terms and get average note'
Jonas-Sander Mar 13, 2024
216be34
move average grade calculation to term
Jonas-Sander Mar 13, 2024
32b5355
Add second test file
Jonas-Sander Mar 13, 2024
904fa9c
Add first simple test in new file.
Jonas-Sander Mar 13, 2024
d312a6f
Change test to get average grade of two different subjects in term
Jonas-Sander Mar 13, 2024
226189e
Update Term to be immutable
Jonas-Sander Mar 13, 2024
ab90892
Add test: the average grade of the term should equal the average of t…
Jonas-Sander Mar 13, 2024
b78941a
Remove term.addSubject
Jonas-Sander Mar 13, 2024
cb4ec44
Introduce new test with weights, skip it to refactor.
Jonas-Sander Mar 13, 2024
8910aee
Refactor Term to Use list of Subjects
Jonas-Sander Mar 13, 2024
98aa7e7
Implement weighting test.
Jonas-Sander Mar 13, 2024
1c78ff0
Implement with several weights
Jonas-Sander Mar 13, 2024
29f21c3
Make expect more clear
Jonas-Sander Mar 13, 2024
8c49abc
Add test 'one can add grades that are not taken into account for the …
Jonas-Sander Mar 13, 2024
113c2b8
Replace `getAverageGradeForSubject` with `getSubject().grade`
Jonas-Sander Mar 13, 2024
ef43dd5
change API to term.getSubject.addGrade
Jonas-Sander Mar 13, 2024
ab74a16
Add test: subjects can have custom weights per grade type (e.g. prese…
Jonas-Sander Mar 13, 2024
59d8ffa
various refactorings
Jonas-Sander Mar 13, 2024
9300023
refac
Jonas-Sander Mar 13, 2024
2d067fe
Replace Grade constructor with gradeWith method
Jonas-Sander Mar 14, 2024
2206722
Add GradeId
Jonas-Sander Mar 14, 2024
7b287a1
Rename SubjectResult.grade to gradeVal.
Jonas-Sander Mar 14, 2024
6f2602e
Add and implement test: subjects can have custom weights per grade
Jonas-Sander Mar 14, 2024
57e8061
Add .changeWeightingType(WeightType.perGradeType); in test
Jonas-Sander Mar 14, 2024
2efbfd7
Fix weight calculations
Jonas-Sander Mar 14, 2024
531e22b
Add weight example
Jonas-Sander Mar 14, 2024
e1de676
Add test 'grades for a subject will be weighted by the settings in te…
Jonas-Sander Mar 15, 2024
6073a45
Add test 'weighting of grades can be changed for a subject, then over…
Jonas-Sander Mar 15, 2024
8d57327
Add test "weight by grade setting in subject is persisted"
Jonas-Sander Mar 15, 2024
4b58632
Add test "The "Endnote" grade type overrides the subject grade"
Jonas-Sander Mar 15, 2024
2379eda
Add test 'Every subject can have a "Endnote" that overrides the terms…
Jonas-Sander Mar 15, 2024
f86c7d6
Add more abstract test 'The calculated grade of the term is the avera…
Jonas-Sander Mar 15, 2024
4be96b3
'The calculated grade of a subject is the average of the grades by de…
Jonas-Sander Mar 15, 2024
0c5069b
Add test 'the term grade should equal the average of the average grad…
Jonas-Sander Mar 15, 2024
447be63
refactor test
Jonas-Sander Mar 15, 2024
2e1afda
Create `Weight` class and use it in test.
Jonas-Sander Mar 15, 2024
b86a9d5
'grades that are marked as "Nicht in den Schnitt einbeziehen" should …
Jonas-Sander Mar 15, 2024
4ab3238
Generate GradeId in gradeWith
Jonas-Sander Mar 15, 2024
08193b4
Create and use `GradesService`.
Jonas-Sander Mar 15, 2024
c4cbfb2
Add gradeType weight tests.
Jonas-Sander Mar 15, 2024
86e454e
Change ordering
Jonas-Sander Mar 15, 2024
ebf3a5f
Dont specify term name parameter on termWith
Jonas-Sander Mar 15, 2024
9b00245
Dont change weightType automatically in test + add assert.
Jonas-Sander Mar 15, 2024
ffe844e
Add test "subjects can have custom weights per grade"
Jonas-Sander Mar 15, 2024
df3e179
Add test: 'grades for a subject will be weighted by the settings in t…
Jonas-Sander Mar 15, 2024
9bf4545
Add test: ''term weights can be overridden by a subject'
Jonas-Sander Mar 15, 2024
a687a29
Add test: 'a subjects gradeType weights are saved even when they are …
Jonas-Sander Mar 15, 2024
ef45c32
Add test: 'a subjects grade weights are saved even when they are deac…
Jonas-Sander Mar 15, 2024
236a780
Add test: "The "Endnote" grade type overrides the subject grade".
Jonas-Sander Mar 15, 2024
0eee498
Add test: 'A subject can have a custom "Endnote" that overrides the t…
Jonas-Sander Mar 15, 2024
fdc9f73
Add test: 'A user can have several terms'.
Jonas-Sander Mar 15, 2024
3d80672
Make GradesService.updateTerm private
Jonas-Sander Mar 19, 2024
5976c16
Remove old logic.
Jonas-Sander Mar 20, 2024
e073d6a
Move logic to app/lib/grades
Jonas-Sander Mar 20, 2024
f28a078
Merge remote-tracking branch 'origin/main' into grades-logic
Jonas-Sander Mar 20, 2024
7d5d291
Run sz pub get
Jonas-Sander Mar 20, 2024
50c68c5
Fix Id classes
Jonas-Sander Mar 20, 2024
bc938fa
Refactor and move grade files
Jonas-Sander Mar 20, 2024
bb881b7
Add test: 'If a term is created with "Aktuelles Halbjahr" set to true…
Jonas-Sander Mar 20, 2024
143010b
Add test: 'A term can have a name.'
Jonas-Sander Mar 20, 2024
2df0d7c
Fix not updating terms on createTerms
Jonas-Sander Mar 20, 2024
e9be8ff
Remove grades_2_test.dart
Jonas-Sander Mar 20, 2024
2a59aa4
Move `finalGradeType` to constructor of Term
Jonas-Sander Mar 20, 2024
374a450
Make _Grade const
Jonas-Sander Mar 20, 2024
89bd562
Remove old `grades_page.dart`
Jonas-Sander Mar 20, 2024
29f4b53
Fix const lints.
Jonas-Sander Mar 20, 2024
8b019c7
Add wip term dialog
Jonas-Sander Mar 20, 2024
a08ea2c
Add failing test: 'Creating a simple term works'
Jonas-Sander Mar 20, 2024
c101b87
Make test pass.
Jonas-Sander Mar 20, 2024
f23d763
Remove unused import
Jonas-Sander Mar 20, 2024
1c18aad
Change TermResult.subject from map to list
Jonas-Sander Mar 20, 2024
719a153
Change String subjectId to SubjectId class
Jonas-Sander Mar 20, 2024
415076c
Add license headers.
Jonas-Sander Mar 20, 2024
749ef38
Fix names and import between `grades_service.dart` and `term.dart`.
Jonas-Sander Mar 20, 2024
d8f6663
Run `sz build_runner build`.
Jonas-Sander Mar 20, 2024
9f52f6a
Update golden tests
nilsreichardt Mar 20, 2024
db76496
Update app/lib/navigation/drawer/tiles/drawer_tiles.dart
Jonas-Sander Mar 21, 2024
178841f
Make name in subjectWith not required
Jonas-Sander Mar 21, 2024
ad3e986
Create and use `CalculatedGradeResult` in tests.
Jonas-Sander Mar 21, 2024
3d62ed6
Add test with fake pass:" Basic grades test for 1+ to 6 grading system."
Jonas-Sander Mar 21, 2024
dbb9f3e
Add GradingSystem.toDoubleOrThrow
Jonas-Sander Mar 21, 2024
55877aa
Add fake GradingSystem.getClosestGrade
Jonas-Sander Mar 21, 2024
3bdf5b7
Implement GradingSystem.getClosestGrade
Jonas-Sander Mar 21, 2024
8733d64
Add `GradingSystem` to `_Subject`
Jonas-Sander Mar 21, 2024
e3e0fc5
Make inheriting class OneToSixWithPlusMinusGradingSystem
Jonas-Sander Mar 21, 2024
57a6ea7
Add and implement test: 'Basic grades test for 0 to 25 points grading…
Jonas-Sander Mar 21, 2024
6a409cc
Add empty next test
Jonas-Sander Mar 21, 2024
bd8b707
Add and implement test: 'Grades that are not in the same gradingSyste…
Jonas-Sander Mar 22, 2024
116cd85
Edit comment
Jonas-Sander Mar 22, 2024
0cae859
Add test: 'A term can have a grading system.'
Jonas-Sander Mar 22, 2024
58fd944
Add test and implement: 'The subject will use the Terms grading syste…
Jonas-Sander Mar 22, 2024
54df567
Use term grading system in existing tests
Jonas-Sander Mar 22, 2024
d6f3887
Move test
Jonas-Sander Mar 22, 2024
f6a566e
Add comment
Jonas-Sander Mar 22, 2024
c2c0edb
Make Grade.type required
Jonas-Sander Mar 22, 2024
85ec10a
Add and implement: 'Nicht in den Schnitt einbeziehen" will be deactiv…
Jonas-Sander Mar 23, 2024
e29b2d8
add .grade(id).isTakenIntoAccount to tests.
Jonas-Sander Mar 23, 2024
340b886
Create `GradingSystems` enum
Jonas-Sander Mar 23, 2024
526f21e
Remove gradingSystem from Subject
Jonas-Sander Mar 23, 2024
9142d91
Remove SubjectRes/GradeRes classes
Jonas-Sander Mar 23, 2024
91e01a3
Replace `CalculatedGradeResult.closestGrade` with `.displayableGrade`
Jonas-Sander Mar 25, 2024
8ac5868
Add `grade_systems_test.dart`
Jonas-Sander Mar 25, 2024
728f1b8
add license headers
Jonas-Sander Mar 25, 2024
380b140
Refactor grading systems test
Jonas-Sander Mar 25, 2024
3ac59e6
Change test name
Jonas-Sander Mar 26, 2024
72e2b0f
Add and implement test: 'Correct predefined grade types are existent'
Jonas-Sander Mar 26, 2024
b50d3ec
Change `GradeType` to `GradeTypeId extends Id`
Jonas-Sander Mar 26, 2024
711f8ea
Add TODO
Jonas-Sander Mar 26, 2024
251f6ae
Remove commented out code
Jonas-Sander Mar 26, 2024
984a90b
Add `GradeType` class
Jonas-Sander Mar 26, 2024
dccc0f3
Add `PredefinedGradeTypes` enum
Jonas-Sander Mar 26, 2024
8313b13
Refactor to GradeType constructors and GradeType.predefinedGradeTypes
Jonas-Sander Mar 26, 2024
52aba1a
Add doc comment
Jonas-Sander Mar 26, 2024
efb0b22
Add test and implement: 'A custom grade type can be created which wil…
Jonas-Sander Mar 26, 2024
6c94ea6
Use predefined GradeTypes in tests.
Jonas-Sander Mar 26, 2024
2f69468
Add `id` arg to `termWith`
Jonas-Sander Mar 26, 2024
6278174
Add and implement: 'Trying to add a grade with an non-existing gradeT…
Jonas-Sander Mar 26, 2024
71d7b66
Add test and implement: 'Adding a already existing grade type will do…
Jonas-Sander Mar 26, 2024
04e3f3e
Implement `createMissingGradeTypes` in the right way
Jonas-Sander Mar 26, 2024
7f3b951
Move grade type tests and shared test code to seperate files.
Jonas-Sander Mar 26, 2024
f267aaf
Move grading system tests to `grading_systems_test.dart`.
Jonas-Sander Mar 26, 2024
109768a
Add and implement: 'A grade has a Date'
Jonas-Sander Mar 27, 2024
d310d4a
Rename `GradesService.addSubject` to `GradesService.addSubjectToTerm`
Jonas-Sander Mar 27, 2024
1c8c952
Add and implement test: 'A subject has a Design'
Jonas-Sander Mar 27, 2024
5512814
Add and implement: `'If a subject with the same id is already existin…
Jonas-Sander Mar 27, 2024
5944070
Add comment
Jonas-Sander Mar 27, 2024
baffe56
Make "add grade" dialog functional.
Jonas-Sander Mar 27, 2024
cf87bb4
Add `Subject.name`
Jonas-Sander Mar 27, 2024
b0fa598
Add and implement: 'If a grade with an unknown subject id was added t…
Jonas-Sander Mar 27, 2024
87ed069
Add testing for term.subject.name for subject name
Jonas-Sander Mar 27, 2024
7853abb
Add and implement: 'adding a subject multiple times to a term does no…
Jonas-Sander Mar 27, 2024
194a1d7
Add test 'adding an unknown subject to a term throws $SubjectNotFound…
Jonas-Sander Mar 27, 2024
c8e5c22
refactor
Jonas-Sander Mar 27, 2024
dedea9e
Add doc
Jonas-Sander Mar 27, 2024
983addd
Change grading test to checking double and string grade results.
Jonas-Sander Mar 27, 2024
f3b1bb2
refactoring
Jonas-Sander Mar 27, 2024
3cc756d
Add/update test: 'A subject has a name and abbreviation'
Jonas-Sander Mar 27, 2024
0767a81
Replace abbreviation on grade page with real implementation.
Jonas-Sander Mar 27, 2024
f7dd89a
Add SubjectResult.design + test
Jonas-Sander Mar 27, 2024
6653a0b
Rename exceptions.
Jonas-Sander Mar 27, 2024
e0908e2
Create `grading_system.dart` and move classes
Jonas-Sander Mar 27, 2024
fd1f159
Create and use gradingSystem.toGradeResult
Jonas-Sander Mar 27, 2024
6068b83
Delete unused class CalculatedGradeRes
Jonas-Sander Mar 27, 2024
6dd599e
Make arg required
Jonas-Sander Mar 27, 2024
4f6bb05
org imports
Jonas-Sander Mar 27, 2024
f23085e
Make files part (of)
Jonas-Sander Mar 27, 2024
df5ef6e
Make Term, GradingSystem etc private
Jonas-Sander Mar 27, 2024
dff2441
Move date and takeIntoAccount to `Grade` class
Jonas-Sander Mar 27, 2024
c39c9dc
Use subject.name instead of .design in test
Jonas-Sander Mar 27, 2024
4f45e14
Remove TODO
Jonas-Sander Mar 27, 2024
3b3f143
Add subject to term implicitly when calling addGrade.
Jonas-Sander Mar 27, 2024
0439d6a
Remove TODOs
Jonas-Sander Mar 27, 2024
a2362a8
Add license headers.
Jonas-Sander Mar 27, 2024
e606635
Merge remote-tracking branch 'origin/main' into grades-logic-2
Jonas-Sander Mar 27, 2024
5873401
Make GradeType constructor calls static attributes
Jonas-Sander Mar 27, 2024
fc125f9
Rename 1 to 15 point grading system to 0 to 15 points.
Jonas-Sander Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 268 additions & 60 deletions app/lib/grades/grades_service/grades_service.dart

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions app/lib/grades/grades_service/src/grading_system.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

part of '../grades_service.dart';

extension _ToGradingSystem on GradingSystem {
_GradingSystem toGradingSystem() {
switch (this) {
case GradingSystem.oneToFiveteenPoints:
return _GradingSystem.oneToFiveteenPoints;
case GradingSystem.oneToSixWithPlusAndMinus:
return _GradingSystem.oneToSixWithPlusAndMinus;
}
}
}

extension _ToGradingSystems on _GradingSystem {
GradingSystem toGradingSystems() {
if (this is OneToFiveteenPointsGradingSystem) {
return GradingSystem.oneToFiveteenPoints;
} else if (this is OneToSixWithPlusMinusGradingSystem) {
return GradingSystem.oneToSixWithPlusAndMinus;
}
throw UnimplementedError();
}
}

sealed class _GradingSystem {
static final oneToSixWithPlusAndMinus = OneToSixWithPlusMinusGradingSystem();
static final oneToFiveteenPoints = OneToFiveteenPointsGradingSystem();

double toDoubleOrThrow(String grade);
IList<String> get possibleValues;

CalculatedGradeResult toGradeResult(num grade) {
final displayableGrade = toDisplayableGrade(grade);
return CalculatedGradeResult(
asNum: grade,
displayableGrade: displayableGrade,
);
}

String toDisplayableGrade(num grade) {
final res = getDisplayableGradeIfExactMatch(grade);
if (res != null) {
return res;
}
return grade.toStringAsFixed(2).replaceAll('.', ',').substring(0, 3);
}

String? getDisplayableGradeIfExactMatch(num grade);
}

class OneToFiveteenPointsGradingSystem extends _GradingSystem
Jonas-Sander marked this conversation as resolved.
Show resolved Hide resolved
with EquatableMixin {
@override
IList<String> get possibleValues => const IListConst([
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12',
'13',
'14',
'15',
]);

@override
double toDoubleOrThrow(String grade) {
return double.parse(grade);
}

@override
List<Object?> get props => [];

@override
String? getDisplayableGradeIfExactMatch(num grade) {
for (var val in possibleValues) {
if (int.parse(val) == grade) {
return val;
}
}
return null;
}
}

class OneToSixWithPlusMinusGradingSystem extends _GradingSystem
with EquatableMixin {
@override
IList<String> get possibleValues => const IListConst([
'1+',
'1',
'1-',
'2+',
'2',
'2-',
'3+',
'3',
'3-',
'4+',
'4',
'4-',
'5+',
'5',
'5-',
'6',
]);

@override
double toDoubleOrThrow(String grade) {
return switch (grade) {
'1+' => 0.75,
'1' => 1,
'1-' => 1.25,
'2+' => 1.75,
'2' => 2,
'2-' => 2.25,
'3+' => 2.75,
'3' => 3,
'3-' => 3.25,
'4+' => 3.75,
'4' => 4,
'4-' => 4.25,
'5+' => 4.75,
'5' => 5,
'5-' => 5.25,
'6' => 6,
_ => throw ArgumentError.value(
grade,
'grade',
'Invalid grade value',
),
};
}

@override
List<Object?> get props => [];

@override
String? getDisplayableGradeIfExactMatch(num grade) {
for (var val in possibleValues) {
if (toDoubleOrThrow(val) == grade) {
return val;
}
}
return null;
}
}
Loading
Loading