feat: Member Effectiveness Score + Representation Alignment View (v0.9.9)

Member Effectiveness Score
- New BillCosponsor table (migration 0018) with per-bill co-sponsor
  party data required for the bipartisan multiplier
- bill_category column on Bill (substantive | commemorative | administrative)
  set by a cheap one-shot LLM call after each brief is generated
- effectiveness_score / percentile / tier columns on Member
- New bill_classifier.py worker with 5 tasks:
    classify_bill_category  — triggered from llm_processor after brief
    fetch_bill_cosponsors   — triggered from congress_poller on new bill
    calculate_effectiveness_scores — nightly at 5 AM UTC
    backfill_bill_categories / backfill_all_bill_cosponsors — one-time
- Scoring: distance-traveled pts × bipartisan (1.5×) × substance (0.1×
  for commemorative) × leadership (1.2× for committee chairs)
- Percentile normalised within (seniority tier × party) buckets
- Effectiveness card on member detail page with colour-coded bar
- Admin panel: 3 new backfill/calculate controls in Maintenance section

Representation Alignment View
- New GET /api/alignment endpoint: cross-references user's stanced bill
  follows (pocket_veto/pocket_boost) with followed members' vote positions
- Efficient bulk queries — no N+1 loops
- New /alignment page with ranked member list and alignment bars
- Alignment added to sidebar nav (auth-required)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jack Levy
2026-03-14 18:05:09 -04:00
parent cba19c7bb3
commit d0da0b8dce
19 changed files with 910 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import axios from "axios";
import type {
AlignmentData,
Bill,
BillAction,
BillDetail,
@@ -303,4 +304,16 @@ export const adminAPI = {
apiClient.get<{ status: string; batch_id?: string; doc_count?: number; submitted_at?: string }>(
"/api/admin/llm-batch-status"
).then((r) => r.data),
backfillCosponsors: () =>
apiClient.post("/api/admin/backfill-cosponsors").then((r) => r.data),
backfillCategories: () =>
apiClient.post("/api/admin/backfill-categories").then((r) => r.data),
calculateEffectiveness: () =>
apiClient.post("/api/admin/calculate-effectiveness").then((r) => r.data),
};
// Alignment
export const alignmentAPI = {
get: () =>
apiClient.get<AlignmentData>("/api/alignment").then((r) => r.data),
};

View File

@@ -51,6 +51,9 @@ export interface Member {
leadership_json?: MemberLeadership[];
sponsored_count?: number;
cosponsored_count?: number;
effectiveness_score?: number;
effectiveness_percentile?: number;
effectiveness_tier?: string;
latest_trend?: MemberTrendScore;
}
@@ -119,6 +122,27 @@ export interface Bill {
latest_trend?: TrendScore;
updated_at?: string;
has_document?: boolean;
bill_category?: string;
}
export interface AlignmentScore {
bioguide_id: string;
name: string;
party?: string;
state?: string;
chamber?: string;
photo_url?: string;
effectiveness_percentile?: number;
aligned: number;
opposed: number;
total: number;
alignment_pct?: number;
}
export interface AlignmentData {
members: AlignmentScore[];
total_bills_with_stance: number;
total_bills_with_votes: number;
}
export interface BillDetail extends Bill {