data_stat_run.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from model.DateUtils import DateUtils
  2. import logging
  3. from model.DingTalkUtils import DingTalkUtils
  4. from app.etl.data_stat_task import *
  5. from app.etl.sync_to_ck_task import *
  6. from app.etl.dm.dm_pitcher_daily_overview import dm_pitcher_daily_overview
  7. from app.etl.dw.dw_channel_daily import dw_channel_daily
  8. from app.etl.dw.dw_pitcher_daily import dw_pitcher_trend
  9. from app.etl.src.src_book_info import src_book_info
  10. from app.etl.dw.dw_book_trend import book_trend
  11. from app.etl.src import book_annual_expect_profit
  12. from logging import handlers
  13. from app.api_data.platform_order.order_data_change import insert_order_data_ck_gamedatasum
  14. du = DateUtils()
  15. logger = logging.getLogger("")
  16. # logger.setLevel(logging.ERROR)
  17. # logging.getLogger().setLevel(logging.WARNING)
  18. def do_order(st, et):
  19. logging.info('订单数据同步到ck,开始')
  20. for i in du.getDateLists(st, et):
  21. logging.info('订单:' + str(i))
  22. insert_order_data_ck_gamedatasum(i)
  23. logging.info('订单数据同步到ck,结束')
  24. def do_cost(st, et):
  25. logging.info('消耗数据处理,开始')
  26. for i in du.getDateLists(st, et):
  27. logging.info("消耗:" + str(i))
  28. channel_by_account_daily(i)
  29. channel_info_daily(i)
  30. dw_daily_channel_cost_ck_gamedatasum(i)
  31. # dw_daily_bytedance_cost(i)
  32. platform_data_sum(i)
  33. logging.info('消耗数据处理,结束')
  34. def main(st, et):
  35. try:
  36. do_order(st, et)
  37. do_cost(st, et)
  38. dw_channel_daily()
  39. dw_pitcher_trend()
  40. book_trend()
  41. dm_pitcher_daily_overview()
  42. except Exception as e:
  43. logging.error(e)
  44. DingTalkUtils().send("hourlyRun fail!! " + str(e), '15168342316')
  45. def hourly():
  46. thedate = du.getTodayOrYestoday()
  47. # 默认做三天的留存数据
  48. # for i in du.getDateLists(du.get_n_days(-15), du.getNow()):
  49. # dw_daily_channel_cost(i)
  50. main(thedate, thedate)
  51. def daily():
  52. "往前跑10天"
  53. st = du.get_n_days(-10)
  54. et = du.get_n_days(-1)
  55. do_order(st, et)
  56. do_cost(st, et)
  57. if __name__ == '__main__':
  58. logging.basicConfig(
  59. handlers=[
  60. logging.handlers.RotatingFileHandler('./data_stat_run.log',
  61. maxBytes=10 * 1024 * 1024,
  62. backupCount=5,
  63. encoding='utf-8')
  64. , logging.StreamHandler() # 供输出使用
  65. ],
  66. level=logging.INFO,
  67. format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
  68. )
  69. do_cost('2021-09-01','2022-04-20')
  70. # main(du.get_n_days(-200), du.getNow())
  71. # hourly()
  72. # daily()
  73. # daily('2021-06-30','2021-07-04')
  74. # do_order('2021-05-30', '2021-06-29')