From aced6844d31e67c026a72d66e242cf7586a90c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= <250213850@qq.com> Date: Thu, 21 Apr 2022 11:02:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E4=BA=8B=E4=BB=B6=E5=88=86?= =?UTF-8?q?=E6=9E=90=E4=B8=AD=E5=8A=A0=E5=87=8F=E4=B9=98=E9=99=A4=E7=9A=84?= =?UTF-8?q?=E8=BF=90=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/behavior_analysis.py | 42 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) 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(