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

Fix program selection for profile page #846

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions lib/core/constants/programs_credits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class ProgramCredits {
"6556": 117,
"6557": 118,
"7086": 116,
// TODO: Ajouter le code lorsque le programme sera en vigeur
// (https://www.etsmtl.ca/etudes/premier-cycle/Baccalaureat-informatique-distribuee)
// "À venir" : 90",
"6646": 90,
"5766": 30,
"4567": 30,
"4412": 30,
Expand Down
18 changes: 13 additions & 5 deletions lib/core/viewmodels/profile_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,27 @@ class ProfileViewModel extends FutureViewModel<List<Program>> {
int percentage = 0;

if (programList.isNotEmpty) {
Program currentProgram = programList.first;
for (final program in programList) {
if (int.parse(program.registeredCredits) >
int.parse(currentProgram.registeredCredits)) {
currentProgram = program;
}
}
final int numberOfCreditsCompleted =
int.parse(programList[programList.length - 1].accumulatedCredits);
final String code = programList[programList.length - 1].code;
int.parse(currentProgram.accumulatedCredits);
final String code = currentProgram.code;
bool foundMatch = false;

programCredits.programsCredits.forEach((key, value) {
if (key == code ||
programList[programList.length - 1].name.startsWith(key)) {
if (key == code || currentProgram.name.startsWith(key)) {
percentage = (numberOfCreditsCompleted / value * 100).round();
foundMatch = true;
}
});

if (!foundMatch) {
final String programName = programList[programList.length - 1].name;
final String programName = currentProgram.name;
analyticsService.logEvent("profile_view",
'The program $programName (code: $code) does not match any program');
percentage = 0;
Expand All @@ -91,6 +97,8 @@ class ProfileViewModel extends FutureViewModel<List<Program>> {
}

_programList.sort((a, b) => b.status.compareTo(a.status));
_programList
.sort((a, b) => a.registeredCredits.compareTo(b.registeredCredits));

return _programList;
}
Expand Down
Loading