-
Notifications
You must be signed in to change notification settings - Fork 4
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
Beta Majors! #739
Merged
Merged
Beta Majors! #739
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ccdc350
wip commit
AlpacaFur 39caf75
Remove empty sections
AlpacaFur 969a3ec
Remove fuzzy search use
BrandonLim8890 55c3d92
Remove empty sections for real
AlpacaFur 2596a87
Merge branch 'luke/majors-wip' of github.com:sandboxnu/graduatenu int…
AlpacaFur 587c239
Add existing majors back into new structure
AlpacaFur 485377a
minor code cleanup
AlpacaFur bdcbdf1
Remove old majors
AlpacaFur ad65ebc
major -> majors
AlpacaFur 0857a51
Update .gitignore
AlpacaFur 634d0b1
Add some comments to the major collator
AlpacaFur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
raw.*.html | ||
tokens.*.json |
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { Major2 } from "@graduate/common"; | ||
|
||
const MAJORS: Record<string, Record<string, Major2>> = {}; | ||
const MAJOR_YEARS = new Set<string>(); | ||
|
||
const rootDir = "./src/major/majors"; | ||
|
||
interface YearData { | ||
year: string; | ||
} | ||
|
||
interface YearCollegeData { | ||
year: string; | ||
college: string; | ||
} | ||
|
||
interface YearCollegeMajorData { | ||
year: string; | ||
college: string; | ||
major: string; | ||
} | ||
|
||
async function fileExists( | ||
fs: typeof import("fs/promises"), | ||
path: string | ||
): Promise<boolean> { | ||
return await fs.access(path, fs.constants.F_OK).then( | ||
() => true, | ||
() => false | ||
); | ||
} | ||
|
||
// TODO: this code is quick and dirty but works. this should be replaced with some dry-er code later. | ||
/** | ||
* Iterates over the ./majors directory, collecting majors and adding them to | ||
* the exported MAJORS and MAJOR_YEARS object/set respectively. It prioritizes | ||
* parsed.commit.json files over parsed.initial.json files because _.commit._ | ||
* files have been human-reviewed and _.initial._ files are raw scraper output. | ||
*/ | ||
async function collateMajors() { | ||
// TODO: determine why these needed to be runtime imports (normal import statements didn't work here). | ||
const fs = await import("fs/promises"); | ||
const path = await import("path"); | ||
const years = ( | ||
await fs.readdir(path.resolve(rootDir), { | ||
withFileTypes: true, | ||
}) | ||
) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map( | ||
(dirent): YearData => ({ | ||
year: dirent.name, | ||
}) | ||
); | ||
|
||
const colleges = ( | ||
await Promise.all( | ||
years.map(async ({ year }) => { | ||
const colleges = await fs.readdir(path.join(rootDir, year), { | ||
withFileTypes: true, | ||
}); | ||
return colleges | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map( | ||
(college): YearCollegeData => ({ | ||
year: year, | ||
college: college.name, | ||
}) | ||
); | ||
}) | ||
) | ||
).flat(); | ||
|
||
const majors = ( | ||
await Promise.all( | ||
colleges.map(async ({ year, college }) => { | ||
const majors = await fs.readdir(path.join(rootDir, year, college), { | ||
withFileTypes: true, | ||
}); | ||
return majors | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map( | ||
(major): YearCollegeMajorData => ({ | ||
year: year, | ||
college: college, | ||
major: major.name, | ||
}) | ||
); | ||
}) | ||
) | ||
).flat(); | ||
|
||
years.forEach(({ year }) => { | ||
MAJOR_YEARS.add(year); | ||
MAJORS[year] = {}; | ||
}); | ||
|
||
const done = await Promise.all( | ||
majors.map(async ({ year, college, major }) => { | ||
const basePath = path.join(rootDir, year, college, major); | ||
const commitFile = path.join(basePath, "parsed.commit.json"); | ||
const initialFile = path.join(basePath, "parsed.initial.json"); | ||
|
||
if (await fileExists(fs, commitFile)) { | ||
const fileData = JSON.parse( | ||
(await fs.readFile(commitFile)).toString() | ||
) as Major2; | ||
MAJORS[year][fileData.name] = fileData; | ||
} else if (await fileExists(fs, initialFile)) { | ||
const fileData = JSON.parse( | ||
(await fs.readFile(initialFile)).toString() | ||
) as Major2; | ||
if (MAJORS[year]) MAJORS[year][fileData.name] = fileData; | ||
} | ||
}) | ||
); | ||
|
||
console.log( | ||
`Successfully loaded ${done.length} majors across ${MAJOR_YEARS.size} years!` | ||
); | ||
} | ||
|
||
collateMajors(); | ||
|
||
export { MAJORS, MAJOR_YEARS }; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
My brain is slow but from what it looks like, we run through each year, each college and add all the majors. initial.json is our initial scrape and commit.json is the hand validated stuff?
If this is the case I can update this with comments/put it in our notion somewhere for knowledge transfer.
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.
Good call! Added some comments to the function.