Backup #1425
| ID | 1425 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Infrastructure/Docs/ChunkAnalysisService.php |
| Version | 15 |
| Typ |
modified |
| Größe | 4.5 KB |
| Hash | c0783cef177c11620a5513c7a8b9d18b1f72f6d19335074b0ca2889e14aea499 |
| Datum | 2025-12-25 16:59:21 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Infrastructure\Docs;
// @responsibility: Orchestriert Chunk-Analyse (koordiniert ChunkAnalyzer + ChunkRepository)
use RuntimeException;
final class ChunkAnalysisService implements ChunkProcessorInterface
{
private const string TAXONOMY_MODEL = 'gemma3:4b-it-qat';
private const int BATCH_SIZE = 10;
public function __construct(
private ChunkRepository $repository,
private ChunkAnalyzer $analyzer
) {
}
/**
* Analyzes a single chunk.
*
* @return array{taxonomy: array<string>, entities: array<array{name: string, type: string}>, keywords: array<string>}
*/
public function analyzeChunk(int $chunkId): array
{
return $this->process($chunkId);
}
/**
* Processes a single chunk (implements ChunkProcessorInterface).
*
* @return array{taxonomy: array<string>, entities: array<array{name: string, type: string}>, keywords: array<string>}
*/
public function process(int $chunkId): array
{
$chunk = $this->repository->findById($chunkId);
if ($chunk === null) {
throw new RuntimeException("Chunk #{$chunkId} not found");
}
// Mark as processing
$this->repository->updateStatus($chunkId, 'processing');
try {
// Get document context
$docContext = $this->repository->getDocumentContext((int) $chunk['dokumentation_id']);
// Perform analysis via ChunkAnalyzer
$analysis = $this->analyzer->analyze($chunk, $docContext);
// Store results
$this->repository->storeAnalysisResults($chunkId, $analysis, self::TAXONOMY_MODEL);
return $analysis;
} catch (RuntimeException $e) {
$this->repository->updateStatus($chunkId, 'failed', $e->getMessage());
throw $e;
}
}
/**
* Analyzes all pending chunks in batches.
*
* @return array{analyzed: int, failed: int, errors: array<string>}
*/
public function analyzeAllPending(int $limit = 100): array
{
return $this->processBatch($limit);
}
/**
* Processes multiple chunks in batch (implements ChunkProcessorInterface).
*
* @return array{processed: int, failed: int, errors: array<string>}
*/
public function processBatch(int $limit): array
{
$results = ['processed' => 0, 'failed' => 0, 'errors' => []];
$chunks = $this->repository->findPending($limit);
foreach ($chunks as $chunk) {
try {
$this->process((int) $chunk['id']);
$results['processed']++;
// Progress output
if ($results['processed'] % self::BATCH_SIZE === 0) {
echo "Analyzed {$results['processed']} chunks...\n";
}
} catch (RuntimeException $e) {
$results['failed']++;
$results['errors'][] = "Chunk #{$chunk['id']}: " . $e->getMessage();
}
}
// Return with legacy key 'analyzed' for backward compatibility
$results['analyzed'] = $results['processed'];
return $results;
}
/**
* Gets analysis statistics.
*
* @return array{pending: int, processing: int, completed: int, failed: int, by_category: array<array{category: string, count: int}>}
*/
public function getStats(): array
{
$stmt = $this->pdo->query("
SELECT
SUM(CASE WHEN analysis_status = 'pending' THEN 1 ELSE 0 END) as pending,
SUM(CASE WHEN analysis_status = 'processing' THEN 1 ELSE 0 END) as processing,
SUM(CASE WHEN analysis_status = 'completed' THEN 1 ELSE 0 END) as completed,
SUM(CASE WHEN analysis_status = 'failed' THEN 1 ELSE 0 END) as failed
FROM dokumentation_chunks
");
$counts = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $this->pdo->query('
SELECT taxonomy_category as category, COUNT(*) as count
FROM dokumentation_chunks
WHERE taxonomy_category IS NOT NULL
GROUP BY taxonomy_category
ORDER BY count DESC
');
$byCategory = $stmt->fetchAll(PDO::FETCH_ASSOC);
return [
'pending' => (int) ($counts['pending'] ?? 0),
'processing' => (int) ($counts['processing'] ?? 0),
'completed' => (int) ($counts['completed'] ?? 0),
'failed' => (int) ($counts['failed'] ?? 0),
'by_category' => $byCategory,
];
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1864 |
19 |
modified |
3.5 KB |
2025-12-27 23:48 |
| 1860 |
18 |
modified |
3.5 KB |
2025-12-27 23:47 |
| 1492 |
17 |
modified |
3.5 KB |
2025-12-25 17:28 |
| 1441 |
16 |
modified |
3.5 KB |
2025-12-25 17:00 |
| 1425 |
15 |
modified |
4.5 KB |
2025-12-25 16:59 |
| 1419 |
14 |
modified |
13.2 KB |
2025-12-25 16:59 |
| 1406 |
13 |
modified |
12.8 KB |
2025-12-25 16:58 |
| 1399 |
12 |
modified |
12.4 KB |
2025-12-25 16:58 |
| 1395 |
11 |
modified |
12.5 KB |
2025-12-25 16:58 |
| 856 |
10 |
modified |
12.6 KB |
2025-12-23 08:46 |
| 855 |
9 |
modified |
12.7 KB |
2025-12-23 08:46 |
| 786 |
8 |
modified |
12.9 KB |
2025-12-23 08:05 |
| 398 |
7 |
modified |
12.9 KB |
2025-12-22 08:49 |
| 397 |
6 |
modified |
13.0 KB |
2025-12-22 08:49 |
| 328 |
5 |
modified |
13.0 KB |
2025-12-22 08:08 |
| 327 |
4 |
modified |
12.9 KB |
2025-12-22 08:08 |
| 326 |
3 |
modified |
12.9 KB |
2025-12-22 08:08 |
| 36 |
2 |
modified |
13.7 KB |
2025-12-20 17:23 |
| 27 |
1 |
modified |
13.7 KB |
2025-12-20 17:18 |
← Zurück zur Übersicht