feat: 正式成果并入任务清单并限制成果页列表高度
This commit is contained in:
@@ -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 进程执行,刷新、切页或关闭浏览器不会重启或中断计算。出图停止在几何批处理边界生效,当前文件写入/打包可能需要等待;楼宇查询停止领取新坐标,正在处理的请求和结果写完后退出。已完成文件保留,失败和停止不标为成功;重启后意外退出的进程标为中断。**起始行只控制输入跳过,不是自动断点续传**,重试会创建新任务成果。
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+12
-10
@@ -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}")
|
||||
|
||||
+43
-31
@@ -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("文件较大,请点击上方“打开目录”后直接复制。")
|
||||
|
||||
Reference in New Issue
Block a user