From ed5055e2e26a7af8d260837f883ffb4f8eba4f12 Mon Sep 17 00:00:00 2001 From: wuaho Date: Mon, 30 Aug 2021 17:30:31 +0800 Subject: [PATCH] 1 --- api/api_v1/endpoints/dashboard.py | 4 +++- api/api_v1/endpoints/query.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/api_v1/endpoints/dashboard.py b/api/api_v1/endpoints/dashboard.py index bd34c1c..cf13160 100644 --- a/api/api_v1/endpoints/dashboard.py +++ b/api/api_v1/endpoints/dashboard.py @@ -108,7 +108,9 @@ async def copy( try: await crud.report.insert_one(db, new_report) except: - pass + exists_report = await crud.report.find_one(db, {'project_id': item['project_id'], + 'user_id': item['user_id'], 'name': report['name']}) + report['report_id'] = exists_report['_id'] try: await crud.dashboard.update_one(db, {'project_id': item['project_id'], 'name': item['name'], diff --git a/api/api_v1/endpoints/query.py b/api/api_v1/endpoints/query.py index 6cdc330..5525531 100644 --- a/api/api_v1/endpoints/query.py +++ b/api/api_v1/endpoints/query.py @@ -226,6 +226,8 @@ async def retention_model(request: Request, res = analysis.retention_model_sql2() sql = res['sql'] df = await ckdb.query_dataframe(sql) + if len(df) == 0: + return schemas.Msg(code=-1, msg='无数据', data=None) title = f'用户数' date_range = res['date_range'] @@ -556,7 +558,7 @@ async def scatter_model( if interval_type == 'def' and analysis == 'number_of_days': resp = {'list': {}} for key, tmp_df in df.groupby('date'): - total = round(tmp_df['values'].sum(),2) + total = round(tmp_df['values'].sum(), 2) resp['list'][key.strftime('%Y-%m-%d')] = {'n': total, 'total': total, 'p': 100} return schemas.Msg(code=0, msg='ok', data=resp)