import { Box, LinearProgress, Typography } from '@mui/material' import { dataQualityHex } from '../../lib/utils' import { FreshnessStatus } from '../../domain/enums' import type { Property } from '../../domain/property' interface Dimension { label: string score: number color: string } function freshnessScore(f: string): number { if (f === FreshnessStatus.FRESH) return 100 if (f === FreshnessStatus.STALE) return 50 return 15 } function completenessScore(missingCritical: number, missingOptional: number): number { const critPenalty = missingCritical * 15 const optPenalty = missingOptional * 5 return Math.max(0, 100 - critPenalty - optPenalty) } const SOURCE_PROVENANCE: Record = { ERP_IMPORT: 95, MANUAL_ENTRY: 90, PARTNER_FEED: 80, IMMOSCOUT_SCRAPE: 65, HOMEGATE_SCRAPE: 65, NEWHOME_SCRAPE: 60, MATCHOFFICE_SCRAPE: 60, MAISON_WORK_SCRAPE: 60, AI_SIGNAL: 40, UNKNOWN: 30, } function dimColor(score: number): string { if (score >= 80) return '#1a7a4a' if (score >= 55) return '#d97706' return '#c0392b' } function buildDimensions(p: Property): Dimension[] { const compScore = completenessScore( p.dataQuality.missingCriticalFields.length, p.dataQuality.missingOptionalFields.length, ) const freshScore = freshnessScore(p.dataQuality.freshness) const confScore = Math.round(p.confidenceScore * 100) const provScore = SOURCE_PROVENANCE[p.sourceType] ?? 50 const lastVerified = p.dataQuality.lastVerifiedAt const verScore = lastVerified ? Math.max(10, 100 - Math.floor((Date.now() - new Date(lastVerified).getTime()) / (1000 * 60 * 60 * 24)) * 2) : 10 return [ { label: 'Vollständigkeit', score: compScore, color: dimColor(compScore) }, { label: 'Aktualität', score: freshScore, color: dimColor(freshScore) }, { label: 'Vertrauensscore', score: confScore, color: dimColor(confScore) }, { label: 'Herkunft', score: Math.min(100, provScore), color: dimColor(provScore) }, { label: 'Verifikation', score: Math.min(100, verScore), color: dimColor(verScore) }, ] } interface DataQualityProgressProps { property: Property compact?: boolean } export function DataQualityProgress({ property, compact = false }: DataQualityProgressProps) { const dims = buildDimensions(property) const overallPct = Math.round(property.dataQuality.score * 100) const hex = dataQualityHex(property.dataQuality.score) if (compact) { return ( {dims.map(d => ( ))} ) } return ( {/* Overall score header */} {overallPct}% Gesamtqualität {/* Dimension bars */} {dims.map(d => ( {d.label} {d.score}% ))} ) }