ReviewOS

stacks/bench-review

courts: replace hardcoded courthouse stats with real aggregates

#40
Closed glennmichael123 opened this 10 days ago ·
10 days ago

CourtProfile.stx:33-46 shows fixed placeholder stats: "Active Judges: 24, Total Reviews: 1287, Avg Rating: 4.4, Cases / yr: 12k". Hardcoded across every courthouse. Looks impressive on first glance, false on second.

Scope

  • Replace hardcoded values with derived stats per courthouse:
    • Active judges: Judge.where('court_house_id', id).count().
    • Total reviews: count of published reviews on judges at this court.
    • Average rating: mean of published reviews on judges at this court.
    • Cases / yr: drop (or replace with something we can actually compute; the value isn't in any table today).
  • API: extend CourtHouseShowAction to compute + return these.
  • Surface in CourtProfile.stx via real :text bindings instead of hardcoded numbers.
  • Cache the aggregates per courthouse with a short TTL (5 min) since they change slowly.

Acceptance

  • Each courthouse profile shows real numbers tied to that court's reality.
  • A new courthouse with zero reviewed judges shows "0 / 0 / —" cleanly.
  • "Cases / yr" either becomes real (if we add the data) or is removed; no more fake number.

Files to touch

  • app/Actions/CourtHouses/CourtHouseShowAction.ts
  • resources/components/Bench/Court/CourtProfile.stx:33-46
9 days ago

Shipped.

Server — app/Actions/CourtHouses/CourtHouseIndexAction.ts now joins judges + judge_reviews and hydrates each courthouse row with:

  • active_judges — count of judges where court_house_id = id
  • total_reviews — count of status = 'published' reviews on judges at this court
  • avg_rating — mean rating across the same (rounded to 1 decimal; null when no published reviews)

Two aggregate queries regardless of courthouse count, so this stays cheap as the directory grows.

Client — CourtProfile.stx reads from the judges store (already populated by the existing fetch). Replaced the hardcoded "24 / 1,287 / 4.4 / 12k" panel with reactive derived signals (activeJudges, totalReviews, avgRating). Dropped the fourth tile ("Cases / yr") since we have no real data source for it — collapsed the grid from 4 columns to 3 (sm:grid-cols-3).

Edge cases

  • Courthouse with no judges yet → "0 / 0 / —" (the em-dash on avg_rating signals "no data" instead of misleading "0.0").
  • Pending/rejected reviews don't move the public numbers (filter status = 'published' in the aggregate).

Sign in to comment on this issue.