Skip to content

Commit

Permalink
Add option to scale up tests before calculating the average
Browse files Browse the repository at this point in the history
  • Loading branch information
FauconSpartiate committed Dec 29, 2024
1 parent fb6ecdb commit b752380
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 334 deletions.
16 changes: 11 additions & 5 deletions lib/calculations/calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,26 @@ class Calculator {

if (data.isEmpty || isNullFilled) return null;

final double maxGrade = Manager.years.isNotEmpty ? getCurrentYear().maxGrade : getPreference("maxGrade");
final double maxGrade = Manager.years.isNotEmpty ? getCurrentYear().maxGrade : getPreference<double>("maxGrade");
final bool scaleUpTests = Manager.years.isNotEmpty ? getCurrentYear().scaleUpTests : getPreference<bool>("scaleUpTests");

double totalNumerator = 0;
double totalDenominator = 0;
double totalNumeratorSpeaking = 0;
double totalDenominatorSpeaking = 0;

for (final CalculationObject c in data.where((element) => element.numerator != null && element.denominator != 0)) {
final double maxGradeMultiplier = scaleUpTests ? maxGrade / c.denominator : 1;

final double weightedNumerator = c.numerator! * c.weight * maxGradeMultiplier;
final double weightedDenominator = c.denominator * c.weight * maxGradeMultiplier;

if (c is Test && c.isSpeaking) {
totalNumeratorSpeaking += c.numerator! * c.weight;
totalDenominatorSpeaking += c.denominator * c.weight;
totalNumeratorSpeaking += weightedNumerator;
totalDenominatorSpeaking += weightedDenominator;
} else {
totalNumerator += c.numerator! * c.weight;
totalDenominator += c.denominator * c.weight;
totalNumerator += weightedNumerator;
totalDenominator += weightedDenominator;
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/calculations/year.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Year extends CalculationObject {
double maxGrade = DefaultValues.maxGrade;
String roundingMode = DefaultValues.roundingMode;
int roundTo = DefaultValues.roundTo;
bool scaleUpTests = DefaultValues.scaleUpTests;

bool isYearOverview = false;
bool hasBeenSortedCustom = false;
Expand Down Expand Up @@ -174,6 +175,7 @@ class Year extends CalculationObject {
maxGrade = json["maxGrade"] as double? ?? DefaultValues.maxGrade;
roundingMode = json["roundingMode"] as String? ?? DefaultValues.roundingMode;
roundTo = json["roundTo"] as int? ?? DefaultValues.roundTo;
scaleUpTests = (json["scaleUpTests"] as bool?) ?? DefaultValues.scaleUpTests;

hasBeenSortedCustom = (json["hasBeenSortedCustom"] as bool?) ?? DefaultValues.hasBeenSortedCustom;
}
Expand All @@ -184,6 +186,7 @@ class Year extends CalculationObject {
"maxGrade": maxGrade,
"roundingMode": roundingMode,
"roundTo": roundTo,
"scaleUpTests": scaleUpTests,
"validatedSchoolSystem": validatedSchoolSystem,
"validatedLuxSystem": validatedLuxSystem,
"validatedYear": validatedYear,
Expand Down
4 changes: 4 additions & 0 deletions lib/localization/generated/intl/messages_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class MessageLookup extends MessageLookupByLibrary {
"rounding_mode":
MessageLookupByLibrary.simpleMessage("Abrundungsmodus"),
"save": MessageLookupByLibrary.simpleMessage("Speichern"),
"scale_up_tests":
MessageLookupByLibrary.simpleMessage("Prüfungen skalieren"),
"scale_up_tests_description": MessageLookupByLibrary.simpleMessage(
"Prüfungen zur max. Note skalieren bevor der Durchschnitt berechnet wird"),
"school_system": MessageLookupByLibrary.simpleMessage("Schulsystem"),
"school_termOne": MessageLookupByLibrary.simpleMessage("Schulperiode"),
"school_termOther":
Expand Down
4 changes: 4 additions & 0 deletions lib/localization/generated/intl/messages_en_GB.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class MessageLookup extends MessageLookupByLibrary {
"round_to": MessageLookupByLibrary.simpleMessage("Round to"),
"rounding_mode": MessageLookupByLibrary.simpleMessage("Rounding mode"),
"save": MessageLookupByLibrary.simpleMessage("Save"),
"scale_up_tests":
MessageLookupByLibrary.simpleMessage("Scale up tests"),
"scale_up_tests_description": MessageLookupByLibrary.simpleMessage(
"Scale up tests to the max. grade before calculating the average"),
"school_system": MessageLookupByLibrary.simpleMessage("School system"),
"school_termOne": MessageLookupByLibrary.simpleMessage("School term"),
"school_termOther":
Expand Down
4 changes: 4 additions & 0 deletions lib/localization/generated/intl/messages_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ class MessageLookup extends MessageLookupByLibrary {
"rounding_mode":
MessageLookupByLibrary.simpleMessage("Mode arrondissage"),
"save": MessageLookupByLibrary.simpleMessage("Sauvegarder"),
"scale_up_tests":
MessageLookupByLibrary.simpleMessage("Étendre les devoirs"),
"scale_up_tests_description": MessageLookupByLibrary.simpleMessage(
"Étendre les devoirs à la note max. avant de calculer la moyenne"),
"school_system":
MessageLookupByLibrary.simpleMessage("Système scolaire"),
"school_termOne":
Expand Down
4 changes: 4 additions & 0 deletions lib/localization/generated/intl/messages_lb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class MessageLookup extends MessageLookupByLibrary {
"rounding_mode":
MessageLookupByLibrary.simpleMessage("Ofronnungsmodus"),
"save": MessageLookupByLibrary.simpleMessage("Späicheren"),
"scale_up_tests":
MessageLookupByLibrary.simpleMessage("Prüfungen skaléieren"),
"scale_up_tests_description": MessageLookupByLibrary.simpleMessage(
"Prüfungen zur max. Notte skaléieren virun dass d\'Moyenne gerechent gëtt"),
"school_system": MessageLookupByLibrary.simpleMessage("Schoulsystem"),
"school_termOne": MessageLookupByLibrary.simpleMessage("Schoulperiod"),
"school_termOther":
Expand Down
4 changes: 4 additions & 0 deletions lib/localization/generated/intl/messages_nl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class MessageLookup extends MessageLookupByLibrary {
"round_to": MessageLookupByLibrary.simpleMessage("Rond naar"),
"rounding_mode": MessageLookupByLibrary.simpleMessage("Ronde modus"),
"save": MessageLookupByLibrary.simpleMessage("Opslaan"),
"scale_up_tests":
MessageLookupByLibrary.simpleMessage("Toetsen opschalen"),
"scale_up_tests_description": MessageLookupByLibrary.simpleMessage(
"Toetsen opschalen tot het max. cijfer voordat het gemiddelde wordt berekend"),
"school_system": MessageLookupByLibrary.simpleMessage("Schoolsysteem"),
"school_termOne": MessageLookupByLibrary.simpleMessage("Schoolperiode"),
"school_termOther":
Expand Down
20 changes: 20 additions & 0 deletions lib/localization/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/misc/default_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DefaultValues {
static const String roundingMode = RoundingMode.up;
static const int roundTo = 1;
static const int preciseRoundToMultiplier = 10;
static const bool scaleUpTests = false;
static const double weight = 1.0;
static const double bonus = 1;
static const double speakingWeight = 3.0;
Expand Down Expand Up @@ -63,6 +64,7 @@ const Map<String, dynamic> defaultValues = {
"roundingMode": RoundingMode.up,
"roundTo": 1,
"preciseRoundToMultiplier": 10,
"scaleUpTests": false,
"weight": 1.0,
"speakingWeight": 3.0,
"examWeight": 2.0,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/utilities/app_theme.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Flutter imports:
import "package:dynamic_color/dynamic_color.dart";
import "package:flutter/material.dart";

// Package imports:
import "package:animations/animations.dart";
import "package:dynamic_color/dynamic_color.dart";
import "package:flex_color_scheme/flex_color_scheme.dart";

// Project imports:
Expand Down
Loading

0 comments on commit b752380

Please # to comment.