From 20ea6efd44cbfee1972185cf1026dd293aeeb8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= <250213850@qq.com> Date: Mon, 26 Sep 2022 17:09:58 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E4=BA=8B=E4=BB=B6=E5=88=86?= =?UTF-8?q?=E6=9E=90int=E7=B1=BB=E5=9E=8B=E5=88=86=E7=BB=84=E6=8C=89?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E5=A4=A7=E5=B0=8F=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api_v1/endpoints/query.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/api/api_v1/endpoints/query.py b/api/api_v1/endpoints/query.py index c1970a7..5c040a7 100644 --- a/api/api_v1/endpoints/query.py +++ b/api/api_v1/endpoints/query.py @@ -438,7 +438,33 @@ async def event_model( item['sum'] = np.array(item['sum'])[sort_key].tolist() item['avg'] = np.array(item['avg'])[sort_key].tolist() res = [item for idx, item in enumerate(res) if idx not in is_hide] - + # 对单个为int的分组进行排序 + if analysis.event_view.get('groupBy','') !=[] and analysis.event_view.get('groupBy','') != '': + if analysis.event_view.get('groupBy','')[0]['data_type'] == 'int' and len(analysis.event_view.get('groupBy','')) == 1 and len(res[0]['groups']) > 1: + short_list = sorted([ast.literal_eval(i)[0] for i in res[0]['groups']]) + idx_list = [] + for date in res[0]['groups']: + for id, i in enumerate(short_list): + if date == f'[{i}]': + idx_list.append(id) + break + for i in ['groups', 'values', 'sum', 'avg']: + ad = [0 for nu in range(len(idx_list))] + for idx, ii in enumerate(idx_list): + ad[ii] = res[0][i][idx] + res[0][i] = ad + # 计算每一天的总和 + # if res[0]['event_name'] == '充值排行': + # zong=[] + # lens=len(res[0]['date_range']) + # for nu in range(lens): + # aa=0 + # for value in res[0]['values']: + # aa+=value[nu] + # zong.append(aa) + # res[0]['zong']=zong + # else: + # res[0]['zong'] = [] return schemas.Msg(code=0, msg='ok', data=res) @@ -1887,6 +1913,11 @@ async def scatter_model( ac = ast.literal_eval(i) ab = [str(ii) for ii in ac] groupby_data.append(ab) + # if not isinstance(ac,int): + # ab = [str(ii) for ii in ac] + # groupby_data.append(ab) + # else: + # groupby_data.append(ac) resp['groupby_data'] = groupby_data return schemas.Msg(code=0, msg='ok', data=resp) else: