dm_pitcher_daily_overview.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. """
  2. @desc 投手累计数据
  3. @auth ck
  4. """
  5. from model.DateUtils import DateUtils
  6. from model.DataBaseUtils import MysqlUtils, CkUtils
  7. import logging
  8. du = DateUtils()
  9. db = MysqlUtils()
  10. ck = CkUtils()
  11. def dm_pitcher_daily_overview():
  12. logging.info('投手累计数据处理,开始')
  13. logging.info("run> dm_pitcher_daily_overview")
  14. sql = f"""
  15. select
  16. q.pitcher,
  17. channel_count,
  18. on_channel_count,
  19. channel_count-on_channel_count off_channel_count,
  20. this_month_cost,
  21. this_month_amount,
  22. if(this_month_cost < 1, 0, round(this_month_amount / this_month_cost, 4)) this_month_roi,
  23. last_month_cost,
  24. last_month_amount,
  25. if(last_month_cost < 1, 0, last_month_amount / last_month_cost) last_month_roi,
  26. last_month_far_amount,
  27. follow_user,
  28. if(last_month_cost < 1, 0, last_month_far_amount / last_month_cost) last_month_far_roi
  29. from (select pitcher,
  30. sum(follow_user) follow_user
  31. from dw_daily_channel_cost
  32. group by pitcher) q
  33. left outer join
  34. (select count(distinct channel) channel_count, pitcher
  35. from dw_daily_channel_cost
  36. where dt = '{du.get_n_days(0)}'
  37. group by pitcher) w
  38. on q.pitcher = w.pitcher
  39. left outer join(
  40. select count(distinct channel) on_channel_count, pitcher
  41. from dw_daily_channel_cost
  42. where dt >= '{du.get_n_days(-15)}'
  43. and cost > 0
  44. group by pitcher) e
  45. on q.pitcher = e.pitcher
  46. left outer join (
  47. select pitcher,
  48. sum(cost) this_month_cost
  49. from dw_daily_channel_cost
  50. where dt >= '{du.get_n_pre_month_first_day(0)}'
  51. group by pitcher) r
  52. on q.pitcher = r.pitcher
  53. left outer join(
  54. select pitcher,
  55. sum(cost) last_month_cost
  56. from dw_daily_channel_cost
  57. where dt >= '{du.get_n_pre_month_first_day(1)}'
  58. and dt < '{du.get_n_pre_month_first_day(0)}'
  59. group by pitcher) t on q.pitcher = t.pitcher
  60. left outer join (
  61. select b.pitcher, sum(amount) last_month_far_amount
  62. from order a
  63. left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
  64. 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 status=2
  65. group by pitcher
  66. ) y on q.pitcher = y.pitcher
  67. left outer join (
  68. select b.pitcher, sum(amount) last_month_amount
  69. from order a
  70. left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
  71. 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 status=2
  72. and dt<'{du.get_n_pre_month_first_day(0)}'
  73. group by pitcher
  74. ) p on q.pitcher=p.pitcher
  75. left outer join (
  76. select b.pitcher, sum(amount) this_month_amount
  77. from order a
  78. left outer join dw_daily_channel_cost b on a.channel = b.channel and a.date = b.dt
  79. where reg_time >= '{du.get_n_pre_month_first_day(0)} 00:00:00' and status=2
  80. group by pitcher
  81. ) g on q.pitcher=g.pitcher
  82. """
  83. data = ck.execute(sql)
  84. db.dm.executeMany("replace into dm_pitcher_daily_overview values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", data)
  85. logging.info('投手累计数据处理,结束')
  86. if __name__ == '__main__':
  87. dm_pitcher_daily_overview()