ck 4 tahun lalu
induk
melakukan
ea401e8b01
2 mengubah file dengan 49 tambahan dan 50 penghapusan
  1. 45 15
      app/etl/data_stat_task.py
  2. 4 35
      app/etl/sync_to_ck_task.py

+ 45 - 15
app/etl/data_stat_task.py

@@ -72,17 +72,17 @@ def channel_info_daily(ymd):
 
     pitcher_change=db.quchen_text.getData(
                                           "select b.channel as channel,pitcher from "
-                                          "(select min(end_time) as end_time,channel from pitcher_change "
-                                     " where end_time>'{}' GROUP BY channel) a"
-                                     " left join pitcher_change  b on  a.end_time=b.end_time and a.channel=b.channel".format(ymd))
+                                          "(select max(start_time) as start_time,channel from pitcher_change "
+                                     " where start_time<='{}' GROUP BY channel) a"
+                                     " left join pitcher_change  b on  a.start_time=b.start_time and a.channel=b.channel".format(ymd))
 
-    platform_change=db.quchen_text.getData("select b.name as channel,primary_platform as platform from (select min(change_date) as change_date,name from platform_change "
-                                          "where change_date>'{}' GROUP BY name) a "
+    platform_change=db.quchen_text.getData("select b.name as channel,current_platform as platform from (select max(change_date) as change_date,name from platform_change "
+                                          "where change_date<='{}' GROUP BY name) a "
                                           "left join platform_change  b on  a.change_date=b.change_date and a.name=b.name".format(ymd))
 
-    book_change=db.quchen_text.getData("select b.name as channel,book from (select min(end_time) as end_time,name from book_change "
-                                           "where end_time>'{}' GROUP BY name) a "
-                                           "left join book_change  b on  a.end_time=b.end_time and a.name=b.name".format(ymd))
+    book_change=db.quchen_text.getData("select b.name as channel,book from (select max(start_time) as start_time,name from book_change "
+                                           "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))
 
     for i in data:
         for j in pitcher_change:
@@ -131,13 +131,43 @@ def order_account_text():
             db.quchen_text.execute("insert into order_account_text(platform,text) values ('文鼎','{}')".format(i))
 
 
+def update_dw_daily_channel_all(ymd):
+    """把某天的数据都捞出来 按照注册时间 更新前面日期的数据"""
+    # sql="""select DATE_FORMAT(reg_time,'%Y-%m-%d') as dt,count(1) as  reg_user_order_count,
+    #         count(DISTINCT user_id) as reg_user,
+    #         sum(amount) as reg_user_order_amount,
+    #         sum(if(DATE_ADD(reg_time,INTERVAL 30 day)<STR_TO_DATE('2020-12-16','%Y-%m-%d '),0,amount))
+    #         from ods_order where date='2020-12-16' GROUP BY DATE_FORMAT(reg_time,'%Y-%m-%d')
+    #         """
+    """"""
+    sql="select count(1) as reg_user_order_count," \
+        "       count(DISTINCT user_id) reg_user," \
+        "       sum(amount) as reg_user_order_amount," \
+        "       sum(if(DATE_SUB(date ,INTERVAL 30 day)>STR_TO_DATE('{0}','%Y-%m-%d '),0,amount)) as reg_user_order_amount30" \
+        "        from ods_order where DATE_FORMAT(reg_time,'%Y-%m-%d')='{0}'".format(ymd)
+    data=db.quchen_text.getData(sql)
+    print(data)
+    exit(0)
+
+    update_sql="update dw_daily_channel set reg_user_order_count={},reg_user={},reg_user_order_amount={},reg_user_order_amount30={} " \
+               " where  dt='{}'".format()
+
+
+
+
+
+
+
+
+
 
 if __name__ == '__main__':
     # dw_daily_channel('2020-12-14')
-    # channel_info_daily('2020-12-14')
-    for i in dt.getDateLists('2019-05-20','2020-12-16'):
-        print(i)
-        # channel_by_account_daily(i)
-        # channel_info_daily(i)
-        # dw_daily_channel(i)
-        clean_order(i)
+    # channel_info_daily('2020-12-07')
+    for i in dt.getDateLists('2019-03-18','2020-12-16'):
+    #     print(i)
+    #     # ods_order(i)
+    #     # channel_by_account_daily(i)
+          channel_info_daily(i)
+    #     dw_daily_channel(i)
+

+ 4 - 35
app/etl/sync_to_ck_task.py

@@ -17,7 +17,7 @@ def order(ymd):
 
     data = db.quchen_text.getData(sql)
 
-    # 掌中云时间格式转换
+    # # 掌中云时间格式转换
     data1 = []
     for x in data:
         li = list(x)
@@ -25,40 +25,8 @@ def order(ymd):
         li[0]=str(li[0])
         li[6]=str(li[6])
         li[7]=str(li[7])
+        li[9]='' if li[9]==None else li[9]
 
-        #
-        # li[6] = li[6].replace('T',' ').replace('+08:00','').replace('/','-')
-        #
-        # if li[6] == None or li[6] == '':
-        #     li[6] = '0000-00-00 00:00:00'
-        #
-        # if li[7]==None or li[7]=='':
-        #     li[7]='0000-00-00 00:00:00'
-        # else:
-        #     li[7] = li[7].replace('T',' ').replace('+08:00','').replace('/','-')
-        #
-        # try:
-        #     li[6]=str(datetime.strptime(li[6],'%Y-%m-%d %H:%M'))
-        #     li[7]=str(datetime.strptime(li[7],'%Y-%m-%d %H:%M'))
-        #     # li[7]=str(datetime.strptime(li[7],'%Y/%m/%d %H:%M:%S'))
-        # except:
-        #     pass
-            # print("======================")
-        #     try:
-        #         li[6] = str(datetime.strptime(li[6][:17], '%Y-%m-%d %H:%M'))
-        #         li[7] = str(datetime.strptime(li[7][:17], '%Y/%m/%d %H:%M'))
-        #     except:
-        #         pass
-                # li[6]='2020-11-01 00:00:00'
-                # li[7]='2020-11-01 00:00:00'
-
-        # li[6] =li[6][:19]
-        # li[7] =li[7][:19]
-        #
-        # li[9] = '' if li[9] is None else li[9]
-        # li[5] = '' if li[5] is None else li[5]
-        # li[1] = '' if li[1] is None else li[1]
-        #
         data1.append(tuple(li))
 
     # 删除分区
@@ -195,4 +163,5 @@ def campaign_vx():
 
 
 if __name__ == '__main__':
-    order('2020-12-09')
+    for i in dt.getDateLists('2019-05-20','2020-12-27'):
+        order(i)