ck %!s(int64=4) %!d(string=hai) anos
pai
achega
86877e75ea

+ 2 - 1
app/etl/data_stat_daily.py

@@ -3,6 +3,7 @@ from data_stat_task import *
 from sync_to_ck_task import *
 du = DateUtils()
 from model.DingTalkUtils import DingTalkUtils
+from app.etl.dm.dm_pitcher_daily_overview import dm_pitcher_daily_overview
 yestoday = du.get_n_days(-1)
 today = du.get_n_days(0)
 
@@ -51,7 +52,7 @@ def run_cost_history():
 def main():
     run(yestoday)
     dw_daily_channel()
-    dm_pitcher_daily_page_total()
+    dm_pitcher_daily_overview()
 
 
 if __name__ == '__main__':

+ 2 - 1
app/etl/data_stat_hourly.py

@@ -3,6 +3,7 @@ from model.log import logger
 from model.DingTalkUtils import DingTalkUtils
 from data_stat_task import *
 from sync_to_ck_task import *
+from app.etl.dm.dm_pitcher_daily_overview import dm_pitcher_daily_overview
 log=logger()
 du = DateUtils()
 yestoday = du.get_n_days(-1)
@@ -25,7 +26,7 @@ def main():
     do_order()
     do_cost()
     dw_daily_channel()
-    dm_pitcher_daily_page_total()
+    dm_pitcher_daily_overview()
 
 if __name__ == '__main__':
     main()

+ 0 - 80
app/etl/data_stat_task.py

@@ -198,87 +198,7 @@ select formatDateTime(reg_time,'%Y-%m-%d') reg_date,channel,count(1) user_order_
     print("ok")
 
 
-def dm_pitcher_daily_page_total():
 
-    sql=f"""
-insert into dm_pitcher_daily_page_total
-select '{dt.get_n_days(0)}' dt,
-       q.pitcher,
-       round(cost,2),
-       round(amount,2),
-       round(roi,4),
-       channel_count,
-       on_channel_count,
-       channel_count-on_channel_count off_channel_count,
-       round(this_month_cost,2),
-       round(this_month_amount,2),
-       if(this_month_cost = 0, 0, round(this_month_amount / this_month_cost, 4)) this_month_roi,
-       last_month_cost,
-       last_month_amount,
-       if(last_month_cost = 0, 0, last_month_amount / last_month_cost) last_month_roi,
-       round(last_month_far_amount,2),
-       follow_user,
-       if(last_month_cost = 0, 0, last_month_far_amount / last_month_cost) last_month_far_roi
-from (select pitcher,
-             sum(cost)                                cost,
-             sum(reg_order_amount)                        amount,
-             sum(follow_user) follow_user,
-             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(0)}'
-      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
-    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
-    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' and reg_time<'{dt.get_n_pre_month_first_day(0)} 00:00:00'
-    group by pitcher
-    ) y on q.pitcher = y.pitcher
-left outer join (
-    select b.pitcher, sum(amount) last_month_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' and reg_time<'{dt.get_n_pre_month_first_day(0)} 00:00:00' 
- and dt<'{dt.get_n_pre_month_first_day(0)}'
-    group by pitcher
-) p on q.pitcher=p.pitcher
-left outer join (
-    select b.pitcher, sum(amount) this_month_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(0)} 00:00:00' 
-    group by pitcher
-) g on q.pitcher=g.pitcher
-"""
-    print(sql)
-    ck.execute(f"alter table dm_pitcher_daily_page_total drop partition '{dt.get_n_days(0)}'")
-    ck.execute(sql)
 
 
 def dw_channel_daily_total(ymd):

+ 94 - 0
app/etl/dm/dm_pitcher_daily_overview.py

@@ -0,0 +1,94 @@
+"""
+@desc 投手累计数据
+@auth ck
+"""
+from model.DateUtils import DateUtils
+from model.DataBaseUtils import MysqlUtils,CkUtils
+du = DateUtils()
+db= MysqlUtils()
+ck = CkUtils()
+
+def dm_pitcher_daily_overview():
+    sql=f"""
+select '{du.get_n_days(0)}' dt,
+       q.pitcher,
+       total_cost,
+       total_amount,
+       if(total_cost=0,0,total_amount/total_cost) roi,
+       channel_count,
+       on_channel_count,
+       channel_count-on_channel_count off_channel_count,
+       this_month_cost,
+       this_month_amount,
+       if(this_month_cost = 0, 0, round(this_month_amount / this_month_cost, 4)) this_month_roi,
+       last_month_cost,
+       last_month_amount,
+       if(last_month_cost = 0, 0, last_month_amount / last_month_cost) last_month_roi,
+       last_month_far_amount,
+       follow_user,
+       if(last_month_cost = 0, 0, last_month_far_amount / last_month_cost) last_month_far_roi
+from (select pitcher,
+             sum(follow_user) follow_user
+      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 = '{du.get_n_days(0)}'
+      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 >= '{du.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
+    from dw_daily_channel
+    where dt >= '{du.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
+    from dw_daily_channel
+    where dt >= '{du.get_n_pre_month_first_day(1)}'
+      and dt < '{du.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 >= '{du.get_n_pre_month_first_day(1)} 00:00:00' and reg_time<'{du.get_n_pre_month_first_day(0)} 00:00:00'
+    group by pitcher
+    ) y on q.pitcher = y.pitcher
+left outer join (
+    select b.pitcher, sum(amount) last_month_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 >= '{du.get_n_pre_month_first_day(1)} 00:00:00' and reg_time<'{du.get_n_pre_month_first_day(0)} 00:00:00' 
+ and dt<'{du.get_n_pre_month_first_day(0)}'
+    group by pitcher
+) p on q.pitcher=p.pitcher
+left outer join (
+    select b.pitcher, sum(amount) this_month_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 >= '{du.get_n_pre_month_first_day(0)} 00:00:00' 
+    group by pitcher
+) g on q.pitcher=g.pitcher
+    left outer join(
+select pitcher,total_amount,total_cost from dw_daily_pitcher where dt='{du.get_n_days(0)}'
+) k on  q.pitcher=k.pitcher
+    
+
+"""
+    data=ck.execute(sql)
+# print(data)
+    db.quchen_text.executeMany("replace into dm_pitcher_daily_overview values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",data)
+
+if __name__ == '__main__':
+    dm_pitcher_daily_overview()