ck hace 4 años
padre
commit
24c8ea7609
Se han modificado 1 ficheros con 11 adiciones y 69 borrados
  1. 11 69
      app/etl/dw/dw_channel_daily.py

+ 11 - 69
app/etl/dw/dw_channel_daily.py

@@ -1,76 +1,17 @@
 """
-@desc 号维度全量表 ck上跑完dw_daily_channel 并同步到mysql dw_channel_daily
+@desc  公众号维度的数据处理
+
 @auth ck
 """
 import time
 from model.DateUtils import DateUtils
 from model.DataBaseUtils import MysqlUtils,CkUtils
 du = DateUtils()
-db= MysqlUtils()
+db = MysqlUtils()
 ck = CkUtils()
 
 
-def dw_daily_channel():
-    print("run> dw_daily_channel")
-
-    sql="""insert into dw_daily_channel
-select
-       dt,channel,pitcher,stage,platform,book,
-       order_count,order_user,order_amount,first_order_count,first_order_user,first_order_amount,
-       view_count,click_count,follow_user,cost,reg_order_count,reg_order_user,
-       reg_order_amount,reg_order_amount30,web_view_count,platform_view_count,web_order_count,
-       0 total_cost,0 total_amount,
-       reg_order_user_again,reg_order_user7,reg_order_user30,reg_order_amount7,type,
-       0 total_first_amount,
-       require_roi,require_mult
-from
-(select dt,channel, pitcher,stage,platform,book,cost,view_count,click_count,follow_user,web_view_count,platform_view_count,web_order_count,
-case type when 'vx' then 'MP' when 'qq' then 'GDT' else type end type,require_roi,require_mult from dw_daily_channel_cost) a
-    left outer join
-    (select toDate(formatDateTime(reg_time,'%Y-%m-%d')) as dt2,channel as channel2,
-       sum(amount) as reg_order_amount,
-       count(distinct user_id) as reg_order_user,
-       count(1) as reg_order_count,
-       sum(if(subtractDays(date, 30)>reg_time,0,amount)) as reg_order_amount30,
-       count(distinct if(subtractDays(date, 7)>reg_time,'',user_id))-1 reg_order_user7,
-       sum(if(subtractDays(date, 7)>reg_time,0,amount)) as reg_order_amount7,
-       count(distinct if(subtractDays(date, 30)>reg_time,'',user_id))-1 reg_order_user30
-       from order where reg_time>'2019-03-18 00:00:00' group by toDate(formatDateTime(reg_time,'%Y-%m-%d')),channel) b
-        on dt=dt2 and channel=channel2 left outer join
-     (select date as dt3,channel as channel3,
-     count(1) as first_order_count,
-        count(distinct user_id) as first_order_user,
-             sum(amount) as first_order_amount
-       from order where toDate(reg_time)=date  group by date,channel) c
-        on dt=dt3 and channel=channel3
-    left outer join
-    (select date as dt4,channel as channel4,
-     count(1) as order_count,
-        count(distinct user_id) as order_user,
-             sum(amount) as order_amount
-       from order  group by date,channel) d
-        on dt=dt4 and channel=channel4
-left outer join (
-select sum(if(user_order_count>1,1,0)) reg_order_user_again,channel channel6,toDate(reg_date) dt6  from (
-select formatDateTime(reg_time,'%Y-%m-%d') reg_date,channel,count(1) user_order_count
-    from order group by formatDateTime(reg_time,'%Y-%m-%d') ,user_id,channel
-    ) x group by reg_date,channel
-    ) f on dt=dt6 and channel=channel6
-    having order_amount+cost+reg_order_amount>0
-        """
-    ck.execute("truncate table dw_daily_channel")
-    ck.execute(sql)
-    print("ok")
-
-    data=ck.execute('select * from dw_daily_channel')
-    insert_sql="insert into dw_channel_daily values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
-
-    db.quchen_text.execute("truncate table dw_channel_daily")
-    db.quchen_text.executeMany(insert_sql,data)
-
-
-
-def dw_channel_daily():
+def dw_channel():
     sql="""
 select
        dt,channel,pitcher,stage,platform,book,if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP') type,
@@ -128,6 +69,7 @@ left outer join
     db.dm.execute("truncate table dw_channel")
     db.dm.executeMany(isql,data)
 
+
 def dw_channel_user_daily():
     sql="""
 select toDate(formatDateTime(reg_time,'%Y-%m-%d')) as dt,
@@ -172,6 +114,7 @@ from order where reg_time>'2019-03-18 00:00:00' group by toDate(formatDateTime(r
     db.dm.execute("truncate table dw_channel_user_daily")
     db.dm.executeMany(isql,data)
 
+
 def dw_channel_amount_daily():
     sql="""
   select toDate(formatDateTime(reg_time,'%Y-%m-%d')) as dt,
@@ -247,7 +190,6 @@ def dw_channel_amount_daily():
     db.dm.executeMany(isql,data)
 
 
-
 def dw_channel_amount_daily_reverse():
     sql = """
      select toDate(formatDateTime(reg_time,'%Y-%m-%d')) as dt,
@@ -274,11 +216,11 @@ def del_channel():
 
 def dw_channel():
     print('run> dw_channel')
-    dw_channel_daily()
-    dw_channel_user_daily()
-    dw_channel_amount_daily()
-    dw_channel_amount_daily_reverse()
-    del_channel()
+    dw_channel()   # 公众号基本数据
+    dw_channel_user_daily()  # 用户激活
+    dw_channel_amount_daily()  # 用户充值
+    dw_channel_amount_daily_reverse()  # 用户充值倒序
+    del_channel()  # 删除代投的号
 
 if __name__ == '__main__':