Agent View Schema Documentation
Overview
The Agent View provides agent-level churn analysis using Stage3 snapshot data. This document outlines the schema, data sources, and integration points for implementing the Agent dashboard feature.Data Source
Primary Table:stage3_snapshot_history
Schema
Key Differences from CEO View
| Aspect | CEO View (Stage1) | Agent View (Stage3) |
|---|---|---|
| Granularity | Business-level | Agent × Business-level |
| Employee Count | COUNT(DISTINCT member_id) | Pre-aggregated in Stage3 |
| Commission | SUM(total) | SUM(agent_total) per agent |
| Use Case | Executive reporting | Agent dashboards, payout validation |
| Metrics | Company-wide churn | Agent-specific business changes |
Agent View Metrics
1. Agent Monthly Commission
View:agent_monthly_commission
Aggregates commission by agent, business, and month.
Output Columns:
month- Period labelagent_name- Agent identifierbusiness_name- Business nametotal_employees- Employee counttotal_commission- Agent commissionhas_tpa_commission- Whether TPA was applied
2. Agent Business Churn (MoM)
View:agent_business_churn_mom
Tracks month-over-month changes in agent’s book of business.
Output Columns:
month- Current monthagent_name- Agent identifierbusiness_name- Business nameprevious_month_employees- Employee count in prior monthcurrent_month_employees- Employee count in current monthemployee_change- Net change in employeesprevious_month_commission- Commission in prior monthcurrent_month_commission- Commission in current monthcommission_change- Net change in commissionchange_category- Classification: New Business, Lost Business, Growth, Decline, Stableemployee_change_percent- Percentage change in employees
3. Agent Attrition Events
View:agent_attrition_events
Filters to businesses where agent lost ≥15% employees but business remains active.
Output Columns:
- Same as
agent_business_churn_mom, filtered to:change_category = 'Decline'employee_change_percent <= -15.0current_month_employees > 0
4. Agent Performance Summary
View:agent_performance_summary
Aggregate metrics per agent for the reporting period.
Output Columns:
agent_name- Agent identifiertotal_businesses- Count of unique businessesmonths_active- Number of months with activitytotal_employees- Sum of all employee countstotal_commission- Sum of all commissionsbusinesses_gained- Count of new businessesbusinesses_lost- Count of lost businessesnet_business_change- Gained - Lostbusinesses_with_attrition- Count with ≥15% employee lossavg_commission_per_employee- Average commission rate
Implementation Roadmap
Phase 1: Data Pipeline (Not Yet Implemented)
- Create ETL job to load Stage3 snapshots to BigQuery
- Populate
stage3_snapshot_historytable - Validate data quality and completeness
- Set up incremental loading for new months
Phase 2: SQL Views (Scaffolding Complete ✓)
- Create
agent_monthly_commissionview - Create
agent_business_churn_momview - Create
agent_attrition_eventsview - Create
agent_performance_summaryview
Phase 3: API Integration
- Add
get_agent_churn_data(agent_name, start_month, end_month)toapi/bigquery/queries.py - Add
get_agent_performance_summary()endpoint - Add
get_agent_attrition_alerts(agent_name)endpoint - Create API route in
api/routes/agent_dashboard.py
Phase 4: Dashboard UI
- Create
dashboard/src/pages/agent/index.tsx- Agent dashboard page - Create
dashboard/src/components/AgentChurnTable.tsx- Churn events table - Create
dashboard/src/components/AgentPerformanceCard.tsx- Summary metrics - Add agent filter dropdown to select specific agent
- Add date range picker for custom period selection
Phase 5: Reporting
- Generate Excel export for agent-level churn reports
- Add agent churn tab to existing executive reports
- Create automated alerts for agents with high attrition
Dashboard Mockup
Agent Dashboard Page Structure
Integration with Existing Systems
CEO View vs Agent View
CEO View (Current Implementation):- Purpose: Executive-level visibility into overall business health
- Data: Stage1 snapshots (raw employee data)
- Metrics: Total employees, total commission, business-level churn
- Audience: CEO, CFO, Executive team
- Purpose: Agent-level performance tracking and client relationship management
- Data: Stage3 snapshots (post-TPA agent commissions)
- Metrics: Agent-specific book of business, client gains/losses, attrition alerts
- Audience: Agents, Sales managers, Operations team
Data Flow
API Endpoint Specifications (Future)
1. Get Agent Churn Data
2. Get Agent Performance Summary
3. Get Agent Attrition Alerts
Testing Checklist
Data Validation
- Verify Stage3 data loads correctly to BigQuery
- Confirm employee counts match between Stage1 and Stage3 aggregates
- Validate commission totals against existing reports
- Check for duplicate records
View Accuracy
- Compare
agent_business_churn_momresults with manual calculations - Verify attrition threshold (≥15%) is applied correctly
- Confirm change_category logic matches business rules
- Validate agent performance summary totals
API Testing
- Test all API endpoints with valid agent names
- Test error handling for invalid agent names
- Verify date range filtering works correctly
- Check response time for large datasets
UI Testing
- Verify agent dropdown populates with all agents
- Test churn table sorting and filtering
- Confirm performance cards display correct metrics
- Validate responsive design on mobile devices
Notes
- Stage3 data is already available in
data/archive/{month}/stage3_snapshot.csv - BigQuery upload needs to be implemented (see
integration/bigquery/scripts/etl_loader.py) - SQL views are ready and can be deployed once Stage3 data is in BigQuery
- Dashboard scaffolding (placeholder tab) is included in CEO churn workbook
- No breaking changes to existing CEO view or reports
Next Steps
- Review and approve SQL view logic
- Implement Stage3 data ETL to BigQuery
- Deploy SQL views to BigQuery
- Build API endpoints for agent queries
- Create React dashboard components
- User acceptance testing with agent team
- Production deployment
Last Updated: 2025-10-17
Status: Scaffolding Complete - Ready for Implementation
Owner: Engineering Team