feat: 支持研究素材删除并统一 Semi 表格
This commit is contained in:
@@ -5,7 +5,7 @@ import json
|
||||
from collections import defaultdict
|
||||
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy import func, select, update
|
||||
|
||||
from ..backtests.contracts import Candidate, DraftInput, PreviewInput, SimulationSettings, Source
|
||||
from ..backtests.service import Backtests, uid
|
||||
@@ -243,6 +243,7 @@ class Experiments:
|
||||
"id",
|
||||
"name",
|
||||
"kind",
|
||||
"archived",
|
||||
"hypothesis",
|
||||
"inputs",
|
||||
"parents",
|
||||
@@ -256,7 +257,7 @@ class Experiments:
|
||||
)
|
||||
|
||||
async def list(self, kind=None, limit=25, offset=0):
|
||||
query = select(ResearchExperiment)
|
||||
query = select(ResearchExperiment).where(ResearchExperiment.archived.is_(False))
|
||||
if kind:
|
||||
query = query.where(ResearchExperiment.kind == kind)
|
||||
total = await self.db.scalar(select(func.count()).select_from(query.subquery()))
|
||||
@@ -281,6 +282,19 @@ class Experiments:
|
||||
}
|
||||
)
|
||||
|
||||
async def archive(self, experiment_id):
|
||||
"""Hide an immutable experiment; backtests and lineage must still resolve it.
|
||||
|
||||
Returns an acknowledgement, or raises HTTP 404 for an unknown ID. Repeated
|
||||
deletion is idempotent because candidate contents cannot change.
|
||||
"""
|
||||
result = await self.db.execute(
|
||||
update(ResearchExperiment).where(ResearchExperiment.id == experiment_id).values(archived=True)
|
||||
)
|
||||
if result.rowcount != 1:
|
||||
raise HTTPException(404, "研究实验不存在")
|
||||
return {"ok": True}
|
||||
|
||||
async def preview(self, experiment_id, candidate_ids=None, source_kind=None, reference=None):
|
||||
experiment = await self.get(experiment_id)
|
||||
candidates = experiment["candidates"]
|
||||
|
||||
Reference in New Issue
Block a user