From 85913f83321718855f831961caa29420b7a05158 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 22 Jul 2026 17:56:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A8=A1=E5=9E=8B=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E6=8C=89model=E5=BD=92=E5=B9=B6(GROUP=20BY),?= =?UTF-8?q?=E6=B6=88=E9=99=A4=E5=90=8C=E6=A8=A1=E5=9E=8B=E5=A4=9A=E6=9D=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sage_datamart/init.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sage_datamart/init.py b/sage_datamart/init.py index 4323394..2486b0d 100644 --- a/sage_datamart/init.py +++ b/sage_datamart/init.py @@ -57,7 +57,15 @@ async def api_model_perf(sor, params_kw=None): try: model = params_kw.get('model') if params_kw else None stat_date = params_kw.get('date') if params_kw else None - sql = "SELECT * FROM dm_model_perf_daily WHERE 1=1" + sql = """SELECT model, catelogid, providerid, + SUM(total_calls) as total_calls, + SUM(success_calls) as success_calls, + SUM(fail_calls) as fail_calls, + CASE WHEN SUM(total_calls)>0 THEN ROUND(SUM(success_calls)*100.0/SUM(total_calls),1) ELSE 0 END as success_rate, + CASE WHEN SUM(total_calls)>0 THEN ROUND(SUM(total_calls*avg_ttft_ms)/SUM(total_calls),1) ELSE NULL END as avg_ttft_ms, + CASE WHEN SUM(total_calls)>0 THEN ROUND(SUM(total_calls*avg_ttot_ms)/SUM(total_calls),1) ELSE NULL END as avg_ttot_ms, + COALESCE(SUM(total_amount_cny),0) as total_amount_cny + FROM dm_model_perf_daily WHERE 1=1""" ns = {} if stat_date: sql += " AND stat_date=${stat_date}$" @@ -65,6 +73,7 @@ async def api_model_perf(sor, params_kw=None): if model: sql += " AND model=${model}$" ns['model'] = model + sql += " GROUP BY model, catelogid, providerid" sql += " ORDER BY total_calls DESC LIMIT 50" rows = await sor.sqlExe(sql, ns) return [dict(r) for r in rows]