离散分布
This commit is contained in:
parent
5a6bd4ea02
commit
01600069d6
@ -606,7 +606,7 @@ async def scatter_model(
|
||||
analysis = res['analysis']
|
||||
groupby = res['groupby']
|
||||
quota_interval_arr = res['quota_interval_arr']
|
||||
if analysis != 'number_of_days':
|
||||
if analysis != 'number_of_days' and interval_type != 'discrete':
|
||||
max_v = int(df['values'].max())
|
||||
min_v = int(df['values'].min())
|
||||
interval = (max_v - min_v) // 10 or 1
|
||||
@ -655,10 +655,25 @@ async def scatter_model(
|
||||
|
||||
# elif analysis == 'number_of_days':
|
||||
else:
|
||||
resp = {'list': {}}
|
||||
for key, tmp_df in df.groupby('date'):
|
||||
total = int(tmp_df['values'].sum())
|
||||
resp['list'][key.strftime('%Y-%m-%d')] = {'n': total, 'total': total, 'p': 100}
|
||||
resp = {'list': {}, 'label': [],
|
||||
'start_date': res['start_date'],
|
||||
'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')
|
||||
labels_dict = {}
|
||||
for key2, tmp_df2 in tmp_df.groupby('values'):
|
||||
label = str(key2)
|
||||
n = len(tmp_df2)
|
||||
labels_dict[label] = n
|
||||
|
||||
resp['list'][dt] = {'总体': {'n': [labels_dict.get(i, 0) for i in labels], 'total': total,
|
||||
'p': [round(labels_dict.get(i, 0)*100 / total, 2) for i in labels]}}
|
||||
return schemas.Msg(code=0, msg='ok', data=resp)
|
||||
|
||||
# bins_s = pd.cut(tmp_df['values'], bins=bins,
|
||||
|
Loading…
Reference in New Issue
Block a user