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

Sort by semester #537

Merged
merged 54 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
fe11182
Added orderByNewest field to user-semesters
zachary-kent Oct 4, 2021
363ddd9
Prevented scope of breaking changes by un-nesting.
zachary-kent Oct 5, 2021
1cad246
Updated firestore schema
zachary-kent Oct 5, 2021
4792347
Added assets
zachary-kent Oct 5, 2021
b4aa5b5
Updated Vuex store to persist
zachary-kent Oct 5, 2021
848bde4
Added check to ensure orderByNewest is not
zachary-kent Oct 5, 2021
2a932fc
Basic dropdown functionality
zachary-kent Oct 5, 2021
3fdf686
Completed Dropdown Functionality
zachary-kent Oct 6, 2021
d929421
Made backend operations more
zachary-kent Oct 6, 2021
b008836
Added horizontal line to dropdown
zachary-kent Oct 6, 2021
4f506cb
Ran prettier
zachary-kent Oct 6, 2021
de3e835
Increased horizontal line spacing
zachary-kent Oct 6, 2021
562962f
Added type safety to event handling
zachary-kent Oct 6, 2021
0200555
Ran prettier
zachary-kent Oct 6, 2021
b48aecb
Removed old assets and .dmg
zachary-kent Oct 6, 2021
ca062b2
Restored old assets, removed .dmg
zachary-kent Oct 6, 2021
ee0d86f
Merge branch 'sort-by-semester' of https://github.com/cornell-dti/cou…
zachary-kent Oct 6, 2021
6c585d5
Restored files
zachary-kent Oct 6, 2021
a43b800
Moved sorting logic to store.ts
zachary-kent Oct 6, 2021
d79bee9
Simplfied SeasonOrdinal export
zachary-kent Oct 6, 2021
c0a484e
Ran prettier
zachary-kent Oct 6, 2021
4297fd9
Uncmoitted package-lock changes
zachary-kent Oct 8, 2021
63a24a6
Removed comparisons using "!=" that result in
zachary-kent Oct 8, 2021
6f88817
Improved readability
zachary-kent Oct 8, 2021
0c320ce
ran prettier
zachary-kent Oct 8, 2021
be73ca1
Removed uneeded event modifiers
zachary-kent Oct 8, 2021
7397288
Made dropdown toggleable
zachary-kent Oct 19, 2021
b85e1d3
Fixed button font issues
zachary-kent Oct 19, 2021
7020936
Removed references to newly created colors
zachary-kent Oct 19, 2021
d1cd8cc
Ran prettier
zachary-kent Oct 19, 2021
44ca16a
Cleaned up image source paths
zachary-kent Oct 19, 2021
afba67b
Removed uneeded css prop
zachary-kent Oct 19, 2021
60d07ea
Switched from em to rem
zachary-kent Oct 19, 2021
937f9b3
Maintained hierarchy
zachary-kent Oct 19, 2021
57ec53b
maintained hierarchy (again)
zachary-kent Oct 19, 2021
01c5a25
Added descriptive alt
zachary-kent Oct 19, 2021
c576f01
Made padding property terse,
zachary-kent Oct 19, 2021
e378b87
Merge branch 'master' into sort-by-semester
zachary-kent Oct 19, 2021
e5d3fe4
Merged master in
zachary-kent Oct 19, 2021
5309c11
Updated backend structure
zachary-kent Oct 19, 2021
8f2a42a
Ran prettier
zachary-kent Oct 19, 2021
8eb1a49
Removed duplicated files
zachary-kent Oct 19, 2021
93f4316
Factored out repreated code
zachary-kent Oct 19, 2021
928d0c8
Update src/store.ts
zachary-kent Oct 20, 2021
aa620b9
Refactored according to Ben's suggestions
zachary-kent Oct 20, 2021
2aaa33a
Fixed persistence
zachary-kent Oct 20, 2021
b757494
Renamed OrderDropdown to ViewDropdown
zachary-kent Oct 20, 2021
e5398dd
Added no-wrap rule to prevent semester
zachary-kent Oct 20, 2021
0856739
Made dropdown close upon outside click
zachary-kent Oct 20, 2021
054ce30
Reverted Semester.vue to master
zachary-kent Oct 20, 2021
23cc2bb
Added compareFirestoreSemesters back
zachary-kent Oct 20, 2021
2b1da10
Merge branch 'master' into sort-by-semester
zachary-kent Oct 22, 2021
d72f7a8
Changed setOrderByNewest to be pure
zachary-kent Oct 22, 2021
9d9c91e
Removed @ prefix (seemed to break frontend test,
zachary-kent Oct 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into sort-by-semester
  • Loading branch information
zachary-kent committed Oct 19, 2021
commit e378b87af306e8ee8bf39ada1ea919d13a9578b7
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/config/
dist/
/*.js
functions/deployment-template/index.js
2 changes: 1 addition & 1 deletion .github/workflows/ci-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
with:
cache: 'npm'
- name: NPM Clean Install
run: npm ci
run: npm ci && cd functions && npm ci
- name: Run Prettier Check
run: npm run format:check
- name: Run Linter
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist
.vscode
.firebase
requirement-generator-dist/
functions/deployment-template/index.js
.eslintcache

# local env files
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ npm run serve

Then access http://localhost:8080/

## Docs

- [Requirements](./src/requirements/README.md)
- [Feature Flags](./src/feature-flags.md)

## Contributors

### SP21
Expand Down
4 changes: 4 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"destination": "/index.html"
}
]
},
"functions": {
"source": "functions/deployment-template",
"runtime": "nodejs14"
}
}
9 changes: 9 additions & 0 deletions functions/deployment-template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "deployment-template",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"deploy": "firebase deploy --only functions"
}
}
107 changes: 0 additions & 107 deletions functions/index.js

This file was deleted.

207 changes: 207 additions & 0 deletions functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import functions from 'firebase-functions';
import admin from 'firebase-admin';

admin.initializeApp();
const db = admin.firestore();
const usernameCollection = db.collection('user-name');
const semestersCollection = db.collection('user-semesters');
const onboardingCollection = db.collection('user-onboarding-data');

const average = (array: readonly number[]) => array.reduce((a, b) => a + b) / array.length;
function typeToMonth(type: string) {
switch (type) {
case 'Spring':
return 1;
case 'Summer':
return 6;
case 'Fall':
return 8;
case 'Winter':
return 12;
default:
throw new Error();
}
}

function isOld(semester: { year: number; type: string }) {
const currentTime = new Date();
const month = currentTime.getMonth() + 1;
const year = currentTime.getFullYear();
if (semester.year > year) {
return false;
}
if (semester.year < year) {
return true;
}
if (typeToMonth(semester.type) <= month) {
return true;
}
return false;
}

// add all colleges/programs/majors etc. in arr to frequency dict
// TODO this will not show any colleges/grad programs with 0 people.
// Need to look at requirements data and add each to the map with 0 frequency to do so.
function addToFrequencyDictionary(
categories: readonly { readonly acronym: string }[],
freqDict: Record<string, number>
) {
// if no colleges/programs/majors/minors for this doc, skip
if (!categories) {
return;
}

categories.forEach(category => {
if (category.acronym in freqDict) {
freqDict[category.acronym] += 1;
} else {
freqDict[category.acronym] = 1;
}
});
}

// adds year to freqDict if not set, otherwise increments frequency by 1
// simplified version of addToFrequencyDictionary for entrance/grad year, as they
// are single elements, not lists, and do not have an acronym prop
function addYearToFrequencyDictionary(year: string, freqDict: Record<string, number>) {
if (!year) {
return;
}

if (year in freqDict) {
freqDict[year] += 1;
} else {
freqDict[year] = 1;
}
}

/**
* TrackUsers returns user metrics based on
* data from the user-name and user-semesters Firestore collections.
*
* It returns the total number of users (total-users),
* the total number of semesters across all users (total-semesters),
* the average number of semesters per user (avg-semester),
* the average number of older semesters that are/before the current semester
* per user (avg-old-semester),
* and the average number of newer semesters that are
* after the current semester (avg-new-semester).
*/

exports.TrackUsers = functions.https.onRequest(async (req, res) => {
let totalUsersCount = 0;
const semesters = [];
const oldSemesters = [];
const newSemesters = [];
let semesterCount = 0;

const usernamePromise = usernameCollection.get().then(usernameQuerySnapshot => {
usernameQuerySnapshot.forEach(() => {
totalUsersCount += 1;
});
const usernameResponse = {
'total-users': totalUsersCount,
};
return usernameResponse;
});

const semesterPromise = semestersCollection.get().then(semesterQuerySnapshot => {
semesterQuerySnapshot.forEach(doc => {
let oldSemesterCount = 0;
let newSemesterCount = 0;
doc.data().semesters.forEach(semester => {
if (isOld(semester)) {
oldSemesterCount += 1;
} else {
newSemesterCount += 1;
}
semesterCount += 1;
});
semesters.push(doc.data().semesters.length);
oldSemesters.push(oldSemesterCount);
newSemesters.push(newSemesterCount);
});
const semesterResponse = {
'total-semesters': semesterCount,
'avg-semester': average(semesters),
'avg-old-semester': average(oldSemesters),
'avg-new-semster': average(newSemesters),
};
return semesterResponse;
});

const onboardingPromise = onboardingCollection.get().then(onboardingQuerySnapshot => {
let undergradCount = 0;
let gradCount = 0;
let undergradAndGradCount = 0;

let totalNumMajors = 0;
let totalNumMinors = 0;
let totalNumExams = 0;

const collegeFreq: Record<string, number> = {};
const programFreq: Record<string, number> = {};
const majorFreq: Record<string, number> = {};
const minorFreq: Record<string, number> = {};

const entranceYearFreq: Record<string, number> = {};
const gradYearFreq: Record<string, number> = {};

onboardingQuerySnapshot.forEach(doc => {
const { majors, minors, exam, colleges, gradPrograms } = doc.data();

addToFrequencyDictionary(colleges, collegeFreq);
addToFrequencyDictionary(gradPrograms, programFreq);
addToFrequencyDictionary(majors, majorFreq);
addToFrequencyDictionary(minors, minorFreq);

addYearToFrequencyDictionary(doc.data().entranceYear, entranceYearFreq);
addYearToFrequencyDictionary(doc.data().gradYear, gradYearFreq);

const isUndergrad = colleges && colleges.length > 0;
const isGrad = gradPrograms && gradPrograms.length > 0;

if (isUndergrad) {
if (isGrad) {
undergradAndGradCount += 1;
} else {
undergradCount += 1;
}

totalNumMajors += majors ? majors.length : 0;
totalNumMinors += minors ? minors.length : 0;
totalNumExams += exam ? exam.length : 0;
} else if (isGrad) {
gradCount += 1;
}
});

const onboardingResponse = {
'undergrad-students': undergradCount,
'grad-students': gradCount,
'both-undergrad-and-grad-students': undergradAndGradCount,
'undergrad-college-frequencies': collegeFreq,
'major-frequencies': majorFreq,
'minor-frequencies': minorFreq,
'graduate-program-frequencies': programFreq,
'average-number-majors-for-undergrads':
totalNumMajors / (undergradAndGradCount + undergradCount),
'average-number-minors-for-undergrads':
totalNumMinors / (undergradAndGradCount + undergradCount),
'average-number-ap/ib-exams-for-undergrads':
totalNumExams / (undergradAndGradCount + undergradCount),
'entrance-year-frequencies': entranceYearFreq,
'grad-year-frequencies': gradYearFreq,
};

return onboardingResponse;
});

Promise.all([usernamePromise, semesterPromise, onboardingPromise]).then(promiseResponses => {
const response = Object.assign({}, ...promiseResponses);
// eslint-disable-next-line no-console
console.log(response);
res.send(response);
return response;
});
});
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.