Pārlūkot izejas kodu

MOD:添加注册人数,创角人数

cxyu 3 gadi atpakaļ
vecāks
revīzija
b42e6f1e5b
2 mainītis faili ar 50 papildinājumiem un 24 dzēšanām
  1. 41 17
      app/etl/data_stat_task.py
  2. 9 7
      app/etl/dw/dw_channel_daily.py

+ 41 - 17
app/etl/data_stat_task.py

@@ -1,6 +1,8 @@
 from model.DataBaseUtils import MysqlUtils, CkUtils
+from datetime import datetime, timedelta, timezone
 from model.DateUtils import DateUtils
 import logging
+import time
 
 db = MysqlUtils()
 ck = CkUtils()
@@ -78,7 +80,13 @@ def platform_data_sum(ymd):
 
 def dw_daily_channel_cost(ymd):
     logging.info("run> dw_daily_channel_cost")
-    sql = """
+    datatime_ymd = datetime.strptime(ymd, '%Y-%m-%d').astimezone(timezone(timedelta(hours=8))).timetuple()
+    timestamp_ymd = time.mktime(datatime_ymd)
+    tomorrow_ymd = (datetime.strptime(ymd, '%Y-%m-%d').astimezone(timezone(timedelta(hours=8))) + timedelta(
+        days=1)).timetuple()
+    timestamp_tom = time.mktime(tomorrow_ymd)
+
+    sql = f"""
         select x.dt,x.channel,pitcher,stage,x.platform,x.book,
                ifnull(view_count,0),ifnull(click_count,0),
                ifnull(follow_user,0),ifnull(cost,0)/100 as cost,
@@ -86,43 +94,60 @@ def dw_daily_channel_cost(ymd):
                ifnull(platform_view_count,0) platform_view_count,
                ifnull(web_order_count,0) web_order_count,
                if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP') type
-                ,0 require_roi,0 require_mult
+                ,0 require_roi,0 require_mult,ifnull(y.create_user_num,0)
                  from
         ( select dt, channel,stage,pitcher,platform,book  from channel_info_daily cid 
-            where dt='{0}' and channel !=''
+            where dt='{ymd}' and channel !=''
             and channel in 
             (select distinct(channel) from channel_by_account_daily cbad 
-            where dt='{0}'
+            where dt='{ymd}'
             and (type ='GDT' or type='MP')
             ) 
         ) x  -- 只允许渠道MP、GDT
         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
+        (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
          from
-            (select account_id,cost,view_count,valid_click_count,round(valid_click_count*official_account_follow_rate,0) as from_follow_uv,
+            (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,
             0 as platform_view_count,
             0 as web_order_count
-             from daily_vx where date='{0} 00:00:00'
+             from daily_vx where date='{ymd} 00:00:00'
             union
             select account_id,cost,view_count,valid_click_count,from_follow_uv,
             ifnull(web_commodity_page_view_count,0) as  web_view_count, 
             ifnull(platform_page_view_count,0) as platform_view_count,
             ifnull(web_order_count,0) as web_order_count
-             from daily_qq where date='{0} 00:00:00' ) a
+             from daily_qq where date='{ymd} 00:00:00' ) a
         left join
-        (select account_id,channel from channel_by_account_daily where dt='{0}') b 
+        (select account_id,channel from channel_by_account_daily where dt='{ymd}') b 
          on a.account_id=b.account_id  group by channel) 
         z on x.channel=z.channel  
       
-       
-        
+       left join     
+        (
+        select c.name as channel ,DATE(FROM_UNIXTIME(origin.create_time)) as wx_date,
+        count(*) as create_user_num
+        from 
+        db_mp.h_member origin left join
+        db_mp.mp_conf_agent a  on origin.app_id =a.app_id and origin.agent_id = a.agent_id 
+        left join
+        db_mp.mp_mp_conf b on a.advertiser_conf_id =b.id
+        left join 
+        quchen_text.advertiser_vx c on b.mp_id =c.wechat_account_id 
+        where c.wechat_account_id is not null
+        and origin.create_time > {timestamp_ymd} and origin.create_time < {timestamp_tom}
+        group by name,wx_date
+        ) y on x.channel= y.channel
         
