dm_pitcher_daily_overview.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. sql=f"""
  12. select '{du.get_n_days(0)}' dt,
  13. q.pitcher,
  14. total_cost,
  15. total_amount,
  16. if(total_cost=0,0,total_amount/total_cost) roi,
  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 = 0, 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 = 0, 0, last_month_amount / last_month_cost) last_month_roi,
  26. last_month_far_amount,
  27. follow_user,
  28. if(last_month_cost = 0, 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
  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
  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
  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'
  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'
  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'
  80. group by pitcher
  81. ) g on q.pitcher=g.pitcher
  82. left outer join(
  83. select pitcher,total_amount,total_cost from dw_daily_pitcher where dt='{du.get_n_days(0)}'
  84. ) k on q.pitcher=k.pitcher
  85. """
  86. data=ck.execute(sql)
  87. # print(data)
  88. db.quchen_text.executeMany("replace into dm_pitcher_daily_overview values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",data)
  89. if __name__ == '__main__':
  90. dm_pitcher_daily_overview()