Skip to content

Commit

Permalink
Don't show average grade if grading system is not numerical. (#1442)
Browse files Browse the repository at this point in the history
Don't show the calculated average grade if the grading system is not
numerical. To be able to do this I added `GradeResult.gradingSystem` and
`GradeValue.gradingSystem`.

Before:

![image](https://github.com/SharezoneApp/sharezone-app/assets/29028262/d0eae3a3-f5db-4c0c-ba6d-0d0a2032e36d)

After:

![image](https://github.com/SharezoneApp/sharezone-app/assets/29028262/8ab3adf2-5d30-45e7-a54d-3711070c08a4)
 
Requires #1441

---------

Co-authored-by: Jonas <--help>
  • Loading branch information
Jonas-Sander authored Apr 10, 2024
1 parent 959125e commit 01dafc8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/lib/grades/grades_service/grades_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class GradeResult {
final GradeValue value;
final bool isTakenIntoAccount;
final Date date;
GradingSystem get gradingSystem => value.gradingSystem;

GradeResult({
required this.id,
Expand Down Expand Up @@ -447,6 +448,8 @@ class GradeValue extends Equatable {
double get asDouble => asNum.toDouble();
final num asNum;

final GradingSystem gradingSystem;

/// Only available if there is a special displayable grade for the calculated
/// grade. For example, if the calculated grade is 2.25, the displayable grade
/// could be '2+' for the (1-6 with +-) grading system.
Expand All @@ -457,12 +460,14 @@ class GradeValue extends Equatable {
final String? suffix;

@override
List<Object?> get props => [asNum, displayableGrade, suffix];
List<Object?> get props => [asNum, gradingSystem, displayableGrade, suffix];

const GradeValue(
{required this.asNum,
required this.displayableGrade,
required this.suffix});
const GradeValue({
required this.asNum,
required this.gradingSystem,
required this.displayableGrade,
required this.suffix,
});
}

class Grade {
Expand Down
1 change: 1 addition & 0 deletions app/lib/grades/grades_service/src/grading_systems.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class _GradingSystem {
GradeValue toGradeResult(num grade) {
return GradeValue(
asNum: grade,
gradingSystem: toGradingSystems(),
displayableGrade: spec.getSpecialDisplayableGradeOrNull?.call(grade),
suffix: spec == zeroToHundredPercentWithDecimalsSpec ? '%' : null,
);
Expand Down
3 changes: 3 additions & 0 deletions app/lib/grades/pages/grades_page/grades_page_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class GradesPageController extends ChangeNotifier {
// This is not covered by tests yet.
String displayGrade(GradeValue? grade) {
if (grade == null) return '—';
if (!grade.gradingSystem.isNumericalAndContinous) {
return grade.displayableGrade ?? '—';
}

String withSuffix(String gs) => '$gs${grade.suffix ?? ''}';

Expand Down
39 changes: 39 additions & 0 deletions app/test/grades/grades_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,45 @@ void main() {
.date,
Date('2024-03-26'));
});
test('A grade and GradeValue has a gradingSystem', () {
final controller = GradesTestController();

final term = termWith(
subjects: [
subjectWith(
id: const SubjectId('Philosophie'),
grades: [
gradeWith(
id: GradeId('grade1'),
gradingSystem: GradingSystem.oneToFiveWithDecimals,
value: 2.5,
),
gradeWith(
id: GradeId('grade2'),
gradingSystem: GradingSystem.sixToOneWithDecimals,
value: 4.2,
),
],
),
],
);
controller.createTerm(term);

final grade1 = controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade1'));
// On both since the calculated averageGrade is only a [GradeValue], not a [GradeResult].
expect(grade1.gradingSystem, GradingSystem.oneToFiveWithDecimals);
expect(grade1.value.gradingSystem, GradingSystem.oneToFiveWithDecimals);

final grade2 = controller
.term(term.id)
.subject(const SubjectId('Philosophie'))
.grade(GradeId('grade2'));
expect(grade2.gradingSystem, GradingSystem.sixToOneWithDecimals);
expect(grade2.value.gradingSystem, GradingSystem.sixToOneWithDecimals);
});
test('A subject has a Design', () {
final controller = GradesTestController();

Expand Down

0 comments on commit 01dafc8

Please sign in to comment.