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

added ignore module pattern to calculate the first semester, solves #95 #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion src/components/module_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ const ModuleParser = {
}
return false
},
/**
* list of modules that should be ignored to calculate the first semester
* check if moduleName matches ignore pattern
*/
shouldModuleBeIgnored: (hsluModuleName) => {
const ignoreModulePatterns = ['INFO_ABEND'];
let dontIgnore = true;
ignoreModulePatterns.forEach(ignorePattern => {
if(hsluModuleName.includes(ignorePattern)) {
console.log(`ignoring module ${hsluModuleName} for first semester calculation`)
dontIgnore = false;
}
})

return dontIgnore;
Comment on lines +138 to +146

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let dontIgnore = true;
ignoreModulePatterns.forEach(ignorePattern => {
if(hsluModuleName.includes(ignorePattern)) {
console.log(`ignoring module ${hsluModuleName} for first semester calculation`)
dontIgnore = false;
}
})
return dontIgnore;
return ignoreModulePatterns.every(pattern => !hsluModuleName.includes(pattern));

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution even better 👍

},
Comment on lines +132 to +147
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bool variables should always have a positive name, e.g. isTrue rather than isNotTrue. Otherwise the valid state is represented as a double negation as in this case with dontIgnore = false meaning the module is invalid. This is simply very confusing.

Besides that, the method name doesn't correspond to what is actually returned. With a name like shouldModuleBeIgnored, I'd expect the method to return true if it is ignored and otherwise false. But it does exactly the opposite.

I'd suggest to change the method like so to make it more easy to understand:

Suggested change
/**
* list of modules that should be ignored to calculate the first semester
* check if moduleName matches ignore pattern
*/
shouldModuleBeIgnored: (hsluModuleName) => {
const ignoreModulePatterns = ['INFO_ABEND'];
let dontIgnore = true;
ignoreModulePatterns.forEach(ignorePattern => {
if(hsluModuleName.includes(ignorePattern)) {
console.log(`ignoring module ${hsluModuleName} for first semester calculation`)
dontIgnore = false;
}
})
return dontIgnore;
},
/**
* Check if a module should be included in the first semester calculation.
*/
isModuleValid: (hsluModuleName) => {
const ignoreModulePatterns = ['INFO_ABEND'];
let isValid = true;
ignoreModulePatterns.forEach(ignorePattern => {
if (moduleName.includes(ignorePattern)) {
console.log(`ignoring module ${hsluModuleName} for first semester calculation`)
isValid = false;
}
})
return isValid;
},

/**
* Generates an array of module objects using the API and the module type mapping json file.
*/
Expand Down Expand Up @@ -157,6 +173,8 @@ const ModuleParser = {
firstModule = anlasslistApiResponse.items
.slice()
.reverse()
//check if module is is in the ignore list
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to add a comment if the method name and docs already explain what's going on :)

.filter(modul => ModuleParser.shouldModuleBeIgnored(modul.anlassnumber))
.find(modul => ModuleParser.isAutumnSemester(modul.anlassnumber) != undefined);

const passedMessage = await i18n.getMessage("Bestanden");
Expand Down Expand Up @@ -202,7 +220,7 @@ const ModuleParser = {
// sets the UseInStats to true by default
parsedModule.UseInStats = true;
if (ignoreInStatsModules != undefined && ignoreInStatsModules[parsedModule.name]) {
parsedModule.UseInStats = false;
parsedModule.UseInStats = false;
}
myCampusModulesList[parsedModule.name] = {
acronym: parsedModule.name,
Expand Down