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

Conversation

Leo1212
Copy link

@Leo1212 Leo1212 commented Feb 15, 2022

I added a new static list of module name patterns that should be ignored on the first semester calculation.
These are only ignored on the firstModule calculation.
This solves the issue #95.

If you want another solution I'm open to it.
Maybe we should also ignore modules that are in ignoreInStatsModules.

@MSiegrist
Copy link

Tried out the changes and works for me in chrome 👍

Copy link
Owner

@eddex eddex left a comment

Choose a reason for hiding this comment

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

Hi and thanks for your contribution!

We can't test this ourselves since both me and @Lextum no longer have access to the MyCampus website, therefore we hope you have tested this well 😉

Comment on lines +132 to +147
/**
* 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;
},
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;
},

@@ -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 :)

Comment on lines +138 to +146
let dontIgnore = true;
ignoreModulePatterns.forEach(ignorePattern => {
if(hsluModuleName.includes(ignorePattern)) {
console.log(`ignoring module ${hsluModuleName} for first semester calculation`)
dontIgnore = false;
}
})

return dontIgnore;

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants