icssc / peterportal-api-next

API that provides easy access to public data from UC Irvine. Developed for Anteaters, by Anteaters.
https://docs.icssc.club/anteaterapi
MIT License
6 stars 0 forks source link

refactor: simplify the websoc combine process #20

Closed ap0nia closed 1 year ago

ap0nia commented 1 year ago

Summary

Attempt to reduce the complexity of the combining function. Proposal / demo of how it could look instead. Needs testing and verification because I've never actually seen or interacted with the WebsocResponse[]

Strategy

  1. Use map and flat to generate a flattened array of enhanced sections: sections that have contextual metadata about the school, department, and course they're in
  2. Use reduce to create an array of schools by iterating through enhanced sections and handling each appropriately.
    • Attempt to find some "part" of the section in the accumulated array of schools
    • If it doesn't exist, then add that "part" of the section to the corresponding property of the accumulated schools
    • Otherwise, index into the found "part" and repeat

Notes

Why

github-actions[bot] commented 1 year ago

Deployed staging instance to https://staging-20.api-next.peterportal.org

ap0nia commented 1 year ago

Ok, it seems to generate the same response as the production website.

image