← Back to Pull requests

fix: talk ratio do card executivo usa transcricao real, nao 50% fixo #164

Open
unknown opened this pull request with 262 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 22, 2026 19:39 UTC
Author

Causa

src/components/executive/ConversationIntelligenceCard.tsx:55:

const avgTalkRatio = 50; // placeholder: precisaria de tabela talk_ratios; mostra benchmark

Um número fixo exibido como "Talk Ratio Médio" no card executivo. Todo cliente, todo período, sempre 50%. O comentário admitia o placeholder.

A tabela nunca foi necessária

call_sessions.duration_seconds          -- duração da chamada
call_transcriptions (speaker, start_time, end_time)  -- quem falou, quando

E já existia src/lib/talkRatio.ts com computeTalkRatio() — helper puro extraído da edge analyze-talk-ratio, com teste, mas zero importadores em produção. A edge analyze-talk-ratio calculava o ratio em toda chamada e devolvia só no response (nunca persistia).

Correção

O card passa a:

1. buscar call_sessions dos últimos 7 dias com duration_seconds;
2. buscar as call_transcriptions dessas chamadas (speaker, start_time, end_time);
3. agrupar por call_session_id e rodar computeTalkRatio(segs, duration);
4. exibir a média real e a amostra: Benchmark: 40-60% · N chamada(s).

Sem transcrição no período: mostra — e Sem transcrição no período, em vez de inventar 50%.

Nenhuma migration, nenhum DDL — só leitura do que já existe.

Verificado

  • npx tsc --noEmit -p tsconfig.json → exit 0

  • npx eslint src/components/executive/ConversationIntelligenceCard.tsx → exit 0

  • npx vitest run src/components/executive/__tests__/ConversationIntelligenceCard.test.tsx → 2/2 passando

  • - caso com 40s de fala do agente em 100s → renderiza 40%, e falha se aparecer o antigo 50%
    - caso sem transcrição → renderiza — + "Sem transcrição no período"

    <!-- devin-review-badge-begin -->

    ---

    <a href="https://app.devin.ai/review/adm01-debug/hello_v3/pull/164" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    Diff: 262 lines (+196 / -66) across 3 files Reviewer: devin-ai-integration[bot] Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.39) × (1 − Review Confidence (0.39)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 262 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 70% · Reviewer familiarity: 35%
    39%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.333
    Real PR Conversation Timeline
    1 comments
    "Review active on #164"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 39.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.3% (MEDIUM) · Higher = larger blast radius
    39.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 39.4% · Lower = rushed or shallow review
    39.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.8% · Safe to merge
    23.8%