diff --git a/models/behavior_analysis.py b/models/behavior_analysis.py index c4ec3d8..0d173e4 100644 --- a/models/behavior_analysis.py +++ b/models/behavior_analysis.py @@ -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(