Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5905549
added the function laborAttendanceByTerm
Arohasina Feb 25, 2026
97fe183
added test function test_laborAttendanceByTerm
Arohasina Feb 25, 2026
4c89d93
added laborAttendanceByTerm to the spreadsheet
Arohasina Feb 25, 2026
be0b9af
removed print statements
Arohasina Feb 26, 2026
eeb4674
removed commented code
Arohasina Feb 26, 2026
07e2ded
Update app/logic/volunteerSpreadsheet.py
Arohasina Feb 26, 2026
ee86729
Update app/logic/volunteerSpreadsheet.py
Arohasina Feb 26, 2026
c9119da
Merge branch 'development' of https://github.com/BCStudentSoftwareDev…
JohnCox2211 Feb 26, 2026
6209cba
removed redundant event and reused existing ones
Arohasina Feb 26, 2026
d68bda6
Merge branch 'Labor_Attendance_report_1626' of github.com:BCStudentSo…
Arohasina Feb 26, 2026
4a863e3
added distinct
Arohasina Feb 26, 2026
7652303
Merge remote-tracking branch 'origin' into Labor_Attendance_report_1626
Arohasina Mar 10, 2026
d37e2ae
include all labor students even with zero attendance and non-labor at…
Arohasina Mar 18, 2026
7936d62
added the return
Arohasina Mar 18, 2026
86fd8c6
Merge remote-tracking branch 'origin' into Labor_Attendance_report_1626
Arohasina Mar 18, 2026
4354374
switched FULL JOIN to Union to fix SQL syntax bug
Arohasina Mar 18, 2026
85cedd3
Merge remote-tracking branch 'origin' into Labor_Attendance_report_1626
Arohasina Mar 24, 2026
240e802
Split labor attendance report into separate sheets by term and fix bl…
Arohasina Mar 24, 2026
5cd4859
for laborQuery changed EventParticipant.event_id to Event.id to fix c…
Arohasina Mar 24, 2026
ef2e93d
removed redundant
Arohasina Mar 25, 2026
80081a2
fix filter term
Arohasina Mar 26, 2026
f9749ff
fix test
Arohasina Mar 26, 2026
68ca9ef
Update app/logic/volunteerSpreadsheet.py
Arohasina Mar 29, 2026
368521c
Merge branch 'development' into Labor_Attendance_report_1626
Arohasina Mar 29, 2026
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
73 changes: 72 additions & 1 deletion app/logic/volunteerSpreadsheet.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from os import major
from openpyxl import workbook
import xlsxwriter
from peewee import fn, Case, JOIN, SQL, Select
from collections import defaultdict
from datetime import date, datetime,time
from app import app
from app.models import mainDB
from app.models.celtsLabor import CeltsLabor
from app.models.eventParticipant import EventParticipant
from app.models.user import User
from app.models.program import Program
Expand Down Expand Up @@ -225,6 +227,70 @@ def calculateRetentionRate(fallDict, springDict):

return retentionDict

def laborAttendanceByTerm(term):
laborQuery = ( #so that all Celts Labor students appear even if they didn't attend anything
CeltsLabor
.select(
fn.CONCAT(User.firstName, ' ', User.lastName).alias('fullName'),
User.bnumber,
fn.CONCAT(User.username, '@berea.edu').alias('email'),
fn.COUNT(EventParticipant.event_id).alias('meetingsAttended')
)
.join(User)
.switch(CeltsLabor)
.join(
EventParticipant,
JOIN.LEFT_OUTER,
on=(CeltsLabor.user == EventParticipant.user)
)
.join(
Event,
JOIN.LEFT_OUTER,
on=(
(EventParticipant.event == Event.id) &
(Event.term == term) &
(Event.isLaborOnly == True) &
(Event.deletionDate.is_null()) &
(Event.isCanceled == False)
)
)
.group_by(CeltsLabor.user)
)

nonLaborQuery = ( #so that non-labor attendees who are not in CeltsLabor also appear
EventParticipant
.select(
fn.CONCAT(User.firstName, ' ', User.lastName).alias('fullName'),
User.bnumber,
fn.CONCAT(User.username, '@berea.edu').alias('email'),
fn.COUNT(EventParticipant.event_id).alias('meetingsAttended')
)
.join(User)
.switch(EventParticipant)
.join(
Event,
on=(
(EventParticipant.event == Event.id) &
(Event.term == term) &
(Event.isLaborOnly == True) &
(Event.deletionDate.is_null()) &
(Event.isCanceled == False)
)
)
.join(
CeltsLabor,
JOIN.LEFT_OUTER,
on=(EventParticipant.user == CeltsLabor.user)
)
.where(CeltsLabor.user.is_null())
.group_by(EventParticipant.user)
)

query = laborQuery.union(nonLaborQuery).order_by(SQL('fullName'))
columns = ("Full Name", "B-Number", "Email", "Meetings Attended")

return (columns, query.tuples())


def makeDataXls(sheetName, sheetData, workbook, sheetDesc=None):
# assumes the length of the column titles matches the length of the data
Expand Down Expand Up @@ -271,7 +337,12 @@ def createSpreadsheet(academicYear):
makeDataXls("Unique Volunteers", getUniqueVolunteers(academicYear), workbook, sheetDesc=f"All students who participated in at least one service event during {academicYear}.")
makeDataXls("Only All Volunteer Training", onlyCompletedAllVolunteer(academicYear), workbook, sheetDesc="Students who participated in an All Volunteer Training, but did not participate in any service events.")
makeDataXls("Retention Rate By Semester", getRetentionRate(academicYear), workbook, sheetDesc="The percentage of students who participated in service events in the fall semester who also participated in a service event in the spring semester. Does not currently account for fall graduations.")


fallTerm = getFallTerm(academicYear)
springTerm = getSpringTerm(academicYear)
makeDataXls(f"Labor Attendance {fallTerm.description}", laborAttendanceByTerm(fallTerm), workbook,sheetDesc=f"Number of labor-only events attended in {fallTerm.description} for each labor student and non-labor attendees, including zero attendance (for labor students).")
makeDataXls(f"Labor Attendance {springTerm.description}", laborAttendanceByTerm(springTerm), workbook, sheetDesc=f"Number of labor-only events attended in {springTerm.description} for each labor student and non-labor attendees, including zero attendance (for labor students).")

fallTerm = getFallTerm(academicYear)
springTerm = getSpringTerm(academicYear)
makeDataXls(fallTerm.description, getAllTermData(fallTerm), workbook, sheetDesc= "All event participation for the term, excluding deleted or canceled events.")
Expand Down
21 changes: 17 additions & 4 deletions tests/code/test_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def fixture_info():
startDate=date(2023, 9, 1),
isCanceled=False,
deletionDate=None,
isService=True
isService=True,
isLaborOnly=True
)
event2 = Event.create(
name='Event2',
Expand All @@ -41,7 +42,8 @@ def fixture_info():
startDate=date(2023, 9, 10),
isCanceled=False,
deletionDate=None,
isService=True
isService=True,
isLaborOnly=True
)
event3 = Event.create(
name='Event3',
Expand Down Expand Up @@ -683,5 +685,16 @@ def test_getUniqueVolunteers(fixture_info):
("Test Tester", "testt@berea.edu", "B55555"),
])



@pytest.mark.integration
def test_laborAttendanceByTerm(fixture_info):
EventParticipant.create(event=fixture_info["event2"], user=fixture_info['user1'], hoursEarned=1)
EventParticipant.create(event=fixture_info["event2"], user=fixture_info['user2'], hoursEarned=1)
EventParticipant.create(event=fixture_info["event1"], user=fixture_info['user3'], hoursEarned=1)

columns, results = laborAttendanceByTerm("2023-2024-test")
assert columns == ("Full Name", "B-Number", "Email", "Term", "Meetings Attended")

assert len(results) == 3
assert ("John Doe", "B774377", "doej@berea.edu", "Fall 2023", 2) in results
assert ("Jane Doe", "B888828", "doej2@berea.edu", "Fall 2023", 2) in results
assert ("Bob Builder", "B00700932", "builderb@berea.edu", "Fall 2023", 1) in results
Loading