mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-19 10:02:00 +00:00
W4-d 前端:数据目录页的「变化」视图、表详情「结构与取值变化」一节、后台任务条、数据源的角标和定时维护
第 3 波的结构变化、取值观察、变化记录、定时维护都只有接口,这一提交给它们界面,能走通(收口): - 数据目录页左栏加第三个视图「变化」(view=changes):按要处理 / 提醒 / 说明分组(组内照服务端排好的先后),能按开着的 / 处理过的、结构变化 / 取值变化筛,筛选和打开的那一条记在地址里;视图标签上写几条要处理。点开一条,右栏写服务端的一句说法、 依据(谁、经什么测到的;取值变化写观察口径,结构变化写比对的两版结构)、前后各是什么、影响面(说到这些列的目录项和它们 现在的状态、写死了这张表的已发布模板、「这条 SQL 现在会报列不存在」、有效记录条件)、能做的处理。动作和做不了的原因都照 服务端给的 actions 画;清理目录项先确认,加入码值可以先填含义,误报必须写理由(写之前按钮不能点,服务端也会拒)。处理完 照实写结果:谁、什么时候、目录第几版、建了的任务(点得进起草、剖析的进度)。 - 表详情加「结构与取值变化」一节:这张表的变化(点「去处理」到「变化」视图里那一条)、撤销过的「已列全」、最近几次取值观察 (行数、码值分布、最新业务日期、按日行数)和各自的口径,口径换过的说一句不互相比较;按日行数的小柱图只给眼睛看,数字写在 字里和读屏名称里。 - 后台任务条(05 (g)):页头的「起草」「数据剖析」改回纯入口(进行中转圈、排队中时钟,读屏名称写状态、不写数字);DraftStrip 换成 JobStrip,按服务端给的同源队先后列出探查、起草、剖析,每项一行加进度条和提醒(剖析的「最近查询多数超时」也挪到这里, 窄屏、触屏看得见全文),「查看」打开对应的对话框,探查的到数据源卡片上(#source-<id> 滚过去)。 - 数据源卡片:要处理的变化条数的角标(读屏写全,点开到「变化」视图);「定时维护」对话框(和「探查范围」一样是卡片上的 独立对话框,不塞进编辑表单:两个保存混在一起出错时说不清哪一样没存上):开关缺省关、开启时提示选低峰时段,选步骤(PUT /maintenance),频率用 components/FreqPicker,保存成一条 target_kind=source_maintenance 的定时任务(新建 ScheduleTargetCreate, 改频率、开关 SchedulePatch 带版本);照实写下一次什么时候、最近一次建了哪些任务、哪几步没执行和原因(触发记录的 inputs), 剖析没开、调度没开时说到点会怎样。上传表格、记录表不给这一节。开着的维护在卡片上带一个标签写频率。 - 地址里带 pjob / djob 时打开那个剖析、起草任务的进度(定时维护的「最近一次」从数据源页链过来)。 新文件:typesSource.ts(接口约定)、api/sourceChanges.ts、lib/termsSource.ts(terms.ts 末尾转出)、pages/catalog/changes.ts、 ChangesQueue.tsx、ChangeDetail.tsx、TableChanges.tsx、JobStrip.tsx、pages/SourceMaintenanceDialog.tsx。变化的叫法和服务端逐字 一致,tests/test_source_change_terms.py 守着(维护步骤的叫法同样)。观察的按日行数服务端补上窗口里没数据的日子(不然小柱图 看不出断档)。
This commit is contained in:
@@ -556,7 +556,16 @@ def _shown(kind: str, data: Mapping[str, Any]) -> dict[str, Any]:
|
||||
"truncated": bool(data.get("truncated"))}
|
||||
if kind == "daily_volume":
|
||||
days = data.get("days") if isinstance(data.get("days"), Mapping) else {}
|
||||
series = sorted((str(d), int(n)) for d, n in days.items() if isinstance(n, (int, float)))
|
||||
counts = {str(d)[:10]: int(n) for d, n in days.items() if isinstance(n, (int, float))}
|
||||
# 窗口里没数据的日子补 0:只列有数据的日子,断了的那几天在图上就看不出来
|
||||
try:
|
||||
first, last = date.fromisoformat(str(data.get("since"))[:10]), date.fromisoformat(str(data.get("until"))[:10])
|
||||
except ValueError:
|
||||
first = last = None
|
||||
if first and last and 0 <= (last - first).days <= WINDOW_DAYS + 7:
|
||||
for i in range((last - first).days + 1):
|
||||
counts.setdefault((first + timedelta(days=i)).isoformat(), 0)
|
||||
series = sorted(counts.items())
|
||||
return {"since": data.get("since"), "until": data.get("until"), "days": [list(p) for p in series],
|
||||
"total": sum(n for _, n in series), "days_with_data": sum(1 for _, n in series if n > 0)}
|
||||
if kind == "freshness":
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
"""变化的叫法前后端一致(总方案 X10:一种说法)。
|
||||
|
||||
服务端给人看的一句(source_changes.summary)用 KIND_LABEL,前端「变化」标签页、表详情的那一节用 lib/termsSource.ts 的
|
||||
SOURCE_CHANGE_KIND_LABEL:两边逐字对照,一边改了另一边没跟上,同一条变化在接口和界面上就是两种说法。写法同
|
||||
test_notify_events.py 对照通知事件的叫法。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import app.db.models # noqa: F401 - 模型都登记上(source_objects 的外键指向 data_sources)
|
||||
from app.data import source_changes as sc
|
||||
from app.data import source_maintenance as sm
|
||||
|
||||
TERMS = Path(__file__).resolve().parents[2] / "frontend" / "src" / "lib" / "termsSource.ts"
|
||||
|
||||
|
||||
def _block(source: str, head: str) -> str:
|
||||
start = source.index(head)
|
||||
start = source.index("{", start) + 1
|
||||
depth, i = 1, start
|
||||
while depth:
|
||||
depth += {"{": 1, "}": -1}.get(source[i], 0)
|
||||
i += 1
|
||||
return source[start:i - 1]
|
||||
|
||||
|
||||
def _entries(block: str) -> dict[str, str]:
|
||||
return dict(re.findall(r"'?([a-z_]+)'?:\s*'([^']*)'", block))
|
||||
|
||||
|
||||
def test_change_kind_labels_match_word_for_word():
|
||||
source = TERMS.read_text(encoding="utf-8")
|
||||
labels = _entries(_block(source, "export const SOURCE_CHANGE_KIND_LABEL"))
|
||||
assert labels == sc.KIND_LABEL, "「变化」标签页的叫法和服务端的对不上"
|
||||
assert set(labels) == set(sc.KINDS)
|
||||
|
||||
|
||||
def test_maintenance_step_labels_match_word_for_word():
|
||||
source = TERMS.read_text(encoding="utf-8")
|
||||
block = _block(source, "export const MAINTENANCE_TEXT")
|
||||
steps = _entries(_block(block, "step:"))
|
||||
assert steps == sm.STEP_LABEL, "定时维护的步骤叫法和服务端的对不上(没执行的原因里用的是服务端那一份)"
|
||||
@@ -341,3 +341,23 @@ def test_schedule_target_columns_are_the_ones_the_page_uses():
|
||||
"""数据源设置里建的维护定时:target_kind / target_id 写法和调度那一套同一处封装(X4)。"""
|
||||
cols = scheduler_service.target_columns("source_maintenance", "src-x")
|
||||
assert cols["target_kind"] == "source_maintenance" and cols["target_id"] == "src-x" and cols["workflow_id"] == ""
|
||||
|
||||
|
||||
async def test_daily_volume_fills_the_days_without_data(client, shop):
|
||||
"""按日行数只记了有数据的日子:窗口里断了的那几天补 0,界面上的小柱图才看得出断档。"""
|
||||
sid = shop["id"]
|
||||
async with SessionLocal() as session:
|
||||
session.add(TableObservation(source_id=sid, table_name="orders", column_name="paid_on", kind="daily_volume",
|
||||
basis={"method": "window", "column": "paid_on", "days": 35, "since": "2026-10-01"},
|
||||
basis_key="window:paid_on:35",
|
||||
data={"since": "2026-10-01", "until": "2026-10-05",
|
||||
"days": {"2026-10-01": 30, "2026-10-02": 28, "2026-10-05": 31}},
|
||||
at=utcnow()))
|
||||
await session.commit()
|
||||
body = (await client.get(f"/api/datasources/{sid}/observations", params={"table": "orders"})).json()
|
||||
[daily] = [s for s in body["series"] if s["kind"] == "daily_volume"]
|
||||
point = daily["points"][0]
|
||||
assert point["data"]["days"] == [["2026-10-01", 30], ["2026-10-02", 28], ["2026-10-03", 0], ["2026-10-04", 0],
|
||||
["2026-10-05", 31]]
|
||||
assert point["data"]["days_with_data"] == 3 and point["data"]["total"] == 89
|
||||
assert point["basis_text"] == "业务日期 paid_on 最近 35 天"
|
||||
|
||||
Reference in New Issue
Block a user