ck %!s(int64=4) %!d(string=hai) anos
pai
achega
78f14a24f8
Modificáronse 2 ficheiros con 19 adicións e 11 borrados
  1. 16 9
      app/etl/data_stat_task.py
  2. 3 2
      app/etl/sync_to_ck_task.py

+ 16 - 9
app/etl/data_stat_task.py

@@ -147,7 +147,7 @@ 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,total_cost,total_amount
+       web_view_count,platform_view_count,web_order_count,total_cost,total_amount,reg_order_user2
 from
 (select dt,channel, pitcher,stage,platform,book,cost,view_count,click_count,follow_user,web_view_count,platform_view_count,web_order_count from dw_daily_channel_cost) a
     left outer join
@@ -173,7 +173,14 @@ from
         on dt=dt4 and channel=channel4
 left outer join
      (select dt dt5,channel channel5,total_cost,total_amount from dw_channel_daily_total ) e
-         on dt=dt5 and channel=channel5   
+         on dt=dt5 and channel=channel5
+
+left outer join (
+select sum(if(user_order_count>1,1,0)) reg_order_user2,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
         """
     ck.execute("truncate table dw_daily_channel")
     ck.execute(sql)
@@ -251,14 +258,13 @@ having pitcher != ''"""
 
 
 def dw_channel_daily_total(ymd):
-    """每天的公众号数据 (不包含向后数据)"""
     sql=f"""insert into dw_channel_daily_total
             select '{ymd}' dt,channel,total_cost,total_amount from
             (select channel,sum(cost) total_cost  from dw_daily_channel_cost where  dt<='{ymd}'  group by channel)a
             left outer join
             (select  channel,sum(amount) total_amount  from order where date<='{ymd}' group by channel) b
              on a.channel=b.channel"""
-    ck.execute(f"alter table dm_pitcher_daily_page_total drop partition '{ymd}'")
+    ck.execute(f"alter table dw_channel_daily_total drop partition '{ymd}'")
     ck.execute(sql)
 
 if __name__ == '__main__':
@@ -274,11 +280,12 @@ if __name__ == '__main__':
     # dm_pitcher_daily_page_total()
     # dw_channel_daily_total('2020-12-28')
     # exit(0)
-
-    for i in dt.getDateLists('2019-03-18','2021-01-04'):
+    dw_daily_channel()
+    exit(0)
+    for i in dt.getDateLists('2019-03-18','2021-01-05'):
         print(i)
         # ods_order(i)
         # channel_info_daily(i)
-        dw_daily_channel_cost(i)
-        dw_order_channel_cost_sync_ck(i)
-
+        # dw_daily_channel_cost(i)
+        # dw_order_channel_cost_sync_ck(i)
+        dw_channel_daily_total(i)

+ 3 - 2
app/etl/sync_to_ck_task.py

@@ -19,6 +19,7 @@ def order_sync_ck(ymd):
         li = list(x)
 
         li[0]=str(li[0])
+        li[3]='' if li[3]==None else li[3]
         li[5]='' if li[5]==None else li[5]
         li[6]=str(li[6])
         li[7]='0000-00-00 00:00:00' if li[7]==None else str(li[7])
@@ -83,8 +84,8 @@ def dw_order_channel_cost_sync_ck(ymd):
 
 
 if __name__ == '__main__':
-    order_sync_ck('2020-12-20')
-    dw_order_channel_cost_sync_ck(dt.get_n_days(-2))
+    order_sync_ck('2020-12-23')
+    # dw_order_channel_cost_sync_ck(dt.get_n_days(-2))
     # for i in dt.getDateLists('2019-03-18','2020-12-17'):
     # #     order(i)
     #     dw_order_channel_sync_ck(i)