fix(scraper): verify complete article evidence (#40)

This commit is contained in:
2026-11-24 19:24:29 +01:00
parent 70ffe41cfb
commit a55dc2e189
27 changed files with 833 additions and 132 deletions

View File

@ -27,6 +27,7 @@ export interface PromptBudgetUsage {
export interface SourceGenerationStat extends ContentCompleteness {
source_id: string
source_key?: string | null
source_type: string
status: string
candidates: number

View File

@ -1,11 +1,30 @@
import type { GenerationOutcome } from '@/api/summaries'
import type { GenerationOutcome, SourceGenerationStat } from '@/api/summaries'
function sourceLabel(type: string) {
return type === 'cnbc_business' ? 'CNBC Business' : type
function sourceLabel(key?: string | null) {
switch (key) {
case 'yahoo_finance': return 'Yahoo Finance'
case 'bloomberg': return 'Bloomberg'
case 'cnbc_business': return 'CNBC Business'
default: return 'Source non identifiée'
}
}
function sourceState(source: SourceGenerationStat, mode: GenerationOutcome['ranking_mode']) {
if (source.status === 'failed') return 'Récupération impossible'
if (source.status !== 'ok') return 'État de collecte non renseigné'
if (mode === 'title') return 'Source joignable · contenu non évalué'
const counts = [source.content_complete, source.content_incomplete, source.content_unavailable]
if (counts.some(count => count === undefined)) return 'Source joignable · complétude non renseignée'
if (source.candidates === 0) return 'Source joignable · aucun article examiné'
if (counts.filter(count => (count ?? 0) > 0).length > 1) return 'Source joignable · contenus de complétude variable'
if ((source.content_complete ?? 0) > 0) return 'Source joignable · contenus complets'
if ((source.content_incomplete ?? 0) > 0) return 'Source joignable · contenu partiel'
if ((source.content_unavailable ?? 0) > 0) return 'Source joignable · contenu absent'
return 'Source joignable · complétude non renseignée'
}
export function GenerationDetails({ outcome }: { outcome: GenerationOutcome }) {
const unavailable = outcome.source_stats.filter(source => source.status === 'failed').map(source => sourceLabel(source.source_type))
const unavailable = outcome.source_stats.filter(source => source.status === 'failed').map(source => sourceLabel(source.source_key))
const hasCompleteness = outcome.content_complete !== undefined && outcome.content_incomplete !== undefined && outcome.content_unavailable !== undefined
const usage = outcome.prompt_budget
const number = (value: number) => value.toLocaleString('fr-FR')
@ -42,14 +61,16 @@ export function GenerationDetails({ outcome }: { outcome: GenerationOutcome }) {
<p>{outcome.ranking_mode === 'title_content' ? 'Classement effectué à partir des titres et du contenu disponible.' : 'Classement effectué à partir des titres uniquement.'}</p>
<p>Plafond global : {outcome.global_limit} articles par génération</p>
{!hasCompleteness && outcome.content_fallbacks > 0 && <p>Pour {outcome.content_fallbacks} articles examinés, le contenu était indisponible. Laya a utilisé leur titre uniquement.</p>}
<p>Une réponse HTTP 200 ne garantit pas que le texte intégral d’un article soit accessible. L’état de collecte et la complétude des contenus sont distincts.</p>
{outcome.ranking_mode === 'title_content' && outcome.source_stats.some(source => (source.content_incomplete ?? 0) > 0 || (source.content_unavailable ?? 0) > 0) && <p>Le texte intégral n’a pas pu être récupéré pour certains articles. Le bilan ne permet pas d’en confirmer la cause.</p>}
<div className="overflow-x-auto">
<table className="w-full text-sm text-left">
<caption className="text-left font-medium">Bilan par source</caption>
<thead><tr><th scope="col">Source</th><th scope="col">État</th><th scope="col">Examinés</th><th scope="col">Sélectionnés par Laya</th><th scope="col">Retenus</th><th scope="col">Plafond</th><th scope="col">Dates disponibles</th>{outcome.ranking_mode === 'title_content' && <><th scope="col">Contenus complets</th><th scope="col">Contenus partiels</th><th scope="col">Contenus absents</th></>}</tr></thead>
<thead><tr><th scope="col">Source</th><th scope="col">Collecte et complétude</th><th scope="col">Articles examinés</th><th scope="col">Sélectionnés par Laya</th><th scope="col">Retenus</th><th scope="col">Plafond</th><th scope="col">Dates disponibles</th>{outcome.ranking_mode === 'title_content' && <><th scope="col">Contenus complets</th><th scope="col">Contenus partiels</th><th scope="col">Contenus absents</th></>}</tr></thead>
<tbody>{outcome.source_stats.map(source => (
<tr key={source.source_id}>
<th scope="row">{sourceLabel(source.source_type)}</th>
<td>{source.status === 'failed' ? 'Indisponible' : 'Disponible'}</td>
<th scope="row">{sourceLabel(source.source_key)}</th>
<td>{sourceState(source, outcome.ranking_mode)}</td>
<td>{source.candidates}</td><td>{source.laya_selected}</td><td>{source.selected}</td><td>{source.article_limit}</td><td>{source.dates_available ?? 'Non renseigné'}</td>
{outcome.ranking_mode === 'title_content' && <><td>{source.content_complete ?? 'Non renseigné'}</td><td>{source.content_incomplete ?? 'Non renseigné'}</td><td>{source.content_unavailable ?? 'Non renseigné'}</td></>}
</tr>