-
Notifications
You must be signed in to change notification settings - Fork 11
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
Calculating and Storing Requirement Statistics #866
Open
PabloRaigoza
wants to merge
10
commits into
main
Choose a base branch
from
pablo/fulfillment-stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ca6a39d
Adding new file in scripts and debugging credentials
PabloRaigoza f11b11e
Implementing the script to determine course frequencies to fulfill given
PabloRaigoza 06a026f
Fixing formatting and linting errors
PabloRaigoza d06218c
Implmenting gen-req-full-stats
PabloRaigoza 6aab6fe
Ran format
PabloRaigoza ccbfee3
Adding documention and removing console.log
PabloRaigoza 7b5ba5c
Ran format
PabloRaigoza 4f326fd
Merge branch 'main' of github.com:cornell-dti/course-plan into pablo/…
PabloRaigoza a8a5630
Cleaning code and replacing backslash with doc id
PabloRaigoza 95acbc1
Resolving all promises before callback
PabloRaigoza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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,109 @@ | ||
import { | ||
onboardingDataCollection, | ||
semestersCollection, | ||
toggleableRequirementChoicesCollection, | ||
overriddenFulfillmentChoicesCollection, | ||
courseFulfillmentStats, | ||
} from './firebase-config'; | ||
|
||
import computeGroupedRequirementFulfillmentReports from '../src/requirements/requirement-frontend-computation'; | ||
import computeFulfillmentStats from '../src/requirements/fulfillment-stats'; | ||
import { createAppOnboardingData } from '../src/user-data-converter'; | ||
|
||
import '../src/requirements/decorated-requirements.json'; | ||
|
||
let idRequirementFrequency = new Map<string, Map<number, number>[]>(); | ||
let counter = 0; | ||
/** | ||
* Prints to console.out the json string of frequencies each course take to | ||
* fulfill a given requirement | ||
*/ | ||
async function computeRequirementFullfillmentStatistics(_callback) { | ||
const semQuerySnapshot = await semestersCollection.get(); | ||
semQuerySnapshot.forEach(async doc => { | ||
// obtain the user's semesters, onboarding data, etc... | ||
const semestersAndPlans = await doc.data(); | ||
const onboardingData = (await onboardingDataCollection.doc(doc.id).get()).data(); | ||
const toggleableRequirementChoices = | ||
(await toggleableRequirementChoicesCollection.doc(doc.id).get()).data() ?? {}; | ||
const overriddenFulfillmentChoices = | ||
(await overriddenFulfillmentChoicesCollection.doc(doc.id).get()).data() ?? {}; | ||
|
||
if ( | ||
onboardingData !== undefined && | ||
semestersAndPlans.semesters !== undefined && | ||
toggleableRequirementChoices !== undefined && | ||
overriddenFulfillmentChoices !== undefined | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
// if the user has onboarding data | ||
try { | ||
const newOnboardingData = await createAppOnboardingData(onboardingData); // convert to new format | ||
const res = await computeGroupedRequirementFulfillmentReports( | ||
// compute fulfillment stats | ||
semestersAndPlans.semesters, | ||
newOnboardingData, | ||
toggleableRequirementChoices, | ||
overriddenFulfillmentChoices | ||
); | ||
idRequirementFrequency = await computeFulfillmentStats( | ||
res.groupedRequirementFulfillmentReport, | ||
idRequirementFrequency | ||
); // compute fulfillment stats | ||
} catch { | ||
console.log(counter, ' : Error in computing fulfillment stats for user: ', doc.id); | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
counter += 1; | ||
} | ||
} | ||
}); | ||
|
||
setTimeout(_callback, 3600 * 1000); // wait for all the data to be processed | ||
} | ||
|
||
/** | ||
* Stores the computed requirement fulfillment statistics in firestore | ||
*/ | ||
async function storeComputedRequirementFullfillmentStatistics() { | ||
console.log('Keeping only the top fifty courses for each slot'); | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// iterate through all the keys in the idRequirementFrequency hashmap | ||
for (const [reqID, slots] of idRequirementFrequency) { | ||
const newSlots: Map<number, number>[] = []; | ||
for (const slot of slots) { | ||
const newSlot = new Map<number, number>(); | ||
const sorted = [...slot.entries()].sort((a, b) => b[1] - a[1]); | ||
let count = 0; | ||
for (const [course, freq] of sorted) { | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (count === 50) { | ||
break; | ||
} | ||
newSlot.set(course, freq); | ||
count += 1; | ||
} | ||
newSlots.push(newSlot); | ||
} | ||
idRequirementFrequency.set(reqID, newSlots); | ||
} | ||
|
||
console.log('Storing fulfillment stats in firestore'); | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// iterate through all the keys in the idRequirementFrequency hashmap | ||
for (const [reqID, slots] of idRequirementFrequency) { | ||
const json = {}; | ||
|
||
let i = 0; | ||
for (const slot of slots) { | ||
const tempJson = {}; | ||
for (const [course, freq] of slot) { | ||
tempJson[course] = freq; | ||
} | ||
json[i] = tempJson; | ||
i += 1; | ||
} | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const data = { | ||
reqID, | ||
slots: json, | ||
}; | ||
courseFulfillmentStats.doc().set(data); | ||
} | ||
} | ||
|
||
computeRequirementFullfillmentStatistics(storeComputedRequirementFullfillmentStatistics); |
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,37 @@ | ||
export default function computeFulfillmentStats( | ||
groups: readonly GroupedRequirementFulfillmentReport[], | ||
idRequirementFrequency: Map<string, Map<number, number>[]> | ||
) { | ||
const res = idRequirementFrequency; | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
groups.forEach(currentGroup => { | ||
const { reqs } = currentGroup; | ||
reqs.forEach(reqFulfillment => { | ||
const key: string = reqFulfillment.requirement.id; | ||
const { safeCourses } = reqFulfillment.fulfillment; | ||
|
||
// Obtain the frequency list for this particular group's requirements | ||
const freqList = res.get(key) ?? []; | ||
|
||
// Iterate over all slots in the requirement group | ||
// console.log(safeCourses.length); | ||
for (let slotNumber = 0; slotNumber < safeCourses.length; slotNumber += 1) { | ||
if (freqList.length === slotNumber) { | ||
freqList.push(new Map<number, number>()); | ||
PabloRaigoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
const currentCourseSlot = safeCourses[slotNumber]; | ||
const currentRequirementSlotFreq = freqList[slotNumber]; | ||
|
||
// Iterate over all courses taken to fulfill the req-slot | ||
for (let j = 0; j < currentCourseSlot.length; j += 1) { | ||
const currentCourseId = currentCourseSlot[j].courseId; | ||
const pastFreq = currentRequirementSlotFreq.get(currentCourseId) ?? 0; | ||
currentRequirementSlotFreq.set(currentCourseId, pastFreq + 1); | ||
} | ||
Comment on lines
+42
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you convert this into a for each loop? |
||
freqList[slotNumber] = currentRequirementSlotFreq; // Update the frequency list | ||
} | ||
res.set(key, freqList); // Update the hashmap with the new frequency list | ||
}); | ||
}); | ||
|
||
return res; // return the hashmap | ||
} |
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.
Why do we need this
_callback
argument?