ck hace 4 años
padre
commit
d7c29ec387
Se han modificado 2 ficheros con 24 adiciones y 5 borrados
  1. 23 4
      app/etl/data_stat_task.py
  2. 1 1
      app/etl/dw/dw_channel_daily.py

+ 23 - 4
app/etl/data_stat_task.py

@@ -17,12 +17,13 @@ def dw_daily_channel_cost(ymd):
                ifnull(web_view_count,0) web_view_count,
                ifnull(platform_view_count,0) platform_view_count,
                ifnull(web_order_count,0) web_order_count,
-               ifnull(type,''),0 require_roi,0 require_mult
+               if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP') type
+                ,0 require_roi,0 require_mult
                  from
         (select dt,channel,stage,pitcher,platform,book from channel_info_daily where dt='{0}' and channel!='' ) x  
         left join
         (select channel,sum(cost) as cost,sum(view_count) as view_count,sum(valid_click_count) as click_count,sum(from_follow_uv)  as follow_user,
-         sum(web_view_count) as web_view_count,sum(platform_view_count) as platform_view_count,sum(web_order_count) as web_order_count,type
+         sum(web_view_count) as web_view_count,sum(platform_view_count) as platform_view_count,sum(web_order_count) as web_order_count
          from
             (select account_id,cost,view_count,valid_click_count,round(valid_click_count*official_account_follow_rate,0) as from_follow_uv,
             0 as  web_view_count,
@@ -36,9 +37,12 @@ def dw_daily_channel_cost(ymd):
             ifnull(web_order_count,0) as web_order_count
              from daily_qq where date='{0} 00:00:00' ) a
         left join
-        (select account_id,channel,type from channel_by_account_daily where dt='{0}') b 
+        (select account_id,channel from channel_by_account_daily where dt='{0}') b 
          on a.account_id=b.account_id  group by channel) 
         z on x.channel=z.channel  
+      
+       
+        
         
         """.format(ymd)
     data=db.quchen_text.get_data_list(sql)
@@ -118,6 +122,11 @@ def channel_info_daily(ymd):
                                            "where start_time<='{}' GROUP BY name) a "
                                            "left join book_change  b on  a.start_time=b.start_time and a.name=b.name".format(ymd))
 
+    stage_change = db.quchen_text.getData(
+        "select  channel,stage from (select max(start_date) as start_date,channel from stage_change "
+        "where start_date<='{}' GROUP BY channel) a "
+        "left join stage_change using(start_date,channel)".format(ymd))
+
     for i in data:
         for j in pitcher_change:
             if i[1]==j[0]:
@@ -129,7 +138,15 @@ def channel_info_daily(ymd):
         for h in book_change:
             if i[1]==h[0]:
                 i[5]=h[1]
-    # print(data)
+
+        for m in stage_change:
+            if i[1] ==m[0]:
+                i[2]=m[1]
+
+
+
+
+
     insert_sql="replace into channel_info_daily values (%s,%s,%s,%s,%s,%s) "
 
     db.quchen_text.executeMany(insert_sql,data)
@@ -161,6 +178,8 @@ def order_account_text():
             db.quchen_text.execute("insert into order_account_text(platform,text) values ('文鼎','{}')".format(i))
 
 if __name__ == '__main__':
+    channel_info_daily('2021-02-06')
+
     channel_by_account_daily('2021-02-05')
     # for i in dt.getDateLists('2020-04-23','2021-02-05'):
     #     print(i)

+ 1 - 1
app/etl/dw/dw_channel_daily.py

@@ -73,7 +73,7 @@ select formatDateTime(reg_time,'%Y-%m-%d') reg_date,channel,count(1) user_order_
 def dw_channel_daily():
     sql="""
 select
-       dt,channel,pitcher,stage,platform,book,case type when 'vx' then 'MP' when 'qq' then 'GDT' else type end type,
+       dt,channel,pitcher,stage,platform,book,if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP') type,
        order_count,order_user,order_amount,
        first_order_count,first_order_user,first_order_amount,
        view_count,click_count,follow_user,