From d6a0bdc7bf3ad458dc94f078e19bc01ce37f2dae Mon Sep 17 00:00:00 2001 From: anor Date: Thu, 26 Mar 2026 01:47:49 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20batch=20V2=20=E2=80=94=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D0=BC=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=82=D1=82=D0=B5=D1=80=D0=BD=D1=8B=20=D0=B2=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=BE=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D0=B0=20+?= =?UTF-8?q?=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B0=20=D1=81=20=D0=B3=D0=BB?= =?UTF-8?q?=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Claude генерирует batch_summary.json с найденными паттернами - UI показывает сметчику: лист, шифр, паттерны итогов, маппинг столбцов - Скрипт скрыт в
для разработчиков - Кнопка «Пакетная V2» на главной странице чата Co-Authored-By: Claude Opus 4.6 (1M context) --- batch_v2.py | 47 +++++++++++++++++++++++++++++++++++--- main.py | 5 +++-- static/batch2.html | 56 ++++++++++++++++++++++++++++++++++++++++++---- static/chat.html | 3 ++- 4 files changed, 101 insertions(+), 10 deletions(-) diff --git a/batch_v2.py b/batch_v2.py index af51f00..65f4226 100644 --- a/batch_v2.py +++ b/batch_v2.py @@ -196,7 +196,41 @@ NOTE: In the script, use the `target_file` variable (not a hardcoded path). 1. Read the sample CSV files in /data/sample_csv/ — understand their structure 2. Read the target CSV files in /data/target_csv/ — understand where data goes 3. Figure out: what to extract from each source, how to match to target rows -4. Write a COMPLETE Python script to /data/batch_script.py +4. Write TWO files: + +### File 1: /data/batch_summary.json — human-readable summary for the user +JSON with these fields (in Russian): +```json +{{ + "description": "Краткое описание что будет сделано", + "source_patterns": {{ + "sheet": "на каком листе искать данные", + "id_field": "где шифр/название сметы (например: имя файла, ячейка B5)", + "totals": {{ + "строительные работы": "паттерн поиска (например: ВСЕГО строительные работы)", + "монтажные работы": "паттерн поиска", + "оборудование": "паттерн поиска", + "прочие затраты": "паттерн поиска" + }}, + "value_column": "в каком столбце значения (например: A или H)", + "units": "рубли или тыс.руб" + }}, + "target_mapping": {{ + "sheet": "на какой лист сводного файла записывать", + "match_column": "столбец с шифрами для сопоставления (например: B)", + "value_columns": {{ + "строительные работы": "столбец (например: D)", + "монтажные работы": "столбец (например: E)", + "оборудование": "столбец (например: F)", + "прочие затраты": "столбец (например: G)" + }}, + "units": "тыс.руб" + }}, + "conversion": "делить на 1000 (руб → тыс.руб)" или "без конвертации" +}} +``` + +### File 2: /data/batch_script.py — Python script ## CRITICAL: The script will run on ALL {total_xlsx_count} files, not just samples! The script must handle any file with the same general structure as the samples. @@ -303,12 +337,19 @@ async def run_claude_analysis( elif etype == "result": got_result = True script_path = job_dir / "batch_script.py" + summary_path = job_dir / "batch_summary.json" + summary = {} + if summary_path.exists(): + try: + summary = json.loads(summary_path.read_text(encoding="utf-8")) + except (json.JSONDecodeError, OSError): + pass if script_path.exists(): script = script_path.read_text(encoding="utf-8") - yield {"type": "done", "script": script} + yield {"type": "done", "script": script, "summary": summary} else: result_text = event.get("result", "") - yield {"type": "done", "script": "", "result": result_text} + yield {"type": "done", "script": "", "result": result_text, "summary": summary} finally: if proc.returncode is None: diff --git a/main.py b/main.py index 6d883ce..4688576 100644 --- a/main.py +++ b/main.py @@ -465,13 +465,14 @@ async def batch_v2_analyze(job_id: str, request: Request): yield f"event: tool\ndata: {json.dumps({'tool': event['tool']}, ensure_ascii=False)}\n\n" elif etype == "done": script = event.get("script", "") + summary = event.get("summary", {}) if script: - job["analysis"] = {"python_script": script} + job["analysis"] = {"python_script": script, "summary": summary} job["status"] = "analyzed" else: job["analysis"] = {"error": "Claude did not generate script", "result": event.get("result", "")} job["status"] = "analysis_failed" - yield f"event: done\ndata: {json.dumps({'script': script, 'status': job['status']}, ensure_ascii=False)}\n\n" + yield f"event: done\ndata: {json.dumps({'script': script, 'summary': summary, 'status': job['status']}, ensure_ascii=False)}\n\n" return StreamingResponse( event_stream(), diff --git a/static/batch2.html b/static/batch2.html index 32268a4..f79646f 100644 --- a/static/batch2.html +++ b/static/batch2.html @@ -64,11 +64,14 @@ pre { background: #2c2c2c; color: #f5f0eb; padding: .8rem; border-radius: 6px; o
- +