feat: unify backtest table controls and add refresh action
Deploy production / deploy (push) Successful in 53s
Deploy production / deploy (push) Successful in 53s
This commit is contained in:
@@ -151,11 +151,16 @@ class Backtests:
|
||||
await self.db.flush()
|
||||
return await self.draft(draft_id)
|
||||
|
||||
async def drafts(self, limit=25, offset=0):
|
||||
async def drafts(self, limit=25, offset=0, q="", sort="updated_at", direction="desc"):
|
||||
query = select(BacktestDraft)
|
||||
if q:
|
||||
query = query.where(BacktestDraft.name.contains(q, autoescape=True))
|
||||
column = {"name": BacktestDraft.name, "updated_at": BacktestDraft.updated_at}[sort]
|
||||
order = column.asc() if direction == "asc" else column.desc()
|
||||
rows = (
|
||||
await self.db.scalars(
|
||||
select(BacktestDraft)
|
||||
.order_by(BacktestDraft.updated_at.desc(), BacktestDraft.id)
|
||||
query
|
||||
.order_by(order, BacktestDraft.id)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
)
|
||||
@@ -173,7 +178,7 @@ class Backtests:
|
||||
)
|
||||
for r in rows
|
||||
],
|
||||
"total": await self.db.scalar(select(func.count()).select_from(BacktestDraft)),
|
||||
"total": await self.db.scalar(select(func.count()).select_from(query.subquery())),
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
}
|
||||
@@ -355,15 +360,19 @@ class Backtests:
|
||||
await self.db.flush()
|
||||
return await self.run(run.id)
|
||||
|
||||
async def runs(self, limit=25, offset=0, source=None, reference=None, research_id=None):
|
||||
async def runs(self, limit=25, offset=0, source=None, reference=None, research_id=None, q="", sort="created_at", direction="desc"):
|
||||
query = select(BacktestRun)
|
||||
if q:
|
||||
query = query.where(BacktestRun.name.contains(q, autoescape=True))
|
||||
column = {"name": BacktestRun.name, "created_at": BacktestRun.created_at}[sort]
|
||||
order = column.asc() if direction == "asc" else column.desc()
|
||||
for key, value in (("kind", source), ("reference", reference), ("research_id", research_id)):
|
||||
if value:
|
||||
query = query.where(BacktestRun.source[key].as_string() == value)
|
||||
total = await self.db.scalar(select(func.count()).select_from(query.subquery()))
|
||||
rows = (
|
||||
await self.db.scalars(
|
||||
query.order_by(BacktestRun.created_at.desc(), BacktestRun.id).limit(limit).offset(offset)
|
||||
query.order_by(order, BacktestRun.id).limit(limit).offset(offset)
|
||||
)
|
||||
).all()
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user