PageSourceSearch

https://radreport.com.br/assets/AdminCBRAuditPage-ChBk5QWl.js

js radreport.com.br collected 2026-09-24 14:36:29 UTC 8,638 bytes, 1 lines download raw bytes

1import{u as p,j as e}from"./vendor-query-skQMsM6X.js";import{at as f,p as N,ab as i,b as g,aJ as y}from"./index-BGwtrXIa.js";import{L as w}from"./vendor-react-DyYvSSk1.js";import{aq as k,aR as R,b as C,cn as B,bH as P}from"./vendor-ui-CCmu0bzQ.js";import"./vendor-supabase-BfoV2C50.js";const d=t=>t==null?"—":t.toLocaleString("pt-BR"),l=({label:t,value:c,hint:r,tone:n="default"})=>{const o=n==="warn"?"border-amber-500/40 bg-amber-500/5":n==="danger"?"border-destructive/40 bg-destructive/5":n==="ok"?"border-emerald-500/40 bg-emerald-500/5":"border-border/60";return e.jsxs("div",{className:`rounded-lg border p-3 ${o}`,children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("p",{className:"text-xl font-semibold tabular-nums mt-1",children:c}),r&&e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:r})]})},S=()=>{const{data:t,isLoading:c,isFetching:r,refetch:n,error:o}=p({queryKey:["admin-ranking-health"],queryFn:async()=>{const{data:v,error:b}=await g.rpc("get_ranking_health");if(b)throw b;return v},staleTime:6e4}),s=(t==null?void 0:t.attempts_last_7d)??0,a=(t==null?void 0:t.session_logs_last_7d)??0,j=(t==null?void 0:t.step_logs_last_7d)??0,u=(t==null?void 0:t.accuracy_eligible_users)??0,h=Number((t==null?void 0:t.drift_pct)??0),m=s>0&&a===0,_=s>0&&j===0,x=h>5;return e.jsxs(f,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{className:"h-5 w-5 text-emerald-500"}),e.jsx("h2",{className:"font-semibold",children:"Saúde do Ranking — últimos 7 dias"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(t==null?void 0:t.as_of_date)&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Atualizado em"," ",new Date(t.as_of_date).toLocaleDateString("pt-BR")]}),e.jsxs(N,{size:"sm",variant:"outline",onClick:()=>n(),disabled:r,children:[e.jsx(R,{className:`h-3.5 w-3.5 mr-1 ${r?"animate-spin":""}`}),"Recarregar"]})]})]}),o&&e.jsxs("p",{className:"text-sm text-destructive mb-3",children:["Erro ao carregar: ",o.message]}),c?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregando…"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(l,{label:"Tentativas (7d)",value:d(s)}),e.jsx(l,{label:"Usuários distintos",value:d(t==null?void 0:t.distinct_users_last_7d)}),e.jsx(l,{label:"Session logs",value:d(a),tone:m?"warn":"default",hint:m?"FE não está persistindo":void 0}),e.jsx(l,{label:"Step logs",value:d(j),tone:_?"warn":"default",hint:_?"FE não está persistindo":void 0}),e.jsx(l,{label:"Elegíveis Precisão (≥10)",value:d(u),tone:u===0?"default":"ok",hint:u===0?"Ninguém atingiu 10 questões ainda":void 0}),e.jsx(l,{label:"XP via tentativas",value:d(t==null?void 0:t.xp_earned_last_7d_via_attempts)}),e.jsx(l,{label:"XP via liga",value:d(t==null?void 0:t.xp_earned_last_7d_via_league)}),e.jsx(l,{label:"Drift XP",value:`${h.toLocaleString("pt-BR",{maximumFractionDigits:1})}%`,tone:x?"danger":h===0?"ok":"default",hint:x?"Acima de 5% — investigar":void 0})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-4",children:[m&&e.jsx(i,{variant:"outline",className:"border-amber-500/60 text-amber-600",children:"⚠ Sessões não estão sendo salvas"}),x&&e.jsx(i,{variant:"destructive",children:"⚠ Drift de XP alto"}),!m&&!x&&s>0&&e.jsx(i,{variant:"outline",className:"border-emerald-500/60 text-emerald-600",children:"✓ Pipeline saudável"}),s===0&&e.jsx(i,{variant:"outline",children:"Sem atividade nos últimos 7 dias"})]})]})]})};function D(){const{data:t=[],isLoading:c}=p({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["admin-cbr-drift"],queryFn:async()=>{const{data:s,error:a}=await g.from("v_cbr_drift_summary").select("*").order("xp_abs_drift",{ascending:!1}).limit(50);if(a)throw a;return s||[]}}),{data:r=[],isLoading:n}=p({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["admin-cbr-backfill"],queryFn:async()=>{const{data:s,error:a}=await g.from("cbr_backfill_audit").select("*").order("created_at",{ascending:!1}).limit(30);if(a)throw a;return s||[]}}),o=t.reduce((s,a)=>(s[a.drift_bucket]=(s[a.drift_bucket]||0)+1,s),{});return e.jsx(y,{children:e.jsxs("div",{className:"container mx-auto p-6 max-w-6xl space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(N,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(w,{to:"/admin",children:[e.jsx(C,{className:"h-4 w-4 mr-1"})," Admin"]})}),e.jsx("h1",{className:"text-2xl font-bold",children:"Auditoria CBR & Ranking"})]}),e.jsx(S,{}),e.jsxs(f,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(B,{className:"h-5 w-5 text-amber-500"}),e.jsx("h2",{className:"font-semibold",children:"Drift de XP (perfil vs. respostas CBR)"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Δ positivo = perfil tem XP além do CBR (ex.: ganhos antigos antes do CBR). Δ negativo = perfil está atrás dos attempts (bug a investigar)."}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[Object.entries(o).map(([s,a])=>e.jsxs(i,{variant:s==="ok"?"outline":"destructive",children:[s,": ",a]}
1,s)),t.length===0&&!c&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"Sem dados."})]}),c?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregando…"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-xs text-muted-foreground border-b border-border",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left py-2",children:"Usuário"}),e.jsx("th",{className:"text-right py-2",children:"Attempts"}),e.jsx("th",{className:"text-right py-2",children:"XP attempts"}),e.jsx("th",{className:"text-right py-2",children:"XP perfil"}),e.jsx("th",{className:"text-right py-2",children:"Δ (perfil − attempts)"}),e.jsx("th",{className:"text-right py-2",children:"|Δ|"}),e.jsx("th",{className:"text-left py-2 pl-3",children:"Bucket"})]})}),e.jsx("tbody",{children:t.slice(0,30).map(s=>e.jsxs("tr",{className:"border-b border-border/60",children:[e.jsx("td",{className:"py-2",children:s.full_name||s.user_id.slice(0,8)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:s.total_attempts??0}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:s.attempts_xp_sum??0}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:s.progress_total_xp??0}),e.jsx("td",{className:"py-2 text-right tabular-nums font-semibold",children:s.xp_outside_cbr??0}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:s.xp_abs_drift??0}),e.jsx("td",{className:"py-2 pl-3",children:e.jsx(i,{variant:s.drift_bucket==="ok"?"outline":"destructive",children:s.drift_bucket})})]},s.user_id))})]})})]}),e.jsxs(f,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(P,{className:"h-5 w-5 text-blue-500"}),e.jsx("h2",{className:"font-semibold",children:"Histórico de backfills (últimos 30)"})]}),n?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregando…"}):r.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sem entradas."}):e.jsx("ol",{className:"space-y-2",children:r.map(s=>e.jsxs("li",{className:"rounded-lg border border-border/60 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:new Date(s.created_at).toLocaleString("pt-BR",{timeZone:"America/Sao_Paulo"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{variant:"outline",children:s.reason||"—"}),s.source_table&&e.jsx(i,{variant:"secondary",children:s.source_table})]})]}),s.user_id&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["user: ",s.user_id.slice(0,8)]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-xs mt-2",children:[s.attempts_inserted!==null&&e.jsxs("span",{children:["attempts: ",e.jsx("strong",{children:s.attempts_inserted})]}),s.xp_before!==null&&s.xp_after!==null&&e.jsxs("span",{children:["XP: ",e.jsxs("strong",{children:[s.xp_before," → ",s.xp_after]})]}),s.weekly_xp_before!==null&&s.weekly_xp_after!==null&&e.jsxs("span",{children:["Liga: ",e.jsxs("strong",{children:[s.weekly_xp_before," → ",s.weekly_xp_after]})]})]}),s.notes&&e.jsx("p",{className:"text-xs mt-2 text-muted-foreground",children:s.notes})]},s.id))})]})]})})}export{D as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.