Resolve merge conflicts
This commit is contained in:
1 parent
e96cc97462
commit
22be6325a8
3 files changed
+53
-35
No files matched your search
@@ -25,7 +25,7 @@ from datetime import datetime, timedelta
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy import and_, case, desc, func, or_, select
|
||||
from sqlalchemy import and_, case, desc, func, not_, or_, select
|
||||
from langchain_core.messages import HumanMessage, SystemMessage
|
||||
|
||||
from app.gateway.deps import (
|
||||
@@ -355,6 +355,22 @@ def _run_time_filter(since: datetime, until: datetime):
|
||||
return and_(RunRow.created_at >= since, RunRow.created_at <= until)
|
||||
|
||||
|
||||
def _non_scheduled_run_filter():
|
||||
"""Exclude scheduler-generated runs that predate scheduled_task_runs links."""
|
||||
return or_(
|
||||
RunRow.first_human_message.is_(None),
|
||||
not_(RunRow.first_human_message.like("【定时任务触发】%")),
|
||||
)
|
||||
|
||||
|
||||
def _non_scheduled_tool_filter():
|
||||
return or_(
|
||||
ToolCallMetricRow.run_id.is_(None),
|
||||
RunRow.run_id.is_(None),
|
||||
_non_scheduled_run_filter(),
|
||||
)
|
||||
|
||||
|
||||
def _tool_time_filter(since: datetime, until: datetime):
|
||||
return and_(ToolCallMetricRow.created_at >= since, ToolCallMetricRow.created_at <= until)
|
||||
|
||||
@@ -404,6 +420,7 @@ def _apply_run_scope(
|
||||
stmt = stmt.where(RunRow.status != "error")
|
||||
if not include_scheduled:
|
||||
stmt = stmt.where(or_(run_id_column.is_(None), run_id_column.not_in(_scheduled_run_ids_stmt())))
|
||||
stmt = stmt.where(_non_scheduled_run_filter())
|
||||
return stmt
|
||||
|
||||
|
||||
@@ -417,6 +434,7 @@ def _apply_tool_scope(
|
||||
stmt = _apply_user_scope(stmt, ToolCallMetricRow.user_id, exclude_user_ids=exclude_user_ids, include_admins=include_admins)
|
||||
if not include_scheduled:
|
||||
stmt = stmt.where(or_(ToolCallMetricRow.run_id.is_(None), ToolCallMetricRow.run_id.not_in(_scheduled_run_ids_stmt())))
|
||||
stmt = stmt.outerjoin(RunRow, RunRow.run_id == ToolCallMetricRow.run_id).where(_non_scheduled_tool_filter())
|
||||
return stmt
|
||||
|
||||
|
||||
@@ -910,6 +928,7 @@ async def _query_overview(
|
||||
if not include_scheduled:
|
||||
run_where.append(or_(RunRow.run_id.is_(None), RunRow.run_id.not_in(_scheduled_run_ids_stmt())))
|
||||
tool_where.append(or_(ToolCallMetricRow.run_id.is_(None), ToolCallMetricRow.run_id.not_in(_scheduled_run_ids_stmt())))
|
||||
tool_where.append(_non_scheduled_tool_filter())
|
||||
|
||||
total_users_stmt = select(func.count(UserRow.id))
|
||||
total_users_stmt = _apply_user_scope(total_users_stmt, UserRow.id, exclude_user_ids=exclude_user_ids, include_admins=include_admins)
|
||||
@@ -928,7 +947,9 @@ async def _query_overview(
|
||||
select(
|
||||
func.count(ToolCallMetricRow.id),
|
||||
func.sum(case((func.nullif(ToolCallMetricRow.skill_name, "").is_not(None), 1), else_=0)),
|
||||
).where(*tool_where)
|
||||
)
|
||||
.outerjoin(RunRow, RunRow.run_id == ToolCallMetricRow.run_id)
|
||||
.where(*tool_where)
|
||||
)).one()
|
||||
|
||||
return AdminLeaderboardOverview(
|
||||
|
||||
Reference in new issue
Block a user