179 adding date filter to volunteer activity (trend and location dashboards)#200
Open
KTB2110 wants to merge 4 commits into
Open
179 adding date filter to volunteer activity (trend and location dashboards)#200KTB2110 wants to merge 4 commits into
KTB2110 wants to merge 4 commits into
Conversation
…oth new helpers in get_volunteer_activity_trend to filter by date
#183) - Add get_grouping() to return daily/monthly trunc unit and format string based on time_range - Add build_date_filter() as single shared helper returning WHERE clause + params tuple for both trend and location filters - Update get_volunteer_activity_trend() to accept time_range, start_date, end_date; applies dynamic grouping and date filtering across all three queries - Update get_volunteers_by_location() to accept time_range, start_date, end_date; extends list params with date_params tuple - Use %s placeholders for Custom date range to prevent SQL injection - Rename merge_monthly_data() to merge_period_data() to reflect new period key in responses - Update response key from month to period per API spec - Update lambda_handler to independently read time_range/start_date/end_date for trend and time_range_location/location_start_date/location_end_date for location
…ependent Custom filters (#179) Reworks the volunteer_application_analytics response to return every preset time range in a single call, each containing both dashboard widgets. Response structure: - Top-level keys 7D, 30D, 1Y, All, and Custom - Each range holds { volunteer_activity_trend, volunteers_by_location } - Preset ranges (7D/30D/1Y/All) are always computed and populated regardless of whether a custom range is supplied Custom range handling: - volunteer_activity_trend uses start_date / end_date - volunteers_by_location uses independent location_start_date / location_end_date - Each widget inside Custom is populated only if its own date pair is provided; the other defaults to an empty value (empty trend structure for trend, empty list for location) rather than being omitted, so the shape is stable - Trend data in Custom is grouped daily per spec Other: - Updated safe_response fallback to mirror the new time-range-keyed shape so error responses match the success structure the frontend expects
KTB2110
force-pushed
the
KTB2110_183_date_filter_volunteer_activity
branch
from
July 13, 2026 18:57
cc4342a to
632bfa2
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds independent date filter support to the two volunteer analytics widgets on the Super Admin dashboard.
New Helper Functions
build_date_filter()— single shared helper (confirmed with team lead Sana Desai as preferred over two separate helper functions) that acceptstime_range,start_date, andend_date; returns a SQL WHERE condition string and a params tuple (using%splaceholders to prevent SQL injection). Handles7D,30D,1Y,All, andCustomranges againstvd.created_at.get_grouping()— acceptstime_rangeand returns theDATE_TRUNCunit and format string for dynamic grouping. Short ranges (7D,30D,Custom) group daily (YYYY-MM-DD); long ranges (1Y,All) group monthly (YYYY-MM).Updated Functions
get_volunteer_activity_trend()— now acceptstime_range,start_date,end_date; applies dynamic date filtering and grouping across all three sub-queries (new_volunteers,active_volunteers,total_volunteers). Response key updated frommonthtoperiodper API spec.get_volunteers_by_location()— now acceptstime_range,start_date,end_date; applies date filtering only. No grouping logic added. Country aggregation logic unchanged.merge_periodic_data()— renamed frommerge_monthly_data()to reflect the newperiodkey in responses.lambda_handler()— reads two independent filter sets from the event payload:time_range/start_date/end_datefor trend, andtime_range_location/location_start_date/location_end_datefor location.Independent Filters
Trend and location widgets use separate filter keys so each chart can be filtered independently:
{ "time_range": "30D", "time_range_location": "7D" }Testing
Tested locally against a PostgreSQL copy of the Virginia tables for all five time ranges on both widgets. Verified daily grouping for 7D, 30D, Custom and monthly grouping for 1Y, All. Verified
volunteers_by_locationapplies date filtering without grouping dates, only groups countries.Update — Response Restructure (per updated requirements)
Following updated requirements, the response now returns all preset ranges in a single call, keyed by time range, instead of a single flat trend/location pair.
New Response Shape
{ "7D": { "volunteer_activity_trend": {...}, "volunteers_by_location": [...] }, "30D": { "volunteer_activity_trend": {...}, "volunteers_by_location": [...] }, "1Y": { "volunteer_activity_trend": {...}, "volunteers_by_location": [...] }, "All": { "volunteer_activity_trend": {...}, "volunteers_by_location": [...] }, "Custom": { "volunteer_activity_trend": {...}, "volunteers_by_location": [...] } }7D,30D,1Y,Allare always computed and populated for both widgets, even when a custom range is supplied.Customis always present with both keys.Custom Range — Independent Per-Widget Dates
The two widgets inside
Customhave fully independent date ranges:start_date+end_dateCustom.volunteer_activity_trendpopulated (grouped daily)location_start_date+location_end_dateCustom.volunteers_by_locationpopulatedEmpty defaults differ by widget (pulled from one shared definition, not hand-retyped):
{ "new_volunteers": [], "active_volunteers": [], "total_volunteers": [] }[]Safe Response
The error/fallback response was updated to mirror the new time-range-keyed shape, so error responses match the structure the frontend expects on success (previously it returned the old flat shape, which would have broken frontend code indexing by range).
Additional Testing
Custom.volunteers_by_locationreturns[]Custom.volunteer_activity_trendreturns the empty trend structurenew_volunteerscounts cross-checked directly against the DB and matched exactly (2× raw, since Virginia and Ireland point at the same local DB in testing)Closes #179