fix(workbench): remove synthetic check projections
This commit is contained in:
@@ -5,7 +5,7 @@ import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from uuid import NAMESPACE_URL, UUID, uuid5
|
||||
from uuid import UUID, uuid5
|
||||
|
||||
from psycopg.types.json import Jsonb
|
||||
|
||||
@@ -16,49 +16,18 @@ from app.services.content_digest import digest
|
||||
from samples.peripheral.auth import Identity
|
||||
from samples.peripheral.config import SampleSettings
|
||||
from samples.peripheral.demo_data import build_demo_content
|
||||
from samples.peripheral.schemas import CreateTestDataRecord, CreateWorkOrder
|
||||
from samples.peripheral.schemas import CreateTestDataRecord
|
||||
from samples.peripheral.seed_identity import SEED_ACTOR_ID, SEED_NAMESPACE
|
||||
from samples.peripheral.store import PostgresStore
|
||||
|
||||
|
||||
SEED_NAMESPACE = uuid5(NAMESPACE_URL, "tjwater/peripheral-sample/seed/v1")
|
||||
ACTOR_ID = uuid5(SEED_NAMESPACE, "actor")
|
||||
ACTOR_ID = SEED_ACTOR_ID
|
||||
|
||||
|
||||
def request_id(kind: str) -> UUID:
|
||||
return uuid5(SEED_NAMESPACE, kind)
|
||||
|
||||
|
||||
WORK_ORDERS = (
|
||||
{
|
||||
"key": "work-order/demo-communication",
|
||||
"title": "合成通信核查",
|
||||
"summary": "检查 DEMO-P001 的预置通信中断情节,仅用于外围样板联调。",
|
||||
"status": "open",
|
||||
"priority": "high",
|
||||
"assignee": "外围样板班组",
|
||||
"scheduled_at": "2026-09-17T03:00:00Z",
|
||||
},
|
||||
{
|
||||
"key": "work-order/demo-pressure",
|
||||
"title": "合成压力偏差复核",
|
||||
"summary": "复核 DEMO-P001、DEMO-P002 相邻测试点的固定合成读数,不代表现场异常。",
|
||||
"status": "in_progress",
|
||||
"priority": "urgent",
|
||||
"assignee": "演示核查班组",
|
||||
"scheduled_at": "2026-09-17T04:00:00Z",
|
||||
},
|
||||
{
|
||||
"key": "work-order/flow-zero",
|
||||
"title": "合成零流量样本确认",
|
||||
"summary": "确认 DEMO-F001 中零值与缺测值可被界面明确区分。",
|
||||
"status": "completed",
|
||||
"priority": "normal",
|
||||
"assignee": "外围样板班组",
|
||||
"scheduled_at": "2026-09-17T06:00:00Z",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
TEST_DATA = (
|
||||
("DEMO-P001", "合成压力 1 · 00:00", "2026-09-17T00:00:00Z", 24.37, "m", "valid"),
|
||||
("DEMO-P001", "合成压力 1 · 00:15", "2026-09-17T00:15:00Z", 24.18, "m", "valid"),
|
||||
@@ -97,31 +66,22 @@ def previous_seed_result(
|
||||
return row["result"]
|
||||
|
||||
|
||||
def restore_seeded_resources(
|
||||
def restore_seeded_test_data(
|
||||
store: PostgresStore,
|
||||
project_id: str,
|
||||
*,
|
||||
table: str,
|
||||
id_column: str,
|
||||
resource_ids: list[str],
|
||||
record_ids: list[str],
|
||||
) -> None:
|
||||
"""Restore deterministic seed rows that were soft-deleted after an earlier run."""
|
||||
allowed_resources = {
|
||||
("work_orders", "work_order_id"),
|
||||
("test_data_records", "record_id"),
|
||||
}
|
||||
if (table, id_column) not in allowed_resources:
|
||||
raise ValueError("unsupported seeded resource")
|
||||
if not resource_ids:
|
||||
if not record_ids:
|
||||
return
|
||||
|
||||
with store.connection() as connection:
|
||||
connection.execute(
|
||||
f"""UPDATE peripheral_sample.{table}
|
||||
"""UPDATE peripheral_sample.test_data_records
|
||||
SET document=document - 'deleted_at' - 'deleted_by',
|
||||
deleted_at=NULL, deleted_by=NULL
|
||||
WHERE project_id=%s AND {id_column}=ANY(%s::uuid[])""",
|
||||
(project_id, resource_ids),
|
||||
WHERE project_id=%s AND record_id=ANY(%s::uuid[])""",
|
||||
(project_id, record_ids),
|
||||
)
|
||||
|
||||
|
||||
@@ -160,34 +120,6 @@ def main() -> int:
|
||||
who = Identity(project_id, str(ACTOR_ID), True)
|
||||
|
||||
dataset_digest = ensure_demo_dataset(store, project_id)
|
||||
order_ids = []
|
||||
for item in WORK_ORDERS:
|
||||
seed_request_id = request_id(item["key"])
|
||||
command = CreateWorkOrder(
|
||||
request_id=seed_request_id,
|
||||
title=item["title"],
|
||||
summary=item["summary"],
|
||||
status=item["status"],
|
||||
priority=item["priority"],
|
||||
assignee=item["assignee"],
|
||||
scheduled_at=item["scheduled_at"],
|
||||
)
|
||||
previous = previous_seed_result(
|
||||
store,
|
||||
project_id,
|
||||
seed_request_id=seed_request_id,
|
||||
command_key="create_work_order",
|
||||
)
|
||||
result = previous or store.create_work_order(who, command)
|
||||
order_ids.append(result["work_order_id"])
|
||||
restore_seeded_resources(
|
||||
store,
|
||||
project_id,
|
||||
table="work_orders",
|
||||
id_column="work_order_id",
|
||||
resource_ids=order_ids,
|
||||
)
|
||||
|
||||
record_ids = []
|
||||
for point_id, label, observed_at, value, unit, quality in TEST_DATA:
|
||||
seed_request_id = request_id(f"test-data/{point_id}/{observed_at}")
|
||||
@@ -209,20 +141,13 @@ def main() -> int:
|
||||
)
|
||||
result = previous or store.create_test_data(who, command)
|
||||
record_ids.append(result["record_id"])
|
||||
restore_seeded_resources(
|
||||
store,
|
||||
project_id,
|
||||
table="test_data_records",
|
||||
id_column="record_id",
|
||||
resource_ids=record_ids,
|
||||
)
|
||||
restore_seeded_test_data(store, project_id, record_ids)
|
||||
|
||||
result = {
|
||||
"project_id": project_id,
|
||||
"actor_id": str(ACTOR_ID),
|
||||
"origin": "synthetic",
|
||||
"demo_dataset_digest": dataset_digest,
|
||||
"work_orders": {"count": len(order_ids), "ids": order_ids},
|
||||
"test_data_records": {"count": len(record_ids), "ids": record_ids},
|
||||
}
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2, sort_keys=True))
|
||||
|
||||
Reference in New Issue
Block a user