Skip to content

#160: Implement real API for KPI Analytics Lambda#180

Open
anupbpote02 wants to merge 6 commits into
mainfrom
anupb_160_kpi_api_analytics
Open

#160: Implement real API for KPI Analytics Lambda#180
anupbpote02 wants to merge 6 commits into
mainfrom
anupb_160_kpi_api_analytics

Conversation

@anupbpote02

Copy link
Copy Markdown
Contributor

Summary

Implements kpi_api_analytics.py — a new AWS Lambda that connects to the Virginia RDS PostgreSQL database and returns chart-ready JSON for two KPI dashboard widgets.

Closes #160

What's Implemented

Part 1 — Request Status Distribution

  • Counts requests grouped by status (CREATED, IN_PROGRESS, RESOLVED)
  • Returns request_status_distribution array and total_requests count
  • Returns [] and 0 when no data exists

Part 2 — Average Resolution Time by Category

  • Calculates avg resolution time (hours) per help category
  • Uses submission_date and serviced_date, only includes fully resolved requests
  • Returns SLA metadata (target: 10 days/240 hours, warning: 8.33 days/200 hours)
  • Returns [] when no resolved requests exist, SLA always present

Error Handling

  • DB connection and queries wrapped in try/except
  • Returns statusCode 500 with safe defaults on failure
  • finally block closes cursor and connection

Local Testing

  • __main__ block for local execution
  • Verified: safe response on missing env vars, no crashes, all keys present

Schema Corrections from Issue

The issue referenced table/column names that differ from the actual Virginia DB:

Issue assumed Actual DB Used in code
request.request_id request.req_id req_id
request.request_status request.req_status_id (FK) Joined to request_status table
request.category_id request.req_cat_id req_cat_id
request_category table help_categories table help_categories
request.resolved_date request.serviced_date serviced_date

Reference

  • Follows patterns from beneficiariesTrendAnalysis.py and volunteer_application_analytics.py
  • Table/column names confirmed from Saayam_Table.column.names_data.xlsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement real API for KPI_API_Analytics.py— complete, test & deploy

1 participant