diff --git a/app/logic/events.py b/app/logic/events.py index 822d85632..274de795c 100644 --- a/app/logic/events.py +++ b/app/logic/events.py @@ -1,5 +1,5 @@ from flask import url_for, g, session -from peewee import DoesNotExist, fn, JOIN +from peewee import DoesNotExist, fn, JOIN, Case, Value from dateutil import parser from datetime import timedelta, date, datetime from dateutil.relativedelta import relativedelta @@ -398,21 +398,21 @@ def getParticipatedEventsForUser(user): Used in testing, defaults to the current timestamp. :return: A list of Event objects """ - - participatedEvents = (Event.select(Event, Program.programName) + participatedEvents = (Event.select(Event, Program.programName, Case(None, ( + ((Event.isLaborOnly | Event.name.contains("Labor")) & Event.isService, "Labor & Volunteer"), + ((Event.isLaborOnly | Event.name.contains("Labor")), "Labor"), + (Event.isService, "Volunteer")), "Attendee").alias("participatedType")) .join(Program, JOIN.LEFT_OUTER).switch() .join(EventParticipant) .where(EventParticipant.user == user, Event.isAllVolunteerTraining == False, Event.deletionDate == None) .order_by(Event.startDate, Event.name)) - - allVolunteer = (Event.select(Event, "") + allVolunteer = (Event.select(Event, "", Value("Volunteer").alias("participatedType")) .join(EventParticipant) .where(Event.isAllVolunteerTraining == True, EventParticipant.user == user)) union = participatedEvents.union_all(allVolunteer) - unionParticipationWithVolunteer = list(union.select_from(union.c.id, union.c.programName, union.c.startDate, union.c.name).order_by(union.c.startDate, union.c.name).execute()) - + unionParticipationWithVolunteer = list(union.select_from(union.c.id, union.c.programName, union.c.startDate, union.c.name, union.c.participatedType).order_by(union.c.startDate, union.c.name).execute()) return unionParticipationWithVolunteer def validateNewEventData(data): diff --git a/app/logic/volunteerSpreadsheet.py b/app/logic/volunteerSpreadsheet.py index 8bbada14a..fe8fd98b1 100644 --- a/app/logic/volunteerSpreadsheet.py +++ b/app/logic/volunteerSpreadsheet.py @@ -206,6 +206,32 @@ def termParticipation(term): return dict(programParticipationDict) +def graduatingSeniorsVolunteerHours(academicYear): + columns = ["Full Name", "Email", "B-Number", "Unique Volunteer Semesters", "Total Volunteer Hours"] + + currentSeniors = (EventParticipant + .select(EventParticipant.user_id) + .join(User).switch(EventParticipant) + .join(Event) + .join(Term) + .where(Term.academicYear == academicYear, User.rawClassLevel.in_(["Senior", "Graduating"]), Event.isService == True, + Event.deletionDate == None, Event.isCanceled == False)) + + query = (EventParticipant + .select(fn.CONCAT(User.firstName, ' ', User.lastName), + fn.CONCAT(User.username, '@berea.edu'), + User.bnumber, + fn.COUNT(fn.DISTINCT(Event.term)).alias("semester_count"), + fn.SUM(EventParticipant.hoursEarned).alias("total_hours")) + .join(User).switch(EventParticipant) + .join(Event) + .where(Event.isService == True, Event.deletionDate == None, Event.isCanceled == False, EventParticipant.user_id.in_(currentSeniors)) + .group_by(User.bnumber) + .having(fn.COUNT(fn.DISTINCT(Event.term)) >= 4) + .order_by(SQL("semester_count").desc())) + + return (columns, query.tuples()) + def removeNullParticipants(participantList): return list(filter(lambda participant: participant, participantList)) @@ -270,6 +296,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("Graduating Seniors", graduatingSeniorsVolunteerHours(academicYear), workbook, sheetDesc="Graduating seniors who have earned any number of service hours for at least 4 unique semesters.") fallTerm = getFallTerm(academicYear) springTerm = getSpringTerm(academicYear) diff --git a/app/static/js/volunteerDetails.js b/app/static/js/volunteerDetails.js index 1b6192a23..436691673 100644 --- a/app/static/js/volunteerDetails.js +++ b/app/static/js/volunteerDetails.js @@ -61,8 +61,7 @@ $(document).ready(function () { } function sortVolunteers() { - let sortedTable = $("#volunteerInformationTableToPrint_wrapper"); - let entriesTable = sortedTable.find(".volunteerInfoEntries"); + entriesTable.sort(function (a, b) { let textA = a.getElementsByClassName('nameSelect')[0].innerText diff --git a/app/templates/main/userProfile.html b/app/templates/main/userProfile.html index e29db4895..49fa59764 100644 --- a/app/templates/main/userProfile.html +++ b/app/templates/main/userProfile.html @@ -167,12 +167,14 @@