Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 19 additions & 5 deletions chalicelib/services/InsightsService.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,33 @@ def _get_dashboard_insights(data):
else:
majors[major] = 1

avg_gpa /= count_gpa
if count_gpa:
avg_gpa /= count_gpa
else:
avg_gpa = "N/A"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using None is a better choice instead of using strings – having multiple datatypes being returned isn't too good of a practice


# calculate most common major/gradYear
common_major, count_common_major = max(majors.items(), key=lambda x: x[1])
common_grad_year, count_common_grad_year = max(grad_years.items(), key=lambda x: x[1])
# Check if majors dictionary is not empty
if majors:
common_major, count_common_major = max(majors.items(), key=lambda x: x[1])
else:
# Handle the case when majors dictionary is empty
common_major, count_common_major = "N/A", 0

# Check if grad_years dictionary is not empty
if grad_years:
common_grad_year, count_common_grad_year = max(grad_years.items(), key=lambda x: x[1])
else:
# Handle the case when grad_years dictionary is empty
common_grad_year, count_common_grad_year = "N/A", 0


dashboard = {
"applicantCount": num_applicants,
"avgGpa": round(avg_gpa, 1), # round to 1 decimal place (e.g. 3.123 -> 3.1)
"avgGpa": round(avg_gpa, 1) if avg_gpa != "N/A" else avg_gpa,
"commonMajor": common_major.title(),
# "countCommonMajor": count_common_major, # TO-DO: maybe do something with common major counts
"commonGradYear": int(common_grad_year),
"commonGradYear": int(common_grad_year) if common_grad_year != 'N/A' else common_grad_year,
# "avgResponseLength": 0 # TO-DO: maybe implement parsing for response lengths
}

Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from app import app

with open('tests/fixtures/sample_dashboard.json') as f:
with open('tests/fixtures/insights/general/sample_dashboard.json') as f:
SAMPLE_DASHBOARD = json.load(f)

with open('tests/fixtures/sample_distribution.json') as f:
with open('tests/fixtures/insights/general/sample_distribution.json') as f:
SAMPLE_DISTRIBUTION = json.load(f)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to create this! In the fixture itself, you can always check for an empty array instead of loading a file and reading it!

6 changes: 6 additions & 0 deletions tests/fixtures/insights/noApplicants/sample_dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"applicantCount": 0,
"avgGpa": "N/A",
"commonMajor": "N/A",
"commonGradYear": "N/A"
}
9 changes: 9 additions & 0 deletions tests/fixtures/insights/noApplicants/sample_distribution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"colleges": [],
"gpa": [],
"gradYear": [],
"major": [],
"minor": [],
"linkedin": [],
"website": []
}
38 changes: 38 additions & 0 deletions tests/fixtures/insights/noGPAs/sample_applicants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"website": "",
"listingId": "9497eb3a-a9cf-44b0-a0d7-d5869fdf6c52",
"colleges": {
"COM": false,
"QST": false,
"CDS": false,
"CAS": true,
"Wheelock": false,
"Sargent": false,
"Pardee": false,
"SHA": false,
"CGS": false,
"ENG": false,
"CFA": false,
"Other": false
},
"responses": [],
"lastName": "De Rocco",
"linkedin": "",
"dateApplied": "2024-02-16T15:52:34.953662-05:00",
"email": "[email protected]",
"firstName": "William",
"applicantId": "db8308c0-ddb7-4995-9441-e97d1d28861f",
"minor": "",
"events": null,
"image": "https://whyphi-zap.s3.amazonaws.com/dev/image/9497eb3a-a9cf-44b0-a0d7-d5869fdf6c52/De Rocco_William_db8308c0-ddb7-4995-9441-e97d1d28861f.png",
"gpa": "",
"hasGpa": false,
"gradYear": "2030",
"resume": "https://whyphi-zap.s3.amazonaws.com/dev/resume/9497eb3a-a9cf-44b0-a0d7-d5869fdf6c52/De Rocco_William_db8308c0-ddb7-4995-9441-e97d1d28861f.pdf",
"major": "Computer Science",
"gradMonth": "January",
"phone": "2032091600",
"preferredName": ""
}
]
6 changes: 6 additions & 0 deletions tests/fixtures/insights/noGPAs/sample_dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"applicantCount": 1,
"avgGpa": "N/A",
"commonMajor": "Computer Science",
"commonGradYear": 2030
}
Loading