ck пре 4 година
родитељ
комит
41eb07c6e1
3 измењених фајлова са 27 додато и 8 уклоњено
  1. 4 1
      app/etl/data_stat_hourly.py
  2. 5 5
      app/etl/data_stat_task.py
  3. 18 2
      model/DateUtils.py

+ 4 - 1
app/etl/data_stat_hourly.py

@@ -6,7 +6,7 @@ from sync_to_ck_task import *
 log=logger()
 du = DateUtils()
 yestoday = du.get_n_days(-1)
-today = du.get_n_days(0)
+today = du.getTodayOrYestoday()
 
 
 def do_order():
@@ -17,11 +17,14 @@ def do_cost():
     channel_info_daily(today)
     dw_daily_channel_cost(today)
     dw_order_channel_cost_sync_ck(today)
+    dw_channel_daily_total(today)
+
 
 def main():
     do_order()
     do_cost()
     dw_daily_channel()
+    dm_pitcher_daily_page_total()
 
 if __name__ == '__main__':
     main()

+ 5 - 5
app/etl/data_stat_task.py

@@ -194,7 +194,7 @@ def dm_pitcher_daily_page_total():
 
     sql=f"""
 insert into dm_pitcher_daily_page_total
-select '{dt.get_n_days(-1)}' dt,
+select '{dt.get_n_days(0)}' dt,
        pitcher,
        round(cost,2),
        round(amount,2),
@@ -221,7 +221,7 @@ from (select pitcher,
          left outer join
      (select count(distinct channel) channel_count, pitcher
       from dw_daily_channel_cost
-      where dt = '{dt.get_n_days(-1)}'
+      where dt = '{dt.get_n_days(0)}'
       group by pitcher) w
      on q.pitcher = w.pitcher
          left outer join(
@@ -271,7 +271,7 @@ left outer join (
 
 having pitcher != ''"""
     print(sql)
-    ck.execute(f"alter table dm_pitcher_daily_page_total drop partition '{dt.get_n_days(-1)}'")
+    ck.execute(f"alter table dm_pitcher_daily_page_total drop partition '{dt.get_n_days(0)}'")
     ck.execute(sql)
 
 
@@ -298,8 +298,8 @@ 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')
+    # dm_pitcher_daily_page_total()
+    dw_channel_daily_total('2021-01-11')
     exit(0)
     # dw_daily_channel()
     # # exit(0)

+ 18 - 2
model/DateUtils.py

@@ -21,6 +21,18 @@ class DateUtils:
         interval = self.getInterval(begin, end)
         return [self.getLastDays(begin, -x) for x in range(interval + 1)]
 
+    def getTodayOrYestoday(self):
+        """
+        如果当天零点 则返回昨天
+        否则返回今天
+        :return:
+        """
+        if self.now.hour==0:
+            return self.get_n_days(-1)
+        else:
+            return self.get_n_days(0)
+
+
     def getMonthLists(self, begin, end):
         begin_date = datetime.strptime(begin, "%Y-%m").date()
         end_date = datetime.strptime(end, '%Y-%m').date()
@@ -274,5 +286,9 @@ if __name__ == "__main__":
     end = ut.now.strftime('%Y-%m') + '-01 00:00:00'
     # begin = ut.get_n_month_ago_begin(ut.now.strftime('%Y-%m'), 1) + '-01 00:00:00'
     # print(ut.get_n_pre_month_first_day(0))
-    ut.today = date(2018, 1, 1)
-    print(ut.month_first_day())
+    # ut.today = date(2018, 1, 1)
+    # print(ut.month_first_day())
+    # a='2021-01-01 00:01:01'
+    # b=datetime.strptime(a,'%Y-%m-%d %H:%M:%S')
+    # print(b.hour)
+    # print(ut.now.hour)