-
Notifications
You must be signed in to change notification settings - Fork 17
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
firstModule detection fix #101
Open
rogerKaelin
wants to merge
1
commit into
eddex:master
Choose a base branch
from
rogerKaelin:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,8 @@ | ||||||
/** | ||||||
* Update the base module type list for other studies than information science. | ||||||
* | ||||||
* Sometimes the same module can have a different module type depending on the study (I, WI, ICS, DI etc). | ||||||
*/ | ||||||
* Update the base module type list for other studies than information science. | ||||||
* | ||||||
* Sometimes the same module can have a different module type depending on the study (I, WI, ICS, DI etc). | ||||||
*/ | ||||||
const updateModuleTypeList = async (oldModuleTypeList, jsonFilePath) => { | ||||||
let patch = await fetch(Helpers.getExtensionInternalFileUrl(jsonFilePath)) | ||||||
.then(response => response.json()); | ||||||
|
@@ -11,22 +11,36 @@ const updateModuleTypeList = async (oldModuleTypeList, jsonFilePath) => { | |||||
|
||||||
const ModuleParser = { | ||||||
|
||||||
/** | ||||||
* 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) | ||||||
* 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; | ||||||
return hsluModuleName.split('.')[2].includes('H') && ModuleParser.isNotInfoSemester(hsluModuleName); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
|
||||||
/** | ||||||
* 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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
|
||||||
/** | ||||||
* Calculate the semester. | ||||||
* | ||||||
* @param {string} hsluModuleName: is the 'anlassnumber', | ||||||
* e.g. 'I.BA_BCHAIN.H1901'. | ||||||
* @param firstModule | ||||||
*/ | ||||||
calculateSemester: (hsluModuleName, firstModule) => { | ||||||
let semester = undefined; | ||||||
|
@@ -55,34 +69,32 @@ const ModuleParser = { | |||||
if (isStartInAutumn) { | ||||||
if (isModuleInAutumn) { | ||||||
semester = yearDifference * 2 + 1; | ||||||
} | ||||||
else { | ||||||
} else { | ||||||
semester = yearDifference * 2; | ||||||
} | ||||||
} else { | ||||||
if (isModuleInAutumn) { | ||||||
semester = yearDifference * 2 + 2; | ||||||
} | ||||||
else { | ||||||
} else { | ||||||
semester = yearDifference * 2 + 1; | ||||||
} | ||||||
} | ||||||
return semester; | ||||||
}, | ||||||
|
||||||
/** | ||||||
* The module name includes the module id. | ||||||
* But there are different formats for the module names. | ||||||
* | ||||||
* Modules that are parsed: | ||||||
* Usually a module name looks like this: I.BA_IPCV.F1901 | ||||||
* There are modules that have a suffix after a second underscore: I.BA_AISO_E.F1901 | ||||||
* | ||||||
* Modules that are not parsed: | ||||||
* There are modules without underscores in the name: I.ANRECHINDIVID.F1901 | ||||||
* Only the ANRECHINDIVID module is known to have this format. | ||||||
* Probably counted as 'Erweiterungsmodul'. | ||||||
*/ | ||||||
* The module name includes the module id. | ||||||
* But there are different formats for the module names. | ||||||
* | ||||||
* Modules that are parsed: | ||||||
* Usually a module name looks like this: I.BA_IPCV.F1901 | ||||||
* There are modules that have a suffix after a second underscore: I.BA_AISO_E.F1901 | ||||||
* | ||||||
* Modules that are not parsed: | ||||||
* There are modules without underscores in the name: I.ANRECHINDIVID.F1901 | ||||||
* Only the ANRECHINDIVID module is known to have this format. | ||||||
* Probably counted as 'Erweiterungsmodul'. | ||||||
*/ | ||||||
getModuleIdFromModuleName: (moduleName) => { | ||||||
|
||||||
let name = String(moduleName); | ||||||
|
@@ -97,13 +109,11 @@ const ModuleParser = { | |||||
name = name.split('.')[0]; | ||||||
} | ||||||
return name; | ||||||
} | ||||||
else if (name.includes('.')) { | ||||||
} else if (name.includes('.')) { | ||||||
|
||||||
// for module names like I.ANRECHINDIVID.F1901 | ||||||
return name.split('.')[1]; | ||||||
} | ||||||
else { | ||||||
} else { | ||||||
console.log('module id not parseable: ' + moduleName); | ||||||
return null; | ||||||
} | ||||||
|
@@ -124,14 +134,12 @@ const ModuleParser = { | |||||
* Only if all of them are matching in the right order test() returns true | ||||||
* */ | ||||||
const moduleNameRegex = /^(\w+)\.(.+)\.[FH]\d{4}/g; | ||||||
if (moduleNameRegex.test(moduleName)) { | ||||||
return true | ||||||
} | ||||||
return false | ||||||
return moduleNameRegex.test(moduleName); | ||||||
|
||||||
}, | ||||||
/** | ||||||
* Generates an array of module objects using the API and the module type mapping json file. | ||||||
*/ | ||||||
* Generates an array of module objects using the API and the module type mapping json file. | ||||||
*/ | ||||||
generateModuleObjects: async (studyAcronym) => { | ||||||
|
||||||
const API_URL = "https://mycampus.hslu.ch/de-ch/api/anlasslist/load/?page=1&per_page=69&total_entries=69&datasourceid=5158ceaf-061f-49aa-b270-fc309c1a5f69"; | ||||||
|
@@ -154,10 +162,21 @@ const ModuleParser = { | |||||
return; | ||||||
} | ||||||
|
||||||
firstModule = anlasslistApiResponse.items | ||||||
let firstSpringModule = anlasslistApiResponse.items | ||||||
.slice() | ||||||
.reverse() | ||||||
.find(modul => ModuleParser.isAutumnSemester(modul.anlassnumber) != undefined); | ||||||
.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 | ||||||
} | ||||||
|
||||||
const passedMessage = await i18n.getMessage("Bestanden"); | ||||||
const ignoreInStatsModules = (await Helpers.getItemFromLocalStorage("ignoreInStatsModules")).ignoreInStatsModules; | ||||||
|
@@ -167,22 +186,19 @@ const ModuleParser = { | |||||
let parsedModule = {}; | ||||||
if (ModuleParser.validateModuleName(item.anlassnumber)) { | ||||||
parsedModule.semester = ModuleParser.calculateSemester(item.anlassnumber, firstModule); | ||||||
} | ||||||
else { | ||||||
} else { | ||||||
console.log("Not valid modulename: ", item.anlassnumber); | ||||||
parsedModule.semester = undefined | ||||||
} | ||||||
|
||||||
let passed = item.prop1[0].text == 'Erfolgreich teilgenommen'; | ||||||
let passed = item.prop1[0].text === 'Erfolgreich teilgenommen'; | ||||||
parsedModule.passed = passed; | ||||||
|
||||||
if (item.note != null) { | ||||||
parsedModule.mark = item.note; | ||||||
} | ||||||
else if (passed) { | ||||||
} else if (passed) { | ||||||
parsedModule.mark = passedMessage; | ||||||
} | ||||||
else { | ||||||
} else { | ||||||
parsedModule.mark = 'n/a'; | ||||||
} | ||||||
parsedModule.grade = item.grade === null ? 'n/a' : item.grade; | ||||||
|
@@ -200,18 +216,16 @@ const ModuleParser = { | |||||
} | ||||||
|
||||||
// sets the UseInStats to true by default | ||||||
parsedModule.UseInStats = true; | ||||||
if (ignoreInStatsModules != undefined && ignoreInStatsModules[parsedModule.name]) { | ||||||
parsedModule.UseInStats = false; | ||||||
} | ||||||
|
||||||
parsedModule.UseInStats = !(ignoreInStatsModules !== undefined && ignoreInStatsModules[parsedModule.name]); | ||||||
myCampusModulesList[parsedModule.name] = { | ||||||
acronym: parsedModule.name, | ||||||
} | ||||||
|
||||||
modules.push(parsedModule); | ||||||
}); | ||||||
// Save modules from MyCampus to local storage for the popup | ||||||
await Helpers.saveObjectInLocalStorage({ hsluModules: myCampusModulesList }) | ||||||
await Helpers.saveObjectInLocalStorage({hsluModules: myCampusModulesList}) | ||||||
|
||||||
//add custom modules from local storage | ||||||
let moduleList = (await Helpers.getItemFromLocalStorage("moduleList")).moduleList | ||||||
|
@@ -220,7 +234,7 @@ const ModuleParser = { | |||||
const customModule = moduleList[customModuleName]; | ||||||
|
||||||
let parsedModule = {}; | ||||||
parsedModule.passed = customModule.grade == 'F' ? false : true; | ||||||
parsedModule.passed = customModule.grade !== 'F'; | ||||||
parsedModule.mark = customModule.mark; | ||||||
parsedModule.grade = customModule.grade; | ||||||
parsedModule.type = customModule.type; | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a method returns a
bool
, always think of what it should check, not what it shouldn't. This makes the code more readable.