Przeglądaj źródła

MOD:dw_channel添加留存

cxyu 3 lat temu
rodzic
commit
0cd8e31a74
2 zmienionych plików z 21 dodań i 12 usunięć
  1. 14 10
      app/etl/data_stat_task.py
  2. 7 2
      app/etl/dw/dw_channel_daily.py

+ 14 - 10
app/etl/data_stat_task.py

@@ -134,11 +134,14 @@ def dw_daily_channel_cost(ymd):
         
         left join
         (
-        select   h.name as channel ,
-if(d.ct=0,0,ifnull(e.ct,0)/d.ct) as today_active_user_rate,
-if(a.ct=0,0,ifnull( b.ct,0)/a.ct) as second_stay_rate,
-if(a.ct=0,0,ifnull(c.ct,0)/a.ct) as third_stay_rate,
-d.ct game_user_sum
+        select channel ,
+if(sum(d_ct)=0,0,ifnull(sum(e_ct),0)/sum(d_ct)) as today_active_user_rate,
+if(sum(a_ct)=0,0,ifnull(sum(b_ct),0)/sum(a_ct)) as second_stay_rate,
+if(sum(a_ct)=0,0,ifnull(sum(c_ct),0)/sum(a_ct)) as third_stay_rate,
+sum(d_ct) game_user_sum from 
+
+(select   h.name as channel ,
+a.ct as a_ct,b.ct as b_ct,c.ct as c_ct,d.ct as d_ct,e.ct as e_ct
 from 
 (select '{ymd}',a.app_id,a.agent_id,count(*) as ct from 
 db_mp.h_member  a 
@@ -174,12 +177,13 @@ left join
 left join db_mp.mp_conf_agent f on a.app_id =f.app_id and a.agent_id =f.agent_id 
 left join db_mp.mp_mp_conf g on f.advertiser_conf_id = g.id 
 left join quchen_text.advertiser_vx h on g.mp_id = h.wechat_account_id 
-where h.name is not null
-            ) v on x.channel= v.channel
-        
+where h.name is not null)  as keep_data
+group by channel)
+            v on x.channel= v.channel
         
         
         """
+    # print(sql)
     data = db.quchen_text.get_data_list(sql)
 
 
@@ -321,8 +325,8 @@ if __name__ == '__main__':
     # channel_info_daily('2021-02-06')
 
     # channel_by_account_daily('2021-02-05')
-    # dw_daily_channel_cost('2021-10-18')
-
+    dw_daily_channel_cost('2021-11-06')
+    exit()
     for i in dt.getDateLists('2021-09-08', '2021-11-02'):
         print(i)
         channel_info_daily(i)

+ 7 - 2
app/etl/dw/dw_channel_daily.py

@@ -17,7 +17,10 @@ def dw_channel():
 select
        dt1,channel1,pitcher,stage,platform,book,
        if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP'),
-       order_count,create_user_num,reg_num,order_user,order_amount,
+       order_count,create_user_num,reg_num,
+       game_user_sum,third_stay_rate,second_stay_rate,
+       today_active_user_rate,
+       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,
@@ -30,7 +33,9 @@ select
 from (
     select 
     if(dt4='1970-01-01',dt,dt4) dt1,if(channel4='',channel,channel4) channel1,
-    create_user_num,reg_num,pitcher,stage,platform,book,cost,view_count,click_count,   ---基础属性和消耗数据
+    create_user_num,reg_num,today_active_user_rate,second_stay_rate ,third_stay_rate ,
+    game_user_sum ,
+    pitcher,stage,platform,book,cost,view_count,click_count,   ---基础属性和消耗数据
         follow_user,web_view_count,platform_view_count,web_order_count,type,
         require_roi,require_mult,order_count,order_user,order_amount from