Protokoll #24441

ID24441
Zeitstempel2025-12-27 23:15:26.642286
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,617 (Input: 94, Output: 1,523)
Dauer133 ms
Request-Zeit2025-12-27 23:15:26.642286
Response-Zeit2025-12-27 23:15:26.775408

Request

{
    "event": "PreToolUse",
    "tool_name": "Edit",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Taxonomy\/GetTaxonomyOverviewUseCase.php",
        "old_string": "$percentage = $total > 0 ? round(($mappedChunks \/ $total) * 100, 2) : 100.0;",
        "new_string": "$percentage = $total > 0 ? round(($mappedChunks \/ $total) * Constants::PERCENT_FULL, 2) : 100.0;"
    }
}

Response

{
    "tool_response": {
        "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Taxonomy\/GetTaxonomyOverviewUseCase.php",
        "oldString": "$percentage = $total > 0 ? round(($mappedChunks \/ $total) * 100, 2) : 100.0;",
        "newString": "$percentage = $total > 0 ? round(($mappedChunks \/ $total) * Constants::PERCENT_FULL, 2) : 100.0;",
        "originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Taxonomie-Übersicht mit aggregierten Statistiken\n\nuse Domain\\Constants;\nuse Domain\\Repository\\ChunkTaxonomyRepositoryInterface;\nuse Domain\\Repository\\EntityTaxonomyRepositoryInterface;\nuse Domain\\Repository\\TaxonomyRepositoryInterface;\n\nfinal class GetTaxonomyOverviewUseCase\n{\n    public function __construct(\n        private ChunkTaxonomyRepositoryInterface $chunkTaxonomyRepository,\n        private EntityTaxonomyRepositoryInterface $entityTaxonomyRepository,\n        private TaxonomyRepositoryInterface $taxonomyRepository\n    ) {\n    }\n\n    \/**\n     * Get complete taxonomy overview with statistics.\n     *\n     * @return array{\n     *     taxonomy_stats: array{total_terms: int, root_terms: int, max_depth: int, tagged_chunks: int},\n     *     chunk_coverage: array{total: int, mapped: int, percentage: float},\n     *     entity_validation: array{total: int, validated: int, pending: int},\n     *     term_usage: array<int, int>\n     * }\n     *\/\n    public function execute(): array\n    {\n        $taxonomyStats = $this->taxonomyRepository->getStats();\n        $chunkCoverage = $this->calculateChunkCoverage();\n        $entityValidation = $this->entityTaxonomyRepository->getValidationStats();\n        $termUsage = $this->chunkTaxonomyRepository->countByTaxonomyTerm();\n\n        return [\n            'taxonomy_stats' => $taxonomyStats,\n            'chunk_coverage' => $chunkCoverage,\n            'entity_validation' => $entityValidation,\n            'term_usage' => $termUsage,\n        ];\n    }\n\n    \/**\n     * Get chunks that have no taxonomy mapping.\n     *\n     * @return array<array{id: int, document_id: int, content: string}>\n     *\/\n    public function getUnmappedChunks(int $limit = Constants::DEFAULT_LIMIT): array\n    {\n        return $this->chunkTaxonomyRepository->getUnmappedChunks($limit);\n    }\n\n    \/**\n     * Get entity mappings that need validation.\n     *\n     * @return array<\\Domain\\Entity\\EntityTaxonomyMapping>\n     *\/\n    public function getUnvalidatedEntityMappings(int $limit = Constants::DEFAULT_LIMIT): array\n    {\n        return $this->entityTaxonomyRepository->getUnvalidatedMappings($limit);\n    }\n\n    \/**\n     * Get usage statistics for a specific taxonomy term.\n     *\n     * @return array{\n     *     term: array|null,\n     *     chunk_count: int,\n     *     entity_count: int,\n     *     chunks: array<array{chunk_id: int, confidence: float, source: string}>,\n     *     entities: array<array{entity_id: int, relevance: float, validated: bool}>\n     * }\n     *\/\n    public function getTaxonomyTermUsage(int $termId): array\n    {\n        $term = $this->taxonomyRepository->find($termId);\n        $chunks = $this->chunkTaxonomyRepository->findByTaxonomyTermId($termId);\n        $entities = $this->entityTaxonomyRepository->findByTaxonomyTermId($termId);\n\n        return [\n            'term' => $term,\n            'chunk_count' => count($chunks),\n            'entity_count' => count($entities),\n            'chunks' => $chunks,\n            'entities' => $entities,\n        ];\n    }\n\n    \/**\n     * Get all taxonomy terms with their usage counts.\n     *\n     * @return array<array{id: int, name: string, path: string, chunk_count: int, entity_count: int}>\n     *\/\n    public function getTermsWithUsage(): array\n    {\n        $terms = $this->taxonomyRepository->findAll();\n        $chunkCounts = $this->chunkTaxonomyRepository->countByTaxonomyTerm();\n\n        $result = [];\n        foreach ($terms as $term) {\n            $termId = $term['id'];\n            $entityMappings = $this->entityTaxonomyRepository->findByTaxonomyTermId($termId);\n\n            $result[] = [\n                'id' => $termId,\n                'name' => $term['name'],\n                'path' => $term['path'],\n                'chunk_count' => $chunkCounts[$termId] ?? 0,\n                'entity_count' => count($entityMappings),\n            ];\n        }\n\n        return $result;\n    }\n\n    \/**\n     * Calculate chunk coverage statistics.\n     *\n     * @return array{total: int, mapped: int, percentage: float}\n     *\/\n    private function calculateChunkCoverage(): array\n    {\n        $taxonomyStats = $this->taxonomyRepository->getStats();\n        $mappedChunks = $taxonomyStats['tagged_chunks'];\n\n        \/\/ Get total chunks from unmapped query (limit 0 would give us count)\n        \/\/ For efficiency, we estimate based on the stats\n        $unmappedSample = $this->chunkTaxonomyRepository->getUnmappedChunks(1);\n        $hasUnmapped = count($unmappedSample) > 0;\n\n        \/\/ Use a heuristic: if there are unmapped chunks, estimate total\n        \/\/ In production, this would be a dedicated count query\n        $total = $hasUnmapped ? max($mappedChunks + 1, $mappedChunks) : $mappedChunks;\n\n        $percentage = $total > 0 ? round(($mappedChunks \/ $total) * 100, 2) : 100.0;\n\n        return [\n            'total' => $total,\n            'mapped' => $mappedChunks,\n            'percentage' => $percentage,\n        ];\n    }\n}\n",
        "structuredPatch": [
            {
                "oldStart": 137,
                "oldLines": 7,
                "newStart": 137,
                "newLines": 7,
                "lines": [
                    "         \/\/ In production, this would be a dedicated count query",
                    "         $total = $hasUnmapped ? max($mappedChunks + 1, $mappedChunks) : $mappedChunks;",
                    " ",
                    "-        $percentage = $total > 0 ? round(($mappedChunks \/ $total) * 100, 2) : 100.0;",
                    "+        $percentage = $total > 0 ? round(($mappedChunks \/ $total) * Constants::PERCENT_FULL, 2) : 100.0;",
                    " ",
                    "         return [",
                    "             'total' => $total,"
                ]
            }
        ],
        "userModified": false,
        "replaceAll": false
    }
}
← Vorheriger Zur Liste Nächster →