-
Notifications
You must be signed in to change notification settings - Fork 0
changes in new-allocation-card #654
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
Open
conwelld
wants to merge
18
commits into
department-portal-base
Choose a base branch
from
new-allocation-card
base: department-portal-base
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9bd90f6
added changes from previous branch to avoid all files being commited
conwelld 56d5a29
fixed some pr comments
conwelld faf1957
fixed some pr comments for css styling
conwelld 1204269
fixed useless code
conwelld 0f166c2
fixed department code
conwelld 6f5850a
We have change the hard coded part with variable able to be flexible …
813f398
Temporary allocation logic will be replaced by the official shared se…
7584ffa
fix the review comment from Minran, all of them
DanielRukwasha e9a4415
Merge branch 'department-portal-base' into new-allocation-card, resol…
DanielRukwasha 20b424c
Fix import after allocationUtilization rename to getAllocation, add i…
DanielRukwasha ee0e066
Address PR review comments: consolidate getAllocation return dict, ex…
DanielRukwasha 6abd704
Merge branch 'department-portal-base' into new-allocation-card, resol…
DanielRukwasha 8618b68
Adopt approval-status filtering from UsedAllocFunction branch in getA…
DanielRukwasha a0ba238
Polish the allocation card: dynamic Fall/Spring term label, "X of Y" …
munsakad 86bee45
Merge branch 'department-portal-base' into new-allocation-card
munsakad 45b13e0
Fix duplicate main.managePositions endpoint left over from the depart…
munsakad 74bdd3a
Rework allocation rows to the "N hr: X contracts (out of Y allocation…
munsakad a7ca474
Address allocation card review: camelCase naming, stacked layout, con…
munsakad 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 hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
| from datetime import date | ||
|
|
||
| from peewee import fn | ||
|
BrianRamsay marked this conversation as resolved.
|
||
|
|
||
| from app.models.allocation import Allocation | ||
|
DanielRukwasha marked this conversation as resolved.
|
||
| from app.models.laborStatusForm import LaborStatusForm | ||
| from app.models.term import Term | ||
|
DanielRukwasha marked this conversation as resolved.
|
||
| from app.models.formHistory import FormHistory | ||
|
|
||
|
|
||
| def getCurrentSemesterLabel(term): | ||
| """Return the Fall/Spring label (e.g. "Fall 2025") for the AY term's | ||
| current semester, picking the season from today's month.""" | ||
| if not term: | ||
| return None | ||
| academicYear = int(str(term.termCode)[:4]) | ||
| if date.today().month >= 8: | ||
| return f"Fall {academicYear}" | ||
| return f"Spring {academicYear + 1}" | ||
|
|
||
|
|
||
| def countWorkers(department, termCode, jobType, hoursBucket): | ||
| workerCount = ( | ||
| LaborStatusForm.select() | ||
| .join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID)) | ||
| .where( | ||
| LaborStatusForm.department == department, | ||
| LaborStatusForm.termCode == termCode, | ||
| LaborStatusForm.jobType == jobType, | ||
| LaborStatusForm.weeklyHours == hoursBucket, | ||
| LaborStatusForm.contractHours.is_null(True), | ||
| FormHistory.historyType == "Labor Status Form", | ||
| ~(FormHistory.status % "Denied%"), | ||
| ) | ||
| .count() | ||
| ) | ||
| return workerCount | ||
|
|
||
|
|
||
| def getBreakHours(department, termCode): | ||
| breakHoursTotal = ( | ||
| LaborStatusForm.select(fn.SUM(LaborStatusForm.contractHours)) | ||
| .join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID)) | ||
| .where( | ||
| LaborStatusForm.department == department, | ||
| LaborStatusForm.termCode == termCode, | ||
| FormHistory.historyType == "Labor Status Form", | ||
| FormHistory.status == "Approved", | ||
| ) | ||
| .scalar() | ||
| ) or 0 | ||
| return breakHoursTotal | ||
|
|
||
|
|
||
| def getDepartmentAllocationSummary(department): | ||
| """Return allocation-utilization values for a department's most recent term.""" | ||
| result = { | ||
| "term": None, | ||
| "currentSemester": None, | ||
| "allocated": 0, | ||
| "used": 0, | ||
| "usedPositions": { | ||
| "used10": 0, | ||
| "used12": 0, | ||
| "used15": 0, | ||
| "used20": 0, | ||
| "usedSecondary5": 0, | ||
| "usedSecondary10": 0, | ||
| }, | ||
| "breakHours": 0, | ||
| } | ||
|
Contributor
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. when Chris's allocationManager is merge you will have to revisit the logic |
||
|
|
||
| departmentAllocations = list( | ||
| Allocation.select(Allocation, Term).join(Term).where(Allocation.department == department) | ||
| ) | ||
| if not departmentAllocations: | ||
| return result | ||
|
|
||
| recentTerm = Term.order_by_term([a.termCode for a in departmentAllocations], reverse=True)[0] | ||
| termCode = recentTerm.termCode | ||
| result["term"] = recentTerm | ||
| result["currentSemester"] = getCurrentSemesterLabel(recentTerm) | ||
|
|
||
| totalPositions = ( | ||
| Allocation.select( | ||
| fn.SUM(Allocation.primary_10) | ||
| + fn.SUM(Allocation.primary_12) | ||
| + fn.SUM(Allocation.primary_15) | ||
| + fn.SUM(Allocation.primary_20) | ||
| + fn.SUM(Allocation.secondary_5) | ||
| + fn.SUM(Allocation.secondary_10) | ||
| ) | ||
| .where( | ||
| Allocation.department == department, | ||
| Allocation.termCode == termCode, | ||
| ) | ||
| .scalar() | ||
| ) | ||
| result["allocated"] = totalPositions or 0 | ||
|
|
||
| usedAllocation = ( | ||
| LaborStatusForm.select() | ||
| .join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID)) | ||
| .where( | ||
| LaborStatusForm.department == department, | ||
| LaborStatusForm.termCode == termCode, | ||
| LaborStatusForm.contractHours.is_null(True), | ||
| FormHistory.historyType == "Labor Status Form", | ||
| ~(FormHistory.status % "Denied%"), | ||
| ) | ||
| .count() | ||
| ) | ||
| result["used"] = usedAllocation | ||
|
|
||
| result["usedPositions"] = { | ||
| "used10": countWorkers(department, termCode, "Primary", 10), | ||
| "used12": countWorkers(department, termCode, "Primary", 12), | ||
| "used15": countWorkers(department, termCode, "Primary", 15), | ||
| "used20": countWorkers(department, termCode, "Primary", 20), | ||
| "usedSecondary5": countWorkers(department, termCode, "Secondary", 5), | ||
| "usedSecondary10": countWorkers(department, termCode, "Secondary", 10), | ||
| } | ||
|
|
||
| result["breakHours"] = getBreakHours(department, termCode) | ||
|
|
||
| return result | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.