Skip to content
Open
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
63 changes: 63 additions & 0 deletions 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,67 @@ def calculateRetentionRate(fallDict, springDict):

return retentionDict

def laborAttendanceByTerm(academicYear):
# """Get labor students and their meeting attendance count for each term"""
# base = getBaseQuery(academicYear)

# query = (base.select(
# fn.CONCAT(User.firstName, ' ', User.lastName).alias('fullName'),
# User.bnumber,
# fn.CONCAT(EventParticipant.user_id, '@berea.edu').alias('email'),
# Term.description,
# fn.COUNT(EventParticipant.event_id).alias('meetingsAttended'),
# )
# .where(Event.isLaborOnly == True)
# .group_by(EventParticipant.user_id, Term.description)
# .order_by(User.lastName, User.firstName, Term.description)
# )

# columns = ("Full Name", "B-Number", "Email", "Term", "Meetings Attended")
# results = list(query.tuples())
# return (columns, results)


query = (
CeltsLabor
.select(
fn.CONCAT(User.firstName, ' ', User.lastName).alias('fullName'),
User.bnumber,
fn.CONCAT(User.username, '@berea.edu').alias('email'),
Term.description,
fn.COUNT(EventParticipant.event_id).alias('meetingsAttended')
)
.join(User)
.switch(CeltsLabor)
.join(
EventParticipant,
JOIN.FULL,
on=(CeltsLabor.user == EventParticipant.user)
)
.join(
Event,
JOIN.LEFT_OUTER,
on=(EventParticipant.event_id == Event.id)
)
.join(
Term,
on=(Event.term == Term.id)
)
.where(
Term.academicYear == academicYear,
Event.isLaborOnly == True,
Event.deletionDate.is_null(True),
Event.isCanceled == False
)
.group_by(User.id, Term.description)
.order_by(User.lastName, User.firstName, Term.description)
)

columns = ("Full Name", "B-Number", "Email", "Term", "Meetings Attended")
results = list(query.tuples())
return (columns, results)



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,6 +333,7 @@ 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.")
makeDataXls("Labor Attendance By Term", laborAttendanceByTerm(academicYear), workbook, sheetDesc="Labor students and the number of labor events attended for each term in the academic year.")

fallTerm = getFallTerm(academicYear)
springTerm = getSpringTerm(academicYear)
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
Comment on lines +35 to +36
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace after the comma on these lines. Consider removing it for consistency with the rest of the codebase.

Copilot uses AI. Check for mistakes.
)
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
Comment on lines +45 to +46
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace after the comma on these lines. Consider removing it for consistency with the rest of the codebase.

Copilot uses AI. Check for mistakes.
)
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