MCPcopy Create free account
hub / github.com/OpenSIST/OpenSIST.github.io / getPrograms

Function getPrograms

src/Data/ProgramData.js:13–103  ·  view source on GitHub ↗
(isRefresh = false, query = {}, ranking = "cs_rank", {priority = FOREGROUND_PRIORITY} = {})

Source from the content-addressed store, hash-verified

11export async function getPrograms(isRefresh = false, query = {}, ranking = "cs_rank", {priority = FOREGROUND_PRIORITY} = {}) {
12 /*
13 * Get the list of programs (without description) from the server or local storage
14 * @param isRefresh [Boolean]: whether to refresh the data
15 * @param query [Object]: {
16 * 'u': [String]: university name,
17 * (NO PROGRAM) [Delete] 'p': [String]: program name [Delete],
18 * 'd': [String]: degree,
19 * 'm': [String]: major,
20 * 'r': [String]: region,
21 * }
22 * @return: list of programs (without description)
23 */
24 const filters = {
25 ...query,
26 r: normalizeQueryValues(query.r),
27 d: normalizeQueryValues(query.d),
28 m: normalizeQueryValues(query.m),
29 };
30 let programs = await loadCachedValue({
31 key: "programs",
32 legacyFields: ["data"],
33 forceRefresh: isRefresh,
34 priority,
35 load: async () => {
36 const response = await apiJson(PROGRAM_LIST, {
37 fetchPriority: priority,
38 });
39 return response.data;
40 },
41 });
42 if (!programs) {
43 return {};
44 }
45 const univAbbrOrder = univListOrder.reduce((acc, univ) => {
46 acc[univ.abbr] = univ[ranking || 'cs_rank'];
47 return acc;
48 }, {});
49 programs = Object.entries(programs).sort(([univ1], [univ2]) => {
50 return univAbbrOrder[univ1] - univAbbrOrder[univ2];
51 }).reduce((acc, [univ, programs]) => {
52 acc[univ] = programs;
53 return acc;
54 }, {});
55
56 const searchTerm = filters.u?.trim().toLowerCase() ?? '';
57 const matchesUniversity = (univ) => (
58 searchTerm === '' ||
59 univ.abbr.toLowerCase().includes(searchTerm) ||
60 univ.fullName.toLowerCase().includes(searchTerm)
61 );
62 const matchesRegion = (univ) => (
63 !filters.r || filters.r.some(region => univ.region.includes(region))
64 );
65 const emptyUniversityMatches = new Set();
66 const searchPrograms = Object.keys(programs).reduce((matchingPrograms, univName) => {
67 const fullNameResults = (univAbbrFullNameMapping[univName] ?? '').toLowerCase().includes(searchTerm);
68 const abbrResults = univName.toLowerCase().includes(searchTerm);
69 const programResults = programs[univName].filter((programInfo) => {
70 return programInfo.Program.toLowerCase().includes(searchTerm);

Callers 9

StatsBlockFunction · 0.90
getAllRecordsFunction · 0.90
loaderFunction · 0.90
actionFunction · 0.90
loaderFunction · 0.90
loaderFunction · 0.90
prefetchCoreCacheFunction · 0.90
getProgramFunction · 0.85
setProgramFunction · 0.85

Calls 5

loadCachedValueFunction · 0.90
apiJsonFunction · 0.90
normalizeQueryValuesFunction · 0.85
matchesUniversityFunction · 0.85
matchesRegionFunction · 0.85

Tested by

no test coverage detected