Files
CollabTable/shared/media-webui/src/lib/components/AnalyzerPipelineBreakdown.svelte
T

85 lines
3.8 KiB
Svelte

<script lang="ts">
import { Card, SectionTitle } from '@gabriel20xx/web-ui'
type Json = Record<string, unknown>
const mediaTypes = [
{ key: 'image', label: 'Images' },
{ key: 'video', label: 'Videos' },
{ key: 'audio', label: 'Audios' },
{ key: 'funscript', label: 'Funscripts' },
]
// 'convert' is left out - that stage was retired along with the Convert tab, and the
// backend's breakdown map still carries it (always zero) only for backward compatibility.
// 'discover' is left out too - it's not a per-file processing stage, just the media count
// itself, which is already shown via total() in the card header.
const processStages = [
{ key: 'extract', label: 'Metadata' },
{ key: 'generate', label: 'Thumbnails' },
{ key: 'analyze', label: 'AI analysis' },
]
let { pipeline = {} }: { pipeline?: Json } = $props()
// Thumbnails only ever run for images and videos, and AI analysis has no stages at all for
// funscript - skip those rows rather than showing counts that can only ever read zero.
function stagesFor(mediaTypeKey: string) {
return processStages.filter((stage) => {
if (stage.key === 'generate') return mediaTypeKey === 'image' || mediaTypeKey === 'video'
if (stage.key === 'analyze') return mediaTypeKey !== 'funscript'
return true
})
}
function count(stage: string, mediaType: string, status: string) {
const stageData = pipeline[stage]
if (!stageData || typeof stageData !== 'object' || Array.isArray(stageData)) return 0
const mediaData = (stageData as Json)[mediaType]
if (!mediaData || typeof mediaData !== 'object' || Array.isArray(mediaData)) return 0
const value = Number((mediaData as Json)[status] ?? 0)
return Number.isFinite(value) ? value : 0
}
// The "discover" stage's "completed" bucket is a straight count of active media rows of that type
// (funscripts counted via has_funscript rather than their own media_type) - already exactly the
// per-type total, so there's no need for a separate stats prop just to show it in the header.
function total(mediaTypeKey: string) {
return count('discover', mediaTypeKey, 'completed')
}
</script>
<Card class="space-y-4">
<SectionTitle
title="Pipeline breakdown"
description="Pending, completed, and error counts for every media type and processing stage."
/>
<div class="grid gap-4 md:grid-cols-2">
{#each mediaTypes as mediaType (mediaType.key)}
<div class="overflow-hidden rounded-md border border-border">
<div class="flex items-center justify-between border-b border-border bg-bg px-4 py-3">
<h3 class="text-sm font-semibold text-fg">{mediaType.label}</h3>
<span class="text-xs text-muted-fg">{total(mediaType.key).toLocaleString()} total</span>
</div>
<div class="grid grid-cols-[minmax(0,1fr)_4.5rem_4.5rem_4.5rem] items-center gap-x-2 px-4 py-2 text-xs">
<span class="text-muted-fg">Process stage</span>
<span class="text-right text-warning">Pending</span>
<span class="text-right text-success">Done</span>
<span class="text-right text-danger">Errors</span>
{#each stagesFor(mediaType.key) as stage (stage.key)}
<span class="border-t border-border py-2 text-sm text-fg">{stage.label}</span>
<span class="border-t border-border py-2 text-right text-sm text-warning"
>{count(stage.key, mediaType.key, 'queued')}</span
>
<span class="border-t border-border py-2 text-right text-sm text-success"
>{count(stage.key, mediaType.key, 'completed')}</span
>
<span class="border-t border-border py-2 text-right text-sm text-danger"
>{count(stage.key, mediaType.key, 'errors')}</span
>
{/each}
</div>
</div>
{/each}
</div>
</Card>