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

Add support for MPE attributes #3241

Merged
merged 3 commits into from
Feb 23, 2021
Merged

Add support for MPE attributes #3241

merged 3 commits into from
Feb 23, 2021

Conversation

taneliang
Copy link
Member

Context

#3035

Following this email sent from NUSIT to @chuabingquan:

image

This PR adds support for the MPE course attribute to /scraper and /website.

cc @alissayarmantho

Implementation

Though the MPE attribute has multiple possible values, I've flattened them into multiple separate boolean attributes in our API. Definitely not an ideal solution, but I think our Elasticsearch index expects the attributes to be a list of strings.

Other Information

Not tested because it seems like no module in the NUS API has the MPE course attribute yet, so the new code isn't executed. @chuabingquan @alissayarmantho do yall know when NUS plans to add these attributes?

@taneliang taneliang added the api API servers and scrapers label Feb 16, 2021
@vercel
Copy link

vercel bot commented Feb 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

nusmods-website – ./website

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-website/9L2Yw3vfeZZ59W95MBMqxoGYPAKn
✅ Preview: https://nusmods-website-git-eliang-mpe-attributes-nusmodifications.vercel.app

nusmods-export – ./export

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-export/Gh9BShhSDTGBFatQiWRLn6K6wZ8g
✅ Preview: https://nusmods-export-git-eliang-mpe-attributes-nusmodifications.vercel.app

@codecov
Copy link

codecov bot commented Feb 16, 2021

Codecov Report

Merging #3241 (e599950) into master (7467991) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3241      +/-   ##
==========================================
+ Coverage   55.35%   55.37%   +0.01%     
==========================================
  Files         255      255              
  Lines        5320     5320              
  Branches     1228     1228              
==========================================
+ Hits         2945     2946       +1     
+ Misses       2375     2374       -1     
Impacted Files Coverage Δ
website/src/types/modules.ts 100.00% <ø> (ø)
website/src/views/timetable/Timetable.tsx 96.77% <0.00%> (+3.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7467991...e599950. Read the comment docs.

@nusmods-deploy-bot
Copy link

nusmods-deploy-bot bot commented Feb 16, 2021

@@ -54,6 +54,7 @@ const attributeMap: { [attribute: string]: keyof NUSModuleAttributes } = {
LABB: 'lab',
ISM: 'ism',
HFYP: 'fyp',
// MPE handled separately as it maps to multiple attributes
Copy link
Member

Choose a reason for hiding this comment

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

We could add a MPE map to make this a bit more declarative, what do you think?

const mpeValueMap: { [attribute: string]: (keyof NUSModuleAttributes)[] } = {
  S1: ['mpes1'],
  S2: ['mpes2'],
  'S1&S2': ['mpes1', 'mpes2'],
};

// ... 

if (entry.CourseAttribute === 'MPE') {
  const mappedAttributes = mpeValueMap[entry.CourseAttributeValue];
  if (!mappedAttributes) {
    logger.warn(
      { value: entry.CourseAttributeValue, key: entry.CourseAttribute },
      'Non-standard course attribute value',
    );
  } else {
    for (const attr of mappedAttributes) {
      nusAttributes[attr] = true;
    }
  }
  continue;
}

Copy link
Member Author

@taneliang taneliang Feb 23, 2021

Choose a reason for hiding this comment

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

Beautiful 😍

@chuabingquan
Copy link
Contributor

chuabingquan commented Feb 19, 2021

@taneliang NUS have updated their modules with the new attributes. We can now test this PR with the following values:

Available for Sem 1

  • AH3204
  • AH3205
  • BAA6002
  • BBP6781
  • BDC6112
  • CS6285
  • DBA4761

Available for Sem 2

  • AS2237
  • BDC6305
  • BDC6307
  • CS6240
  • DBA3712

Available for Sem 1 & 2

  • AH2101
  • BMA5011
  • BMA5104
  • EBA5006
  • EC1101E
  • EC1301

@taneliang
Copy link
Member Author

Tested locally, seems to work.

image

@taneliang
Copy link
Member Author

Merging without approval due to deadlines

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

Successfully merging this pull request may close these issues.

3 participants