1.新增事件分析中加减乘除的运算

This commit is contained in:
李伟 2022-04-21 11:02:14 +08:00
parent bbbfa90275
commit aced6844d3

View File

@ -381,8 +381,8 @@ class BehaviorAnalysis:
async def event_model_sql(self):
sqls = []
event_time_col = getattr(self.event_tbl.c, '#event_time')
for event in self.events:
operator_ = event.get('operator_val','')
event_name_display = event.get('eventNameDisplay')
is_show = event.get('is_show', True)
@ -450,19 +450,35 @@ class BehaviorAnalysis:
# 按账号聚合
e_account_id_col = getattr(self.event_tbl.c, '#account_id')
# 聚合方式
if analysis == 'total_count':
selectd = select_exprs + [func.count().label('values')]
elif analysis == 'touch_user_count':
selectd = select_exprs + [func.count(sa.distinct(e_account_id_col)).label('values')]
elif analysis == 'touch_user_avg':
selectd = select_exprs + [
func.round((func.count() / func.count(sa.distinct(e_account_id_col))), 2).label(
'values')]
if operator_ == '':
# 聚合方式
if analysis == 'total_count':
selectd = select_exprs + [func.count().label('values')]
elif analysis == 'touch_user_count':
selectd = select_exprs + [func.count(sa.distinct(e_account_id_col)).label('values')]
elif analysis == 'touch_user_avg':
selectd = select_exprs + [
func.round((func.count() / func.count(sa.distinct(e_account_id_col))), 2).label(
'values')]
else:
selectd = select_exprs + [
func.round(getattr(func, analysis)(getattr(self.event_tbl.c, event['event_attr_id'])), 2).label(
'values')]
else:
selectd = select_exprs + [
func.round(getattr(func, analysis)(getattr(self.event_tbl.c, event['event_attr_id'])), 2).label(
'values')]
operator_val=int(operator_)
operator=event['operator'] #运算符号
if analysis == 'total_count':
selectd = select_exprs + [settings.ARITHMETIC[operator](func.count(),operator_val).label('values')]
elif analysis == 'touch_user_count':
selectd = select_exprs + [settings.ARITHMETIC[operator](func.count(sa.distinct(e_account_id_col)),operator_val).label('values')]
elif analysis == 'touch_user_avg':
selectd = select_exprs + [
settings.ARITHMETIC[operator](func.round((func.count() / func.count(sa.distinct(e_account_id_col))), 2),operator_val).label(
'values')]
else:
selectd = select_exprs + [
settings.ARITHMETIC[operator](func.round(getattr(func, analysis)(getattr(self.event_tbl.c, event['event_attr_id'])), 2),operator_val).label(
'values')]
if user_filter:
qry = sa.select(selectd).select_from(