From 6fdc613bac623c33d2ebecb06b4a20c9161dc626 Mon Sep 17 00:00:00 2001 From: nixevol Date: Wed, 16 Sep 2026 17:27:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=AD=A3=E5=BC=8F=E6=88=90=E6=9E=9C?= =?UTF-8?q?=E5=B9=B6=E5=85=A5=E4=BB=BB=E5=8A=A1=E6=B8=85=E5=8D=95=E5=B9=B6?= =?UTF-8?q?=E9=99=90=E5=88=B6=E6=88=90=E6=9E=9C=E9=A1=B5=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- tests/test_toolbox.py | 5 ++- ui/home_page.py | 22 +++++++------ ui/results_page.py | 74 +++++++++++++++++++++++++------------------ 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index c995b7a..940e162 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ python -m streamlit run app.py - **任务中心**:查看进度并停止任务。 - **成果浏览**:查看成果清单,按文件下载。 -每次任务使用 `output/toolbox/tasks/<任务ID>/results/`,不覆盖 `output/` 下原有成果。任务配置、状态和日志持久保存,连接参数只通过标准输入传递,不进入任务历史。上传副本放在 `output/toolbox/imports/`。大文件推荐使用本地路径;Streamlit 上传会占用额外内存,单文件上限 4 GB。超过 128 MB 的成果直接从本地目录复制,避免下载占用服务内存。 +每次任务使用 `output/toolbox/tasks/<任务ID>/results/`。历史正式成果已导入为任务 `20260815-a0000001`,界面只按任务清单浏览和下载,不再单独区分“现有正式成果”。任务配置、状态和日志持久保存,连接参数只通过标准输入传递,不进入任务历史。上传副本放在 `output/toolbox/imports/`。大文件推荐使用本地路径;Streamlit 上传会占用额外内存,单文件上限 4 GB。超过 128 MB 的成果请从本地目录复制,避免下载占用服务内存。 同一时间只运行一个工具箱任务。任务由独立 Python 进程执行,刷新、切页或关闭浏览器不会重启或中断计算。出图停止在几何批处理边界生效,当前文件写入/打包可能需要等待;楼宇查询停止领取新坐标,正在处理的请求和结果写完后退出。已完成文件保留,失败和停止不标为成功;重启后意外退出的进程标为中断。**起始行只控制输入跳过,不是自动断点续传**,重试会创建新任务成果。 diff --git a/tests/test_toolbox.py b/tests/test_toolbox.py index 71a2c9a..37f6ddc 100644 --- a/tests/test_toolbox.py +++ b/tests/test_toolbox.py @@ -172,9 +172,12 @@ class PageTest(unittest.TestCase): (root / "b.zip").write_bytes(b"b") (root / "a.csv").write_text("x\n", encoding="utf-8") (root / ".hidden").write_text("x", encoding="utf-8") - from ui.results_page import _file_rows + from ui.results_page import _file_rows, _task_label names = [path.name for path in _file_rows(root)] self.assertEqual(names, ["a.csv", "b.zip"]) + self.assertIn("市场网格出图", _task_label({ + "id": "20260815-a0000001", "kind": "market", "status": "success" + })) def test_uploaded_file_is_stored_once_with_exact_bytes(self): from streamlit.testing.v1 import AppTest diff --git a/ui/home_page.py b/ui/home_page.py index 472f2d8..881a745 100644 --- a/ui/home_page.py +++ b/ui/home_page.py @@ -1,17 +1,26 @@ -import json +from pathlib import Path import streamlit as st from toolbox.tasks import ROOT, list_tasks, ACTIVE from toolbox.validation import SOURCES +def _result_zip_count(tasks): + total = 0 + for task in tasks: + directory = Path(task["output"]) + if not directory.exists(): + continue + total += sum(1 for path in directory.glob("*.zip") if path.is_file()) + return total + + def render(): st.markdown("## MarketGrid 工具箱") tasks = list_tasks() - output = ROOT / "output" cols = st.columns(3) cols[0].metric("正在运行", sum(t["status"] in ACTIVE for t in tasks)) cols[1].metric("任务记录", len(tasks)) - cols[2].metric("现有 ZIP 成果", len(list(output.glob("*.zip")))) + cols[2].metric("成果包", _result_zip_count(tasks)) st.markdown("#### 选择工具") left, right = st.columns(2) with left, st.container(border=True): @@ -26,10 +35,3 @@ def render(): st.dataframe([{"数据源": label, "状态": "已就绪" if (ROOT / file).is_file() else "缺失", "文件": file, "大小 MB": round((ROOT / file).stat().st_size / 1024**2, 1) if (ROOT / file).is_file() else 0} for label, file, _ in SOURCES.values()], hide_index=True, width="stretch") - summary_path = output / "summary.json" - if summary_path.exists(): - try: - data = json.loads(summary_path.read_text(encoding="utf-8")) - st.caption(f"现有正式成果:{len(data.get('zip_results', []))} 个市场包") - except (OSError, ValueError) as error: - st.warning(f"汇总记录无法读取:{error}") diff --git a/ui/results_page.py b/ui/results_page.py index ba2e8e1..d9a5522 100644 --- a/ui/results_page.py +++ b/ui/results_page.py @@ -1,9 +1,10 @@ import os from pathlib import Path import streamlit as st -from toolbox.tasks import ROOT, KINDS, LABELS, list_tasks +from toolbox.tasks import KINDS, LABELS, list_tasks MAX_INLINE_DOWNLOAD = 128 * 1024**2 +LIST_HEIGHT = 420 def _file_rows(directory): @@ -15,30 +16,20 @@ def _file_rows(directory): ) -def _download_button(path, key): - size = path.stat().st_size - if size <= MAX_INLINE_DOWNLOAD: - st.download_button( - "下载", - data=path.read_bytes(), - file_name=path.name, - mime="application/octet-stream", - key=key, - ) - else: - st.caption("文件较大,请打开目录后复制") +def _task_label(task): + return f"{task['id']} · {KINDS.get(task['kind'], task['kind'])} · {LABELS.get(task['status'], task['status'])}" def render(): st.markdown("## 成果浏览") tasks = list_tasks() - roots = {"现有正式成果": ROOT / "output"} - roots.update({ - f"{task['id']} · {KINDS[task['kind']]} · {LABELS[task['status']]}": Path(task["output"]) - for task in tasks - }) - selected = st.selectbox("成果清单", list(roots)) - directory = roots[selected] + if not tasks: + st.info("暂无成果。完成出图或查询后会显示在这里。") + return + + labels = {_task_label(task): Path(task["output"]) for task in tasks} + selected = st.selectbox("成果清单", list(labels)) + directory = labels[selected] cols = st.columns([4, 1]) cols[0].caption(str(directory)) if os.name == "nt" and cols[1].button("打开目录", use_container_width=True): @@ -46,17 +37,38 @@ def render(): files = _file_rows(directory) if not files: - st.info("暂无文件。") + st.info("该任务暂无文件。") return + download_key = f"pending_download::{selected}" + pending_name = st.session_state.get(download_key) + st.markdown("#### 文件列表") - header = st.columns([5, 2, 2]) - header[0].markdown("**文件**") - header[1].markdown("**大小**") - header[2].markdown("**操作**") - for path in files: - row = st.columns([5, 2, 2]) - row[0].write(path.name) - row[1].write(f"{path.stat().st_size / 1024**2:,.2f} MB") - with row[2]: - _download_button(path, key=f"download_{selected}_{path.name}") + with st.container(height=LIST_HEIGHT, border=True): + for path in files: + row = st.columns([6, 2, 2]) + row[0].markdown(f"`{path.name}`") + row[1].write(f"{path.stat().st_size / 1024**2:,.2f} MB") + if row[2].button("下载", key=f"pick_{selected}_{path.name}", use_container_width=True): + st.session_state[download_key] = path.name + pending_name = path.name + + if pending_name: + target = directory / pending_name + if not target.is_file(): + st.session_state.pop(download_key, None) + st.warning("文件已不存在,请重新选择。") + return + size = target.stat().st_size + st.markdown(f"已选择:**{pending_name}**({size / 1024**2:,.2f} MB)") + if size <= MAX_INLINE_DOWNLOAD: + st.download_button( + "保存到本地", + data=target.read_bytes(), + file_name=target.name, + mime="application/octet-stream", + key=f"save_{selected}_{pending_name}", + type="primary", + ) + else: + st.info("文件较大,请点击上方“打开目录”后直接复制。")