From d14f06a17108c6a2db663efd80dc2c46f5840e88 Mon Sep 17 00:00:00 2001 From: PureSaber <88314620+PureSaber@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:12:45 +0800 Subject: [PATCH 1/4] Improve ledger previews and low-frequency runtime compatibility --- .github/workflows/upstream-integration.yml | 4 +- README.md | 4 + src/quant_studio/desk.py | 40 ++------ src/quant_studio/server.py | 72 +++++++++++++-- src/quant_studio/table_view.py | 82 +++++++++++++++++ tests/test_desk_display.py | 102 +++++++++++++++++++++ 6 files changed, 259 insertions(+), 45 deletions(-) create mode 100644 src/quant_studio/table_view.py create mode 100644 tests/test_desk_display.py diff --git a/.github/workflows/upstream-integration.yml b/.github/workflows/upstream-integration.yml index 1f6cf5a..2f0d5eb 100644 --- a/.github/workflows/upstream-integration.yml +++ b/.github/workflows/upstream-integration.yml @@ -16,10 +16,10 @@ jobs: os: [ubuntu-24.04, windows-latest] upstream: - {repo: quant-paper-sim, ref: 0ff46a10f21c5df64a6cd77b7e941a506240dffe, test: paper} - - {repo: quant-hk-equity, ref: 37a9314e63038b8a89afcbbec2f5936953c0c62b, test: hk} + - {repo: quant-hk-equity, ref: 18cfe93a757e93e0c89875ceff9612350f989359, test: hk} - {repo: a-share-multifactor, ref: 3c48cd28d056b6dad36fbc0041408c010912a20d, test: ashare} - {repo: quant-pipeline, ref: b1fce90b85651248e9e60ae857b88fe4d170319e, test: account} - - {repo: quant-fund, ref: c7be45bdce66aee49762430ba93d2fc361e3c4b5, test: fund} + - {repo: quant-fund, ref: cbdfb5e353bf9ab372499d5ddca3e50bb03270d0, test: fund} - {repo: quant-futures-spread, ref: f01d6afd87ca0556d6e2f44e522cfecbf00cad56, test: futures} - {repo: quant-crypto-basis, ref: 02acfeb6227d8f61243b908846592af4e5b70365, test: crypto} steps: diff --git a/README.md b/README.md index e6e6fe1..ff3e6e7 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,10 @@ python -m venv .venv A股、港股和模拟盘模板均提供独立“数据预检”,分别调用所选环境的`a_share_multifactor.preflight`、`quant-hk preflight`和`quant-paper preflight`,校验同一配置及已有输入,不执行策略。预检记录保存配置、命令、原始输出与上游证据;通过后可“使用相同参数运行”,保留参数、因子和快照选择。实际运行仍重新校验输入,预检不是数据锁定或投资适用性认证。 +结果表格使用中文列名、数值右对齐和交替底色。金额与数量显示千位分隔并省略小数尾零,保留所有非零小数;权重长小数以`…`缩写,极小非零权重仍保留首个有效数字。悬停可查看原值,完整CSV下载保持原始字节和精度。证券代码、订单ID、日期及事件时间不按数值格式化。每张表说明展示行数,更多记录通过完整CSV查看。 + +总览、回测及结果列表的“文件更新”是运行结果文件的修改时间,包含服务所在机器本地时区的UTC偏移,不代表行情截止、成交或账户观察时刻。排序保留文件时间的小数秒,避免同一秒内较新的记录被排到旧记录后面;事件时间及账本计算继续由上游契约决定。 + A股只读加载缓存、检查历史时点、因子可计算性及全收益基准,不下载缺失数据或创建快照。模拟盘检查信号、证券身份、费用及保存状态前置条件,不回放成交或改写账户;Studio仍为每次运行使用独立状态。所选上游环境需要支持对应预检命令,旧版本不支持时保留失败日志,不回退到完整回测或可写的status命令。 ```powershell diff --git a/src/quant_studio/desk.py b/src/quant_studio/desk.py index 85a809b..f05c1f2 100644 --- a/src/quant_studio/desk.py +++ b/src/quant_studio/desk.py @@ -3,13 +3,13 @@ import json import os from dataclasses import dataclass -from datetime import datetime -from html import escape +from datetime import UTC, datetime from pathlib import Path from quant_studio import QuantStudioError from quant_studio.runner import safe_run_file from quant_studio.settings import setting +from quant_studio.table_view import html_table as html_table DATA_ROOTS = ( ("A股", "a-share-multifactor", "data"), @@ -119,42 +119,16 @@ def list_runs(runs_root: Path) -> list[dict[str, str]]: "has_nav": "1" if (directory / "nav.csv").is_file() else "0", "has_report": "1" if has_report else "0", "when": _format_time(stamp), - "mtime": str(int(stamp)), + "mtime": str(stamp), } ) - records.sort(key=lambda item: item["mtime"], reverse=True) + records.sort(key=lambda item: float(item["mtime"]), reverse=True) return records[:40] def _format_time(stamp: float) -> str: - return datetime.fromtimestamp(stamp).strftime("%Y-%m-%d %H:%M") - - -def html_table( - path: Path, title: str, limit: int = 12, *, column_labels: dict | None = None -) -> str: - import csv - - with path.open(newline="", encoding="utf-8") as stream: - reader = csv.reader(stream) - rows = [] - for index, row in enumerate(reader): - if index > limit: - break - rows.append(row) - if not rows: - return "" - labels = column_labels or {} - head = "".join( - f'
| 模板 | 状态 | 时间 | 净值 |
|---|---|---|---|
| 模板 | 状态 | 文件更新 | 净值 |
| 还没有研究记录 | |||
尚未连接账户。查看连接方法
'}这里只读取明确配置的账户,不登记、观察或封存账户。
从策略页提交。打开一条记录可看命令;失败时能看到输出。
| 模板 | 状态 | 时间 | 净值 |
|---|---|---|---|
| 模板 | 状态 | 文件更新 | 净值 |
| 还没有运行 | |||
| 模板 | 状态 | 时间 | 净值 |
|---|---|---|---|
| 模板 | 状态 | 文件更新 | 净值 |
| 还没有带净值或报告的结果 | |||