ck 4 роки тому
батько
коміт
4a223c5974
1 змінених файлів з 18 додано та 9 видалено
  1. 18 9
      app/etl/data_stat_task.py

+ 18 - 9
app/etl/data_stat_task.py

@@ -205,14 +205,15 @@ select '{dt.get_n_days(-1)}' dt,
        round(this_month_cost,2),
        round(this_month_amount,2),
        round(this_month_roi,4),
-       round(last_month_cost,2),
-       round(last_month_amount,2),
-       round(last_month_roi,4),
+       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),
-       0 follow_user
+       follow_user
 from (select pitcher,
              sum(cost)                                cost,
              sum(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
@@ -240,9 +241,7 @@ from (select pitcher,
                          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
+           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)}'
@@ -251,9 +250,18 @@ from (select pitcher,
     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'
+    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
+
 having pitcher != ''"""
     print(sql)
     ck.execute("alter table dm_pitcher_daily_page_total drop partition '{dt.get_n_days(-1)}';")
@@ -283,10 +291,11 @@ if __name__ == '__main__':
     # dw_daily_channel()
     # exit(0)
     # dm_pitcher_daily_page_total()
+    dm_pitcher_daily_page_total()
     # dw_channel_daily_total('2020-12-28')
     # exit(0)
     # dw_daily_channel()
-    # exit(0)
+    exit(0)
     for i in dt.getDateLists('2019-03-18','2021-01-05'):
         print(i)
         # ods_order(i)