feat(training): add Paraglide i18n to training UI components and wire SegmentationTrainingCard

- Convert TrainingHistory, OcrTrainingCard, SegmentationTrainingCard, and
  TranscriptionBlock "Nur Segmentierung" badge to use Paraglide message keys
- Add availableSegBlocks to TrainingInfoResponse to expose segmentation
  block count in the training info endpoint
- Wire SegmentationTrainingCard into admin/system page below OCR training card
- Update api.ts with availableSegBlocks field

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-13 15:14:27 +02:00
parent 4e08d31e01
commit 86e9c05aaf
9 changed files with 144 additions and 25 deletions

View File

@@ -27,6 +27,7 @@ public class OcrTrainingService {
private final OcrTrainingRunRepository trainingRunRepository; private final OcrTrainingRunRepository trainingRunRepository;
private final TrainingDataExportService trainingDataExportService; private final TrainingDataExportService trainingDataExportService;
private final SegmentationTrainingExportService segmentationTrainingExportService;
private final OcrClient ocrClient; private final OcrClient ocrClient;
private final OcrHealthClient ocrHealthClient; private final OcrHealthClient ocrHealthClient;
private final TranscriptionBlockRepository blockRepository; private final TranscriptionBlockRepository blockRepository;
@@ -35,6 +36,7 @@ public class OcrTrainingService {
int availableBlocks, int availableBlocks,
int totalOcrBlocks, int totalOcrBlocks,
int availableDocuments, int availableDocuments,
int availableSegBlocks,
boolean ocrServiceAvailable, boolean ocrServiceAvailable,
OcrTrainingRun lastRun, OcrTrainingRun lastRun,
List<OcrTrainingRun> runs List<OcrTrainingRun> runs
@@ -105,6 +107,7 @@ public class OcrTrainingService {
.count(); .count();
int totalOcrBlocks = blockRepository.findAll().size(); int totalOcrBlocks = blockRepository.findAll().size();
int availableSegBlocks = segmentationTrainingExportService.querySegmentationBlocks().size();
List<OcrTrainingRun> recentRuns = trainingRunRepository.findTop5ByOrderByCreatedAtDesc(); List<OcrTrainingRun> recentRuns = trainingRunRepository.findTop5ByOrderByCreatedAtDesc();
OcrTrainingRun lastRun = recentRuns.isEmpty() ? null : recentRuns.get(0); OcrTrainingRun lastRun = recentRuns.isEmpty() ? null : recentRuns.get(0);
@@ -113,6 +116,7 @@ public class OcrTrainingService {
eligibleBlocks.size(), eligibleBlocks.size(),
totalOcrBlocks, totalOcrBlocks,
availableDocuments, availableDocuments,
availableSegBlocks,
ocrHealthClient.isHealthy(), ocrHealthClient.isHealthy(),
lastRun, lastRun,
recentRuns recentRuns
@@ -139,6 +143,7 @@ public class OcrTrainingService {
"availableBlocks", info.availableBlocks(), "availableBlocks", info.availableBlocks(),
"totalOcrBlocks", info.totalOcrBlocks(), "totalOcrBlocks", info.totalOcrBlocks(),
"availableDocuments", info.availableDocuments(), "availableDocuments", info.availableDocuments(),
"availableSegBlocks", info.availableSegBlocks(),
"ocrServiceAvailable", info.ocrServiceAvailable(), "ocrServiceAvailable", info.ocrServiceAvailable(),
"lastRun", info.lastRun() != null ? info.lastRun() : Map.of(), "lastRun", info.lastRun() != null ? info.lastRun() : Map.of(),
"runs", info.runs() "runs", info.runs()

View File

@@ -44,6 +44,7 @@ class OcrControllerTest {
@MockitoBean UserService userService; @MockitoBean UserService userService;
@MockitoBean CustomUserDetailsService customUserDetailsService; @MockitoBean CustomUserDetailsService customUserDetailsService;
@MockitoBean TrainingDataExportService trainingDataExportService; @MockitoBean TrainingDataExportService trainingDataExportService;
@MockitoBean SegmentationTrainingExportService segmentationTrainingExportService;
@MockitoBean OcrTrainingService ocrTrainingService; @MockitoBean OcrTrainingService ocrTrainingService;
@Test @Test
@@ -217,7 +218,7 @@ class OcrControllerTest {
@WithMockUser(authorities = "ADMIN") @WithMockUser(authorities = "ADMIN")
void getTrainingInfo_returns200_withInfo() throws Exception { void getTrainingInfo_returns200_withInfo() throws Exception {
OcrTrainingService.TrainingInfoResponse info = OcrTrainingService.TrainingInfoResponse info =
new OcrTrainingService.TrainingInfoResponse(5, 20, 2, true, null, List.of()); new OcrTrainingService.TrainingInfoResponse(5, 20, 2, 3, true, null, List.of());
when(ocrTrainingService.getTrainingInfo()).thenReturn(info); when(ocrTrainingService.getTrainingInfo()).thenReturn(info);
mockMvc.perform(get("/api/ocr/training-info")) mockMvc.perform(get("/api/ocr/training-info"))

View File

@@ -25,6 +25,7 @@ class OcrTrainingServiceTest {
OcrTrainingRunRepository runRepository; OcrTrainingRunRepository runRepository;
TrainingDataExportService exportService; TrainingDataExportService exportService;
SegmentationTrainingExportService segExportService;
OcrClient ocrClient; OcrClient ocrClient;
OcrHealthClient healthClient; OcrHealthClient healthClient;
TranscriptionBlockRepository blockRepository; TranscriptionBlockRepository blockRepository;
@@ -34,14 +35,16 @@ class OcrTrainingServiceTest {
void setUp() { void setUp() {
runRepository = mock(OcrTrainingRunRepository.class); runRepository = mock(OcrTrainingRunRepository.class);
exportService = mock(TrainingDataExportService.class); exportService = mock(TrainingDataExportService.class);
segExportService = mock(SegmentationTrainingExportService.class);
ocrClient = mock(OcrClient.class); ocrClient = mock(OcrClient.class);
healthClient = mock(OcrHealthClient.class); healthClient = mock(OcrHealthClient.class);
blockRepository = mock(TranscriptionBlockRepository.class); blockRepository = mock(TranscriptionBlockRepository.class);
service = new OcrTrainingService(runRepository, exportService, ocrClient, healthClient, blockRepository); service = new OcrTrainingService(runRepository, exportService, segExportService, ocrClient, healthClient, blockRepository);
when(blockRepository.findAll()).thenReturn(List.of()); when(blockRepository.findAll()).thenReturn(List.of());
when(runRepository.findTop5ByOrderByCreatedAtDesc()).thenReturn(List.of()); when(runRepository.findTop5ByOrderByCreatedAtDesc()).thenReturn(List.of());
when(segExportService.querySegmentationBlocks()).thenReturn(List.of());
} }
// ─── Concurrent guard ───────────────────────────────────────────────────── // ─── Concurrent guard ─────────────────────────────────────────────────────

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import TrainingHistory from './TrainingHistory.svelte'; import TrainingHistory from './TrainingHistory.svelte';
import { m } from '$lib/paraglide/messages.js';
interface Run { interface Run {
id: string; id: string;
@@ -42,7 +43,7 @@ async function startTraining() {
try { try {
const res = await fetch('/api/ocr/train', { method: 'POST' }); const res = await fetch('/api/ocr/train', { method: 'POST' });
if (res.ok) { if (res.ok) {
successMessage = 'Training wurde gestartet und abgeschlossen.'; successMessage = m.training_success();
setTimeout(() => { setTimeout(() => {
successMessage = null; successMessage = null;
}, 5000); }, 5000);
@@ -54,16 +55,14 @@ async function startTraining() {
</script> </script>
<div class="rounded-sm border border-line bg-surface p-6 shadow-sm"> <div class="rounded-sm border border-line bg-surface p-6 shadow-sm">
<h2 class="mb-1 font-sans text-sm font-bold text-ink">Kurrent-Erkennung trainieren</h2> <h2 class="mb-1 font-sans text-sm font-bold text-ink">{m.training_ocr_heading()}</h2>
<p class="mb-4 text-sm text-ink-2"> <p class="mb-4 text-sm text-ink-2">{m.training_ocr_description()}</p>
Starte ein neues Training mit den bisher geprüften OCR-Blöcken, um die Erkennungsgenauigkeit für
Kurrentschrift zu verbessern.
</p>
<p class="mb-3 text-sm text-ink"> <p class="mb-3 text-sm text-ink">
<strong>{available}</strong> geprüfte Blöcke bereit / {m.training_ocr_blocks_ready({ blocks: available, docs: trainingInfo?.availableDocuments ?? 0 })}
<strong>{trainingInfo?.availableDocuments ?? 0}</strong> Dokumente <span class="text-ink-2"
<span class="text-ink-2">(von {trainingInfo?.totalOcrBlocks ?? 0} OCR-Blöcken gesamt)</span> >{m.training_ocr_blocks_total({ total: trainingInfo?.totalOcrBlocks ?? 0 })}</span
>
</p> </p>
<button <button
@@ -71,21 +70,23 @@ async function startTraining() {
disabled={disabled} disabled={disabled}
class="rounded-sm bg-primary px-5 py-2 font-sans text-xs font-bold tracking-widest text-primary-fg uppercase transition-opacity hover:opacity-80 focus-visible:ring-2 focus-visible:ring-brand-navy disabled:cursor-not-allowed disabled:opacity-50" class="rounded-sm bg-primary px-5 py-2 font-sans text-xs font-bold tracking-widest text-primary-fg uppercase transition-opacity hover:opacity-80 focus-visible:ring-2 focus-visible:ring-brand-navy disabled:cursor-not-allowed disabled:opacity-50"
> >
{training ? '…' : 'Training starten'} {training ? '…' : m.training_start_btn()}
</button> </button>
{#if tooFewBlocks} {#if tooFewBlocks}
<p class="mt-2 text-xs text-ink-3"> <p class="mt-2 text-xs text-ink-3">
Mindestens 5 geprüfte Blöcke erforderlich (aktuell: {available}). {m.training_too_few_blocks({ available })}
</p> </p>
{:else if serviceDown} {:else if serviceDown}
<p class="mt-2 text-xs text-orange-600">OCR-Dienst ist nicht erreichbar.</p> <p class="mt-2 text-xs text-orange-600">{m.training_service_down()}</p>
{/if} {/if}
{#if successMessage} {#if successMessage}
<p class="mt-2 text-xs text-green-700">{successMessage}</p> <p class="mt-2 text-xs text-green-700">{successMessage}</p>
{/if} {/if}
<h3 class="mt-6 mb-3 text-xs font-bold tracking-widest text-ink-3 uppercase">Verlauf</h3> <h3 class="mt-6 mb-3 text-xs font-bold tracking-widest text-ink-3 uppercase">
{m.training_history_heading()}
</h3>
<TrainingHistory runs={trainingInfo?.runs ?? []} /> <TrainingHistory runs={trainingInfo?.runs ?? []} />
</div> </div>

View File

@@ -0,0 +1,86 @@
<script lang="ts">
import TrainingHistory from './TrainingHistory.svelte';
import { m } from '$lib/paraglide/messages.js';
interface Run {
id: string;
status: 'RUNNING' | 'DONE' | 'FAILED';
blockCount: number;
documentCount: number;
modelName: string;
errorMessage?: string;
triggeredBy?: string;
createdAt: string;
completedAt?: string;
}
interface TrainingInfo {
availableBlocks?: number;
ocrServiceAvailable?: boolean;
runs?: Run[];
}
interface Props {
trainingInfo: TrainingInfo | null;
}
let { trainingInfo }: Props = $props();
let training = $state(false);
let successMessage = $state<string | null>(null);
const available = $derived(trainingInfo?.availableBlocks ?? 0);
const tooFewBlocks = $derived(available < 5);
const serviceDown = $derived(trainingInfo?.ocrServiceAvailable === false);
const disabled = $derived(training || tooFewBlocks || serviceDown);
async function startTraining() {
training = true;
successMessage = null;
try {
const res = await fetch('/api/ocr/segtrain', { method: 'POST' });
if (res.ok) {
successMessage = m.training_success();
setTimeout(() => {
successMessage = null;
}, 5000);
}
} finally {
training = false;
}
}
</script>
<div class="rounded-sm border border-line bg-surface p-6 shadow-sm">
<h2 class="mb-1 font-sans text-sm font-bold text-ink">{m.training_seg_heading()}</h2>
<p class="mb-4 text-sm text-ink-2">{m.training_seg_description()}</p>
<p class="mb-3 text-sm text-ink">
{m.training_seg_blocks_ready({ blocks: available })}
</p>
<button
onclick={startTraining}
disabled={disabled}
class="rounded-sm bg-primary px-5 py-2 font-sans text-xs font-bold tracking-widest text-primary-fg uppercase transition-opacity hover:opacity-80 focus-visible:ring-2 focus-visible:ring-brand-navy disabled:cursor-not-allowed disabled:opacity-50"
>
{training ? '…' : m.training_start_btn()}
</button>
{#if tooFewBlocks}
<p class="mt-2 text-xs text-ink-3">
{m.training_seg_too_few_blocks({ available })}
</p>
{:else if serviceDown}
<p class="mt-2 text-xs text-orange-600">{m.training_service_down()}</p>
{/if}
{#if successMessage}
<p class="mt-2 text-xs text-green-700">{successMessage}</p>
{/if}
<h3 class="mt-6 mb-3 text-xs font-bold tracking-widest text-ink-3 uppercase">
{m.training_history_heading()}
</h3>
<TrainingHistory runs={(trainingInfo?.runs ?? []).filter((r) => r.modelName === 'blla')} />
</div>

View File

@@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import { m } from '$lib/paraglide/messages.js';
interface Run { interface Run {
id: string; id: string;
status: 'RUNNING' | 'DONE' | 'FAILED'; status: 'RUNNING' | 'DONE' | 'FAILED';
@@ -31,17 +33,17 @@ function formatDate(iso: string): string {
<table class="w-full text-sm"> <table class="w-full text-sm">
<thead> <thead>
<tr class="border-b border-line text-xs font-bold tracking-widest text-ink-3 uppercase"> <tr class="border-b border-line text-xs font-bold tracking-widest text-ink-3 uppercase">
<th class="pb-2 text-left">Datum</th> <th class="pb-2 text-left">{m.training_history_col_date()}</th>
<th class="pb-2 text-left">Status</th> <th class="pb-2 text-left">{m.training_history_col_status()}</th>
<th class="pb-2 text-right">Blöcke</th> <th class="pb-2 text-right">{m.training_history_col_blocks()}</th>
<th class="hidden pb-2 text-right md:table-cell">Dokumente</th> <th class="hidden pb-2 text-right md:table-cell">{m.training_history_col_docs()}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{#if runs.length === 0} {#if runs.length === 0}
<tr> <tr>
<td colspan="4" class="py-4 text-center text-sm text-ink-2"> <td colspan="4" class="py-4 text-center text-sm text-ink-2">
Noch keine Trainings-Läufe. {m.training_history_empty()}
</td> </td>
</tr> </tr>
{:else} {:else}
@@ -52,18 +54,18 @@ function formatDate(iso: string): string {
{#if run.status === 'DONE'} {#if run.status === 'DONE'}
<span <span
class="inline-flex items-center gap-1 rounded-sm bg-green-100 px-1.5 py-0.5 text-xs font-medium text-green-700" class="inline-flex items-center gap-1 rounded-sm bg-green-100 px-1.5 py-0.5 text-xs font-medium text-green-700"
>Fertig</span >{m.training_status_done()}</span
> >
{:else if run.status === 'FAILED'} {:else if run.status === 'FAILED'}
<span <span
class="inline-flex items-center gap-1 rounded-sm bg-red-100 px-1.5 py-0.5 text-xs font-medium text-red-700" class="inline-flex items-center gap-1 rounded-sm bg-red-100 px-1.5 py-0.5 text-xs font-medium text-red-700"
title={run.errorMessage}> Fehler</span title={run.errorMessage}> {m.training_status_failed()}</span
> >
{:else} {:else}
<span <span
class="inline-flex items-center gap-1 rounded-sm bg-yellow-100 px-1.5 py-0.5 text-xs font-medium text-yellow-700" class="inline-flex items-center gap-1 rounded-sm bg-yellow-100 px-1.5 py-0.5 text-xs font-medium text-yellow-700"
><span class="h-1.5 w-1.5 animate-pulse rounded-full bg-yellow-500" ><span class="h-1.5 w-1.5 animate-pulse rounded-full bg-yellow-500"
></span>Läuft…</span ></span>{m.training_status_running()}</span
> >
{/if} {/if}
</td> </td>

View File

@@ -27,6 +27,7 @@ type Props = {
onMoveDown?: () => void; onMoveDown?: () => void;
isFirst?: boolean; isFirst?: boolean;
isLast?: boolean; isLast?: boolean;
source?: 'MANUAL' | 'OCR';
}; };
let { let {
@@ -48,7 +49,8 @@ let {
onMoveUp, onMoveUp,
onMoveDown, onMoveDown,
isFirst = false, isFirst = false,
isLast = false isLast = false,
source = 'MANUAL'
}: Props = $props(); }: Props = $props();
let localText = $state(text); let localText = $state(text);
@@ -172,6 +174,11 @@ function handleTextareaMouseUp() {
{label} {label}
</span> </span>
{/if} {/if}
{#if (!text || text.trim() === '') && source === 'MANUAL'}
<span class="rounded bg-muted px-1.5 py-0.5 text-xs font-medium text-ink-3"
>{m.transcription_block_segmentation_only()}</span
>
{/if}
</div> </div>
<!-- Textarea --> <!-- Textarea -->

View File

@@ -1429,6 +1429,8 @@ export interface components {
totalOcrBlocks?: number; totalOcrBlocks?: number;
/** Format: int32 */ /** Format: int32 */
availableDocuments?: number; availableDocuments?: number;
/** Format: int32 */
availableSegBlocks?: number;
ocrServiceAvailable?: boolean; ocrServiceAvailable?: boolean;
lastRun?: components["schemas"]["OcrTrainingRun"]; lastRun?: components["schemas"]["OcrTrainingRun"];
runs?: components["schemas"]["OcrTrainingRun"][]; runs?: components["schemas"]["OcrTrainingRun"][];

View File

@@ -2,6 +2,7 @@
import { onDestroy } from 'svelte'; import { onDestroy } from 'svelte';
import { m } from '$lib/paraglide/messages.js'; import { m } from '$lib/paraglide/messages.js';
import OcrTrainingCard from '$lib/components/OcrTrainingCard.svelte'; import OcrTrainingCard from '$lib/components/OcrTrainingCard.svelte';
import SegmentationTrainingCard from '$lib/components/SegmentationTrainingCard.svelte';
import type { components } from '$lib/generated/api.js'; import type { components } from '$lib/generated/api.js';
type TrainingInfo = components['schemas']['TrainingInfoResponse']; type TrainingInfo = components['schemas']['TrainingInfoResponse'];
@@ -102,9 +103,20 @@ async function backfillFileHashes() {
<div class="flex-1 overflow-y-auto p-6"> <div class="flex-1 overflow-y-auto p-6">
<div class="mx-auto max-w-2xl space-y-5"> <div class="mx-auto max-w-2xl space-y-5">
<!-- OCR Training --> <!-- OCR Recognition Training -->
<OcrTrainingCard trainingInfo={trainingInfo} /> <OcrTrainingCard trainingInfo={trainingInfo} />
<!-- OCR Segmentation Training -->
<SegmentationTrainingCard
trainingInfo={trainingInfo
? {
availableBlocks: trainingInfo.availableSegBlocks,
ocrServiceAvailable: trainingInfo.ocrServiceAvailable,
runs: trainingInfo.runs
}
: null}
/>
<!-- Backfill versions --> <!-- Backfill versions -->
<div class="rounded-sm border border-line bg-surface p-6 shadow-sm"> <div class="rounded-sm border border-line bg-surface p-6 shadow-sm">
<h2 class="mb-1 font-sans text-sm font-bold text-ink">{m.admin_system_backfill_heading()}</h2> <h2 class="mb-1 font-sans text-sm font-bold text-ink">{m.admin_system_backfill_heading()}</h2>