-
Notifications
You must be signed in to change notification settings - Fork 80
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
base: main
Are you sure you want to change the base?
Conversation
…d imports Grouped them into a new folder in src/lib/locations
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.
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 |
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.
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 () => { |
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.
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
`;
apps/antalmanac/package.json
Outdated
@@ -39,6 +39,7 @@ | |||
"@tanstack/react-query": "^4.24.4", | |||
"@trpc/client": "^10.30.0", | |||
"@trpc/server": "^10.30.0", | |||
"axios": "^1.7.9", |
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.
"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'; |
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.
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); |
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.
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.
I'm trolling, didn't see the re-request, will review asap 🫡 |
In the meantime, would you mind resolving the merge conflict (should be very quick) |
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.
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) { |
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.
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
...
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.
Lockfile looks funny ⬇️
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.
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
Summary
catalogue_builder.js
intocatalogueBuilder.ts
locations.ts
alongsidebuildingCatalogue.ts
locations.ts
andbuildingCatalogue.ts
with its recently updated versioncatalogueBuilder.ts, buildingCatalogue.ts, locations.ts
intoapps/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, andJSON.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
locations.test.ts
and make sure all tests pass (all tests passed when I ran it on my end)Issues
Closes #1085