This commit is contained in:
wuaho 2021-06-25 18:49:35 +08:00
parent c28d32491a
commit 0888cc88fc
2 changed files with 10 additions and 5 deletions

View File

@ -369,17 +369,19 @@ async def scatter_model(
resp['label'].append(f'[{quota_interval_arr[i]},{v})')
bins.append(v)
summary_data = None
# todo 整体的,需要补充分组的
for key, tmp_df in df.groupby('date'):
bins_s = pd.cut(tmp_df['values'], bins=bins,
right=False).value_counts()
bins_s.sort_index(inplace=True)
total = int(bins_s.sum())
resp['list'][key.strftime('%Y-%m-%d')] = {'n': bins_s.to_list(), 'total': total,
'p': round(bins_s * 100 / total, 2).to_list()}
'p': round(bins_s * 100 / total, 2).to_list()}
return schemas.Msg(code=0, msg='ok', data=resp)
if interval_type == 'def' and analysis == 'number_of_days':
resp = {}
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}

View File

@ -299,12 +299,15 @@ ORDER BY level
event_name_col == event_name
]
values_col = func.count().label('values')
if analysis in ['number_of_days', 'number_of_hours']:
values_col = func.count(func.distinct(e_account_id_col)).label('values')
if analysis in ['times', 'number_of_days', 'number_of_hours']:
qry = sa.select(event_date_col, func.count().label('values')) \
qry = sa.select(event_date_col, values_col) \
.where(and_(*where)) \
.group_by(event_date_col, e_account_id_col)
.group_by(event_date_col, *self.groupby, e_account_id_col)
sql = str(qry.compile(compile_kwargs={"literal_binds": True}))
print(sql)
@ -319,7 +322,7 @@ ORDER BY level
qry = sa.select(event_date_col, settings.CK_FUNC[analysis](event_attr_col).label('values')) \
.where(and_(*where)) \
.group_by(event_date_col, e_account_id_col)
.group_by(event_date_col, *self.groupby, e_account_id_col)
sql = str(qry.compile(compile_kwargs={"literal_binds": True}))
print(sql)
return {