From 237c09262f50dc67ee3fecb67c01826fa99d3085 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 21 Jul 2026 15:05:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20init=5Fdata.py=E8=A1=A5=E5=85=A8?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E5=AD=97=E6=AE=B5+userorgid=E4=B8=BANone?= =?UTF-8?q?=E5=85=9C=E5=BA=95(=E7=A9=BA=E4=B8=B2),=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/init_data.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/init_data.py b/scripts/init_data.py index f9065d4..5d3d6c8 100644 --- a/scripts/init_data.py +++ b/scripts/init_data.py @@ -54,7 +54,7 @@ async def batch_sync_call_fact(sor, source_table, batch_size=1000): if not rows: break - print(f' [{source_table}] batch offset={offset} rows={len(rows)}') + print(' [' + source_table + '] batch offset=' + str(offset) + ' rows=' + str(len(rows))) for r in rows: r = DictObject(r) @@ -73,16 +73,21 @@ async def batch_sync_call_fact(sor, source_table, batch_size=1000): total_skipped += 1 continue + currency = getattr(r, 'amount_currency', None) or 'CNY' + amount = getattr(r, 'amount', 0) or 0 + userorgid = getattr(r, 'userorgid', None) + distributor_orgid = getattr(r, 'distributor_orgid', None) + ns = { 'id': getID(), 'luid': r.id, 'llmid': r.llmid, - 'model': r.llm_model, + 'model': r.llm_model or '', 'catelogid': r.catelogid or '', - 'userid': r.userid, - 'userorgid': r.userorgid, - 'ownerid': r.ownerid, - 'providerid': r.providerid, + 'userid': r.userid or '', + 'userorgid': userorgid or '', + 'ownerid': r.ownerid or '', + 'providerid': r.providerid or '', 'call_date': r.use_date or call_time.strftime('%Y-%m-%d'), 'call_hour': call_time.hour, 'call_time': r.use_time, @@ -91,15 +96,18 @@ async def batch_sync_call_fact(sor, source_table, batch_size=1000): 'prompt_tokens': prompt_tokens, 'completion_tokens': completion_tokens, 'status': r.status or 'SUCCEEDED', - 'amount': r.amount or 0, - 'currency': getattr(r, 'amount_currency', None) or 'CNY', + 'amount': amount, + 'currency': currency, + 'amount_cny': amount, + 'distributor_orgid': distributor_orgid or '', + 'sale_userid': '', } await sor.C('dm_model_call_fact', ns) total_inserted += 1 offset += batch_size - print(f' [{source_table}] done: inserted={total_inserted}, skipped={total_skipped}') + print(' [' + source_table + '] done: inserted=' + str(total_inserted) + ', skipped=' + str(total_skipped)) return total_inserted, total_skipped @@ -112,7 +120,7 @@ async def batch_aggregate_history(sor): {} ) dates = [r['call_date'].strftime('%Y-%m-%d') if hasattr(r['call_date'], 'strftime') else str(r['call_date']) for r in rows] - print(f' aggregating {len(dates)} distinct dates...') + print(' aggregating ' + str(len(dates)) + ' distinct dates...') for d in dates: await aggregate_daily_perf(sor, stat_date=d)