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

fix: Reformat catalogue builder (+ add ISEB) #1119

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

xgraceyan
Copy link
Contributor

Summary

  • Reformatted catalogue_builder.js into catalogueBuilder.ts
  • catalogueBuilder builds locations.ts alongside buildingCatalogue.ts
  • Replaced locations.ts and buildingCatalogue.ts with its recently updated version
  • Moved catalogueBuilder.ts, buildingCatalogue.ts, locations.ts into apps/antalmanac/src/lib/locations

Important note/potential issue

Currently, the data in buildingCatalogue.ts has its building ID keys as strings instead of numbers. This is because json requires all keys be strings, and JSON.stringify is used in order to write the scraped data to buildingCatalogue.

I can't find a workaround that writes to the file without using JSON.stringify as of right now, so I've just left the IDs as strings for now. To my knowledge, you can still use numbers to index the data, and locations are still able to be fetched properly from other scripts. However, this is still pretty important to note down, and might need another solution soon.

Test Plan

  • Run locations.test.ts and make sure all tests pass (all tests passed when I ran it on my end)
  • Ensure locations are able to be looked up on the map
  • Ensure location name, image, directions, and info are displayed when searched on map
  • Ensure any "missing" locations are present -- ie, ISEB and any others
  • Ensure locations are able to be fetched when clicked from a class lookup
  • Ensure locations are able to be saved properly when adding a custom event
  • Ensure location abbreviations are displayed on the calendar (and wherever applicable)

Issues

Closes #1085

Copy link
Member

@KevinWu098 KevinWu098 left a comment

Choose a reason for hiding this comment

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

Great improvement to our system! Just some minor suggestions, but overall very thoroughly put together!

const fs = require('fs');
import fs from 'fs';

import axios from 'axios';
// https://map.uci.edu/?id=463#!s/?ct/8424,8309,8311,8392,8405,44392,44393,44394,44395,44396,44397,44398,44400,44401,44402,44538,44537,44399,8396,11907,8400,10486,11906,11889,8310,8312,8393,8394,8397,8398,8399,8404,8407,8408,11891,11892,11899,11900,11902,21318,8406,11908,11935
Copy link
Member

Choose a reason for hiding this comment

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

chore: maybe colocate this with our CATEGORIES const to explain better where we source our category ids from. adding a brief comment to further illustrate this would be good too

: location.name;
locationIds[locationName] = location.id;

await sleep(250);
}
}
}

(async () => {
Copy link
Member

Choose a reason for hiding this comment

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

issue: looks like this code works, but it's a tad hard on the eyes to read.

suggestion: rewrite this function as a main() and call that at the bottom of the file. Further, break up the string literals into separate variables

const foo = `
    export interface Building {
    imageURLs: string[];
    lat: number;
    lng: number;
    name: string;
    }\n\n
`;

@@ -39,6 +39,7 @@
"@tanstack/react-query": "^4.24.4",
"@trpc/client": "^10.30.0",
"@trpc/server": "^10.30.0",
"axios": "^1.7.9",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"axios": "^1.7.9",

issue: would be nice to not add an additional dependency; we can do this with just fetch

const fs = require('fs');
import fs from 'fs';

import axios from 'axios';
Copy link
Member

Choose a reason for hiding this comment

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

repeat: lets not use a new dependency; fetch is fine here

return new Promise((resolve) => setTimeout(resolve, ms));
}

async function fetchLocations() {
// Hits locations API to get a list of every single location
let locations = await axios.get(LOCATIONS_LIST_API);
let locations: any = await axios.get<BuildingLocation>(LOCATIONS_LIST_API);
Copy link
Member

Choose a reason for hiding this comment

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

issue: using any explicitly and naming both the response and the resulting data the same variable can create a surface for potential errors

suggestion: aside from switching out Axios for Fetch, I'd recommend naming the variables more clearly and not using any. When you must make an assertion (which you'll have to), I'd recommend asserting the type of the decoded data.

Would also be good to write some validator for the data, but I think we can skip on that for now.

@xgraceyan xgraceyan requested a review from KevinWu098 January 20, 2025 00:32
@KevinWu098
Copy link
Member

I'm trolling, didn't see the re-request, will review asap 🫡

@KevinWu098
Copy link
Member

In the meantime, would you mind resolving the merge conflict (should be very quick)

Copy link
Member

@KevinWu098 KevinWu098 left a comment

Choose a reason for hiding this comment

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

Very good work! LGTM 🚀

I think that, like a few of our other "generated" data lists (e.g. term data, fuzzy search), locations would also be a good one to generate at build time!

);

// If one of the locations belongs to one of the categories above, and is not a duplicate
if (CATEGORIES.has(location.catId) && !locationExists) {
Copy link
Member

Choose a reason for hiding this comment

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

nit (non-blocking): An (arguably) better way to write this function would be with a few early returns/guard clauses

if (!CATEGORIES.has()) {
    return;
}

if (!locationExists) {
    return;
}

// do logic after guard clauses
...

Copy link
Member

@KevinWu098 KevinWu098 left a comment

Choose a reason for hiding this comment

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

Lockfile looks funny ⬇️

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... this lockfile looks wrong, actually...

Why are we removing so many dependencies? Can you rerun pnpm install at the root and commit the resulting file? If it's the same, just lmk

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.

fix: ISEB is not included in buildingCatalogue.ts
2 participants