hslu-simple-mep-results
hslu-simple-mep-results copied to clipboard
Extension does not consider first two semesters
Describe the bug The diagram starts in the third semester instead of the first.
Expected behavior My earned and planed credits are shown correctly on the diagram.
Actual behavior It starts displaying my credits from the third semester instead of from the first semester.
Steps to Reproduce [ Tell us how to reproduce the bug. ] For me its just opening the "Meine Anmeldungen" page. I started in the spring semester so i dont know if that could be a factor but i know that my colleagues which also started in the same semester do not have this issue.
Screenshots
Contributing (please choose one)
- [X] I'd like to help implementing this feature!
- [ ] I don't have the time to work on this.
The issue is probably caused by improper first semester detection. Spring semesters are not recognized as possible first semesters and Info modules like the INFO_ABEND are not ignored as they should be.
Old bad code:
firstModule = anlasslistApiResponse.items
.slice()
.reverse()
.find(modul => ModuleParser.isAutumnSemester(modul.anlassnumber) != undefined);
With following method further up:
/**
* Check if a module was done in Autumn.
* Modules are marked with 'H' for 'Herbstsemester' (autumn)
* or 'F' for 'Frühlingssemester' (spring).
*/
isAutumnSemester: (hsluModuleName) => {
const includesH = hsluModuleName.split('.')[2].includes('H');
const includesF = hsluModuleName.split('.')[2].includes('F');
return includesH || includesF ? includesH : undefined;
},
New and improved code:
let firstSpringModule = anlasslistApiResponse.items
.slice()
.reverse()
.find(modul => ModuleParser.isSpringSemester(modul.anlassnumber));
let firstAutumnModule = anlasslistApiResponse.items
.slice()
.reverse()
.find(modul => ModuleParser.isAutumnSemester(modul.anlassnumber));
if (new Date(firstAutumnModule.from).getFullYear() < (new Date(firstSpringModule.from).getFullYear())) {
firstModule = firstAutumnModule
} else {
firstModule = firstSpringModule
}
And further up I needed to change or add following methods:
/**
* Check if a module is an info module
* Info modules contain INFO in their name
*/
isNotInfoSemester: (hsluModuleName) => {
return !hsluModuleName.includes('INFO')
},
/**
* Check if a module was done in Autumn.
* Modules are marked with 'H' for 'Herbstsemester' (autumn)
*/
isAutumnSemester: (hsluModuleName) => {
return hsluModuleName.split('.')[2].includes('H') && ModuleParser.isNotInfoSemester(hsluModuleName);
},
/**
* Check if a module was done in Spring.
* Modules are marked with 'F' for 'Frühlingssemester' (spring).
*/
isSpringSemester: (hsluModuleName) => {
return hsluModuleName.split('.')[2].includes('F') && ModuleParser.isNotInfoSemester(hsluModuleName);
},
-> I've fixed it locally but couldn't yet be bothered to push it.