dm_pitcher_daily_overview.py 3.2 KB

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