Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJKMLHdxMwSUeYcdkwqX4W
50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
"""Сборщики ответов ИС для тестов нормализатора (набор json, задачи 3, 4 и 6)."""
|
||
|
||
from typing import Any
|
||
|
||
OK = {"code": "", "message": ""}
|
||
BAD = {"code": "INVALID_DOCUMENT", "message": "Не удалось определить тип документа."}
|
||
HEAD = {
|
||
"organization": {"form_name": "ООО «Пример»", "confidence": 100.0},
|
||
"inn": {"form_name": "7700000000", "confidence": 100.0},
|
||
"units": {"form_name": "тыс. руб.", "confidence": 100.0},
|
||
"date": {"form_name": "на 31 декабря 2024 г.", "confidence": 100.0},
|
||
}
|
||
BALANCE = [
|
||
("Наименование показателя", "Код", "На 31 декабря 2024 г."),
|
||
("Запасы", "1210", "60"),
|
||
("Дебиторы", "1230", "40"),
|
||
("Итого II", "1200", "100"),
|
||
("НМА", "1110", "50"),
|
||
("Итого I", "1100", "50"),
|
||
("БАЛАНС", "1600", "150"),
|
||
("Капитал", "1310", "150"),
|
||
("Итого III", "1300", "150"),
|
||
("БАЛАНС", "1700", "150"),
|
||
]
|
||
INCOME = [
|
||
("Наименование показателя", "Код", "За 2024 г."),
|
||
("Выручка", "2110", "100"),
|
||
("Себестоимость", "2120", "(60)"),
|
||
("Валовая прибыль", "2100", "40"),
|
||
("Прибыль от продаж", "2200", "40"),
|
||
]
|
||
|
||
|
||
def ocr_table(label: str, rows: list[tuple[str, ...]]) -> dict[str, Any]:
|
||
return {
|
||
"label": {"form_name": label, "confidence": 100.0},
|
||
"rows": [
|
||
{"row_index": i, "cells": [{"column_index": c, "value": v, "confidence": 100.0} for c, v in enumerate(r)]}
|
||
for i, r in enumerate(rows)
|
||
],
|
||
}
|
||
|
||
|
||
def response(*tables: dict[str, Any], error: dict[str, str] = OK, head: dict[str, Any] = HEAD) -> dict[str, Any]:
|
||
return {"file_uid": "x", "error": error, "data_ocr": {**head, "table_structure": list(tables)}}
|
||
|
||
|
||
def merged(*files: tuple[str, Any]) -> dict[str, Any]:
|
||
return {"job_id": "j", "files": [{"name": n, "response": r, "parse_error": None} for n, r in files]}
|