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: