Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
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
74 changes: 73 additions & 1 deletion app/logic/volunteerSpreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 +226,74 @@ 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(fn.DISTINCT(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)
)
)
.where(
(CeltsLabor.term == term)
)
.group_by(CeltsLabor.user)
)
Comment on lines +256 to +260
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This query selects non-aggregated columns (full name, bnumber, email) but only groups by CeltsLabor.user. This relies on MySQL's non-standard GROUP BY behavior and will break if ONLY_FULL_GROUP_BY is enabled, and it also reduces portability/clarity. Include the non-aggregated selected columns (or the underlying User fields) in the GROUP BY to make the aggregation deterministic and SQL-standard.

Copilot uses AI. Check for mistakes.

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')
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

nonLaborQuery counts EventParticipant.event_id without DISTINCT, while laborQuery counts distinct Event.id. Since EventParticipant has no uniqueness constraint on (user,event), duplicate participant rows would inflate the meeting count for non-labor attendees. Use a distinct count here as well (e.g., count distinct event id) so "Meetings Attended" consistently reflects unique meetings.

Suggested change
fn.COUNT(EventParticipant.event_id).alias('meetingsAttended')
fn.COUNT(fn.DISTINCT(EventParticipant.event_id)).alias('meetingsAttended')

Copilot uses AI. Check for mistakes.
)
.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) &
(CeltsLabor.term == term)
)
.where(CeltsLabor.user.is_null())
.group_by(EventParticipant.user)
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This query selects non-aggregated columns (full name, bnumber, email) but only groups by EventParticipant.user. As written, it depends on MySQL's permissive GROUP BY behavior and can fail under ONLY_FULL_GROUP_BY. Group by the non-aggregated selected columns (or the underlying User fields) so the aggregation is deterministic and compatible with stricter SQL modes.

Suggested change
.group_by(EventParticipant.user)
.group_by(
User.firstName,
User.lastName,
User.bnumber,
User.username,
)

Copilot uses AI. Check for mistakes.
)

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,9 +340,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).")

makeDataXls(fallTerm.description, getAllTermData(fallTerm), workbook, sheetDesc= "All event participation for the term, excluding deleted or canceled events.")
makeDataXls(springTerm.description, getAllTermData(springTerm), workbook, sheetDesc="All event participation for the term, excluding deleted or canceled events.")

Expand Down
56 changes: 54 additions & 2 deletions tests/code/test_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from app.models.user import User
from app.models.term import Term
from app.models.eventParticipant import EventParticipant
from app.models.celtsLabor import CeltsLabor
from app.logic.volunteerSpreadsheet import *
from app.models.program import Program
from app.models.event import Event
Expand Down Expand Up @@ -32,7 +33,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 +43,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 All @@ -62,6 +65,10 @@ def fixture_info():
isService=True
)

labor1 = CeltsLabor.create(user=user1, term=term1, positionTitle="test position 1")
labor2 = CeltsLabor.create(user=user2, term=term1, positionTitle="test position 2")
labor3 = CeltsLabor.create(user=user1, term=term2, positionTitle="test position 3")
labor4 = CeltsLabor.create(user=user2, term=term2, positionTitle="test position 4")

eventparticipant1 = EventParticipant.create(event=event1, user=user1, hoursEarned=5)
eventparticipant2 = EventParticipant.create(event=event1, user=user2, hoursEarned=3)
Expand All @@ -86,6 +93,10 @@ def fixture_info():
'eventparticipant1': eventparticipant1,
'eventparticipant2': eventparticipant2,
'eventparticipant4': eventparticipant4,
'labor1': labor1,
'labor2': labor2,
'labor3': labor3,
'labor4': labor4
}

transaction.rollback()
Expand Down Expand Up @@ -683,5 +694,46 @@ def test_getUniqueVolunteers(fixture_info):
("Test Tester", "testt@berea.edu", "B55555"),
])

@pytest.mark.integration
def test_laborAttendanceByTerm(fixture_info):
columns, results = laborAttendanceByTerm(fixture_info['term1'])
results = list(results)

assert columns == ("Full Name", "B-Number", "Email", "Meetings Attended")

assert len(results) == 2
assert ("John Doe", "B774377", "doej@berea.edu", 1) in results
assert ("Jane Doe", "B888828", "doej2@berea.edu", 1) in results

columns, results = laborAttendanceByTerm(fixture_info['term2'])
results = list(results)

assert len(results) == 2
assert ("John Doe", "B774377", "doej@berea.edu", 0) in results
assert ("Jane Doe", "B888828", "doej2@berea.edu", 0) in results

EventParticipant.create(event=fixture_info['event2'], user=fixture_info['user1'], hoursEarned=1)

columns, results = laborAttendanceByTerm(fixture_info['term1'])
results = list(results)

assert len(results) == 2
assert ("John Doe", "B774377", "doej@berea.edu", 2) in results
assert ("Jane Doe", "B888828", "doej2@berea.edu", 1) in results

EventParticipant.create(event=fixture_info['event1'], user=fixture_info['user3'], hoursEarned=1)

columns, results = laborAttendanceByTerm(fixture_info['term1'])
results = list(results)

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

EventParticipant.create(event=fixture_info['event3'], user=fixture_info['user1'], hoursEarned=2)

columns, results = laborAttendanceByTerm(fixture_info['term1'])
results = list(results)

assert ("John Doe", "B774377", "doej@berea.edu", 2) in results
Loading