This commit is contained in:
wuaho 2021-10-13 15:21:36 +08:00
parent 93272cd1f1
commit 5f38bd20a1
2 changed files with 31 additions and 13 deletions

View File

@ -740,6 +740,9 @@ async def scatter_model(
for i, v in enumerate(quota_interval_arr[1:]):
resp['label'].append(f'[{quota_interval_arr[i]},{v})')
bins.append(v)
# 合计的
if res['time_particle'] == 'total':
df['date'] = '合计'
# 这是整体的
for key, tmp_df in df.groupby('date'):
@ -747,6 +750,12 @@ async def scatter_model(
right=False).value_counts()
bins_s.sort_index(inplace=True)
total = int(bins_s.sum())
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(),

View File

@ -625,7 +625,11 @@ ORDER BY level
values_col = func.count(func.distinct(e_account_id_col)).label('values')
if analysis in ['times', 'number_of_days', 'number_of_hours']:
if self.time_particle == 'total':
qry = sa.select( *self.groupby, values_col) \
.where(and_(*where)) \
.group_by( *self.groupby)
else:
qry = sa.select(event_date_col, *self.groupby, values_col) \
.where(and_(*where)) \
.group_by(event_date_col, *self.groupby)
@ -644,7 +648,12 @@ ORDER BY level
}
elif event.get('quota'):
event_attr_col = getattr(self.event_tbl.c, event['quota'])
if self.time_particle == 'total':
qry = sa.select( e_account_id_col,
settings.CK_FUNC[analysis](event_attr_col).label('values')) \
.where(and_(*where)) \
.group_by( *self.groupby, e_account_id_col)
else:
qry = sa.select(event_date_col, e_account_id_col,
settings.CK_FUNC[analysis](event_attr_col).label('values')) \
.where(and_(*where)) \