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
- +