Skip to content

Reports: prompt/topic performance still rank by the zero-diluted average score (shown with a % sign) #564

Closed

Description

@gkhngyk

Problem

#562 switched the All Prompts Visibility column to the prompt-level Visibility Rate because averaging visibility_score across all runs lets zero-visibility runs dilute heavily-mentioned prompts into misleading single digits. The Reports feature still uses the old formula in two sections — and renders the 0–100 score with a % sign, as if it were a percentage:

There is also an adjacent correctness bug in the same two functions: their prompt_results selects are un-paginated, so PostgREST silently caps them at 1000 rows (the #430/#464 defect family — the comment above getPromptVisibilitySummaries in tracking.ts documents this exact hazard). Busy brands get best/worst lists computed from a truncated window. getTopicPerformance spans two windows in one select, so it hits the cap even sooner.

Fix

  1. getPromptPerformance: also select citation_count; page the scan at 1000 rows/page (the paged-loop pattern already exists later in the same file for the citation-evidence scan); accumulate visibleRuns (rows with mention_count > 0 || citation_count > 0); add visibilityRate to ReportPromptPerf — Math.round((visibleRuns / runs) * 1000) / 10, the exact rounding used in getPromptVisibilitySummaries (fix(prompts): show prompt-level visibility rate instead of zero-diluted average score #562); rank best/worst by the rate (tie-break by mentions). Keep avgVisibility in the payload.
  2. getTopicPerformance: same — per-window visibleRuns, topic visibilityRate, and change becomes rate points vs the previous window. Page the scan here too. Keep avgVisibility.
  3. Rendering (detail page + PDF): show the rate with the % sign (it genuinely is a percentage now). Old stored reports must keep rendering: reports are immutable snapshots, so payloads generated before this change won't have visibilityRate — fall back to the existing avgVisibility cell (without adding a misleading %, e.g. render NN or NN/100 for legacy payloads). The competitor table on the detail page already does exactly this dance for its own rate switch (hasCompetitorVisibilityRate ? c.visibilityRate : c.avgVisibilityScore) — mirror it.
  4. No migration needed — reports compute at creation time and store the payload.

Acceptance

  • A newly created report ranks best/worst prompts and topics by visibility rate and labels the values as percentages.
  • Reports created before the change still render without errors, showing their stored score values.
  • A brand with more than 1000 results in the report window gets numbers computed from the full window, not a truncated page.
  • yarn lint, yarn typecheck, yarn format:check pass from web/.

Activity

  1. added
    bug
    good first issue
    on Jul 30, 2026
  2. arambu1a commented on Jul 30, 2026

    @arambu1a
    Contributor

    Hi @gkhngyk I'll work on this

  3. added a commit that references this issue on Jul 31, 2026
    5fd84ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions