分布合计导出
This commit is contained in:
parent
26f63b6f68
commit
4e3eca48a4
@ -612,6 +612,9 @@ async def retention_model_export(request: Request,
|
||||
analysis = res['analysis']
|
||||
groupby = res['groupby']
|
||||
quota_interval_arr = res['quota_interval_arr']
|
||||
# 兼容合计的
|
||||
if res['time_particle'] == 'total':
|
||||
df['date'] = '合计'
|
||||
if analysis != 'number_of_days' and interval_type != 'discrete':
|
||||
max_v = int(df['values'].max())
|
||||
min_v = int(df['values'].min())
|
||||
@ -639,10 +642,17 @@ async def retention_model_export(request: Request,
|
||||
right=False).value_counts()
|
||||
bins_s.sort_index(inplace=True)
|
||||
total = int(bins_s.sum())
|
||||
resp['list'][key.strftime('%Y-%m-%d')] = dict()
|
||||
resp['list'][key.strftime('%Y-%m-%d')]['总体'] = {'n': bins_s.to_list(), 'total': total,
|
||||
'p': round(bins_s * 100 / total, 2).to_list(),
|
||||
'title': '总体'}
|
||||
if res['time_particle'] == 'total':
|
||||
resp['list']['合计'] = dict()
|
||||
resp['list']['合计']['总体'] = {'n': bins_s.to_list(), 'total': total,
|
||||
'p': round(bins_s * 100 / total, 2).to_list(),
|
||||
'title': '总体'}
|
||||
else:
|
||||
resp['list'][key.strftime('%Y-%m-%d')] = dict()
|
||||
resp['list'][key.strftime('%Y-%m-%d')]['总体'] = {'n': bins_s.to_list(), 'total': total,
|
||||
'p': round(bins_s * 100 / total, 2).to_list(),
|
||||
'title': '总体'}
|
||||
|
||||
# 分组的
|
||||
if groupby:
|
||||
export_df = pd.DataFrame(columns=resp['label'])
|
||||
@ -675,12 +685,14 @@ async def retention_model_export(request: Request,
|
||||
'end_date': res['end_date'],
|
||||
'time_particle': res['time_particle']
|
||||
}
|
||||
total_dict = {}
|
||||
labels = [str(i) for i in sorted(df['values'].unique())]
|
||||
resp['label'] = labels
|
||||
for key, tmp_df in df.groupby(['date']):
|
||||
total = len(tmp_df)
|
||||
dt = key.strftime('%Y-%m-%d')
|
||||
if res['time_particle'] == 'total':
|
||||
dt = '合计'
|
||||
else:
|
||||
dt = key.strftime('%Y-%m-%d')
|
||||
labels_dict = {}
|
||||
for key2, tmp_df2 in tmp_df.groupby('values'):
|
||||
label = str(key2)
|
||||
|
Loading…
Reference in New Issue
Block a user