ck 4 jaren geleden
bovenliggende
commit
b31915afb4
3 gewijzigde bestanden met toevoegingen van 83 en 8 verwijderingen
  1. 6 3
      app/etl/data_stat_daily.py
  2. 72 1
      app/etl/data_stat_task.py
  3. 5 4
      model/DataBaseUtils.py

+ 6 - 3
app/etl/data_stat_daily.py

@@ -44,12 +44,15 @@ def run_cost_history():
     dw_daily_channel()
 
 
+def main():
+    run(yestoday)
+    dw_daily_channel()
+    dm_pitcher_daily_page_total()
 
 
 if __name__ == '__main__':
-    run(yestoday)
-    # # dw_daily_channel()
-    # run_order_history()
+   main()
+
 
 
 

+ 72 - 1
app/etl/data_stat_task.py

@@ -8,6 +8,8 @@ dt = DateUtils()
 from datetime import datetime
 from sync_to_ck_task import dw_order_channel_cost_sync_ck
 
+
+
 def dw_daily_channel_cost(ymd):
     sql="""replace into dw_daily_channel_cost
         select dt,x.channel,pitcher,stage,platform,book,
@@ -135,7 +137,6 @@ def order_account_text():
         for i in f.readlines():
             db.quchen_text.execute("insert into order_account_text(platform,text) values ('文鼎','{}')".format(i))
 
-
 def dw_daily_channel():
     """快照表 每日一更新  t-1"""
     sql="""insert into dw_daily_channel
@@ -172,6 +173,74 @@ from
     print("ok")
 
 
+def dm_pitcher_daily_page_total():
+
+    sql=f"""insert into dm_pitcher_daily_page_total
+select '{dt.get_n_days(-1)}' dt,
+       pitcher,
+       cost,
+       amount,
+       roi,
+       channel_count,
+       on_channel_count,
+       channel_count-on_channel_count off_channel_count,
+       this_month_cost,
+       this_month_amount,
+       this_month_roi,
+       last_month_cost,
+       last_month_amount,
+       last_month_roi,
+       last_month_far_amount,
+       0 follow_user
+from (select pitcher,
+             sum(cost)                                cost,
+             sum(order_amount)                        amount,
+             if(cost = 0, 0, round(amount / cost, 2)) roi
+      from dw_daily_channel
+      group by pitcher) q
+         left outer join
+     (select count(distinct channel) channel_count, pitcher
+      from dw_daily_channel_cost
+      where dt = '{dt.get_n_days(-1)}'
+      group by pitcher) w
+     on q.pitcher = w.pitcher
+         left outer join(
+    select count(distinct channel) on_channel_count, pitcher
+    from dw_daily_channel_cost
+    where dt >= '{dt.get_n_days(-15)}'
+      and cost > 0
+    group by pitcher) e
+                        on q.pitcher = e.pitcher
+         left outer join (
+    select pitcher,
+           sum(cost)                                                                 this_month_cost,
+           sum(order_amount)                                                         this_month_amount,
+           if(this_month_cost = 0, 0, round(this_month_amount / this_month_cost, 4)) this_month_roi
+    from dw_daily_channel
+    where dt >= '{dt.get_n_pre_month_first_day(0)}'
+    group by pitcher) r
+                         on q.pitcher = r.pitcher
+         left outer join(
+    select pitcher,
+           sum(cost)                                                                 last_month_cost,
+           sum(order_amount)                                                         last_month_amount,
+           if(last_month_cost = 0, 0, round(last_month_amount / last_month_cost, 2)) last_month_roi
+    from dw_daily_channel
+    where dt >= '{dt.get_n_pre_month_first_day(1)}'
+      and dt < '{dt.get_n_pre_month_first_day(0)}'
+    group by pitcher) t on q.pitcher = t.pitcher
+         left outer join (
+    select b.pitcher, sum(amount) last_month_far_amount
+    from order a
+             left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
+    where reg_time >= '{dt.get_n_pre_month_first_day(1)} 00:00:00'
+    group by pitcher
+    ) y on q.pitcher = y.pitcher
+having pitcher != ''"""
+    print(sql)
+    ck.execute(sql)
+
+
 if __name__ == '__main__':
     # channel_by_account_daily('2020-12-17')
     # dw_daily_channel_cost('2020-12-17')
@@ -182,6 +251,8 @@ if __name__ == '__main__':
     # exit()
     # dw_daily_channel()
     # exit(0)
+    # dm_pitcher_daily_page_total()
+    # exit(0)
 
     for i in dt.getDateLists('2019-03-18','2020-12-21'):
         print(i)

+ 5 - 4
model/DataBaseUtils.py

@@ -73,17 +73,18 @@ class CkUtils:
 
 
 
-    def getColumns(self,table,str=False):
+    def getColumns(self,table,is_list=False):
         data=self.execute("desc "+table)
         li=[]
         str = ''
         for i in data:
             li.append(i[0])
             str+=i[0]+','
-        if str:
-            return str[:-1]
-        else:
+        if is_list:
             return li
+        else:
+            return str[:-1]
+