-        """.format(ymd)
+        """
     data = db.quchen_text.get_data_list(sql)
     data1 = []
-    col = "dt,channel,pitcher,stage,platform,book,view_count,click_count,follow_user,cost,web_view_count,platform_view_count,web_order_count,type,require_roi,require_mult"
+    col = "dt,channel,pitcher,stage,platform,book,view_count,click_count,follow_user,cost,web_view_count,platform_view_count,web_order_count,type,require_roi,require_mult,create_user_num"
     for i in data:
         i[0] = str(i[0])
         i[9] = str(i[9])
@@ -256,9 +281,8 @@ if __name__ == '__main__':
     # channel_info_daily('2021-02-06')
 
     # channel_by_account_daily('2021-02-05')
-    for i in dt.getDateLists('2021-09-11', '2021-10-27'):
-        print(i)
-        channel_info_daily(i)
+    for i in dt.getDateLists('2021-04-08', '2021-10-27'):
+        # channel_info_daily(i)
 
         dw_daily_channel_cost(i)
     # ods_order('2021-05-06')

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

@@ -17,7 +17,7 @@ def dw_channel():
 select
        dt1,channel1,pitcher,stage,platform,book,
        if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP'),
-       order_count,order_user,order_amount,
+       order_count,create_user_num,reg_num,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 +30,7 @@ select
 from (
     select 
     if(dt4='1970-01-01',dt,dt4) dt1,if(channel4='',channel,channel4) channel1,
-    pitcher,stage,platform,book,cost,view_count,click_count,   ---基础属性和消耗数据
+    create_user_num,reg_num,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
 
@@ -51,7 +51,8 @@ left outer join (
            sum(if(user_order_count>=5,1,0)) reg_order_user_again5,
            sum(if(user_order_count>=6,1,0)) reg_order_user_again6
     from (select formatDateTime(reg_time,'%Y-%m-%d') reg_date,channel,count(1) user_order_count
-    from game_data.order where status=2  group by formatDateTime(reg_time,'%Y-%m-%d') ,user_id,channel) x group by reg_date,channel
+    from game_data.order where status=2  group by formatDateTime(reg_time,'%Y-%m-%d') ,user_id,channel) x
+     group by reg_date,channel
     ) f on dt1=dt6 and channel1=channel6
 
 left outer join
@@ -61,7 +62,8 @@ left outer join
    sum(amount) as reg_order_amount,
    count(distinct user_id) as reg_order_user,
    count(1) as reg_order_count
-   from game_data.order where status=2 and reg_time>'2019-03-18 00:00:00' group by toDate(formatDateTime(reg_time,'%Y-%m-%d')),channel) b
+   from game_data.order where status=2 and reg_time>'2019-03-18 00:00:00' 
+   group by toDate(formatDateTime(reg_time,'%Y-%m-%d')),channel) b
     on dt1=dt2 and channel1=channel2
 left outer join
      (select date as dt3,channel as channel3,count(1) as first_order_count,          ---新用户首日充值
@@ -72,7 +74,7 @@ left outer join
     having order_amount+cost+reg_order_amount>0"""
 
     data = ck.execute(sql)
-    isql = "replace into dw_channel 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)"
+    isql = "replace into dw_channel 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)"
     # db.dm.execute("truncate table dw_channel")
     db.dm.executeMany(isql, data)
 
@@ -246,9 +248,9 @@ def dw_channel_daily():
 
 
 if __name__ == '__main__':
-    dw_channel_daily()
+    # dw_channel_daily()
     # dw_daily_channel()
-    # dw_channel()
+    dw_channel()
     # dw_channel_amount_daily()
     # dw_channel_user_daily()
     # dw_channel_amount_daily_reverse()