adq_material_report_daily.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/15 5:10 下午
  4. # @Site :
  5. # @File : MateirialVideoDailyReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. import logging
  9. from Apietl.conn.TidbConn import TidbConn
  10. from Apietl.utlis.Utils import Utils
  11. class AdqMaterialReportDaily(object):
  12. def __init__(self):
  13. self.conn = TidbConn.get_connection()
  14. self.parm = Utils.get_args()
  15. self.start_time = self.parm[0]
  16. self.end_time = self.parm[1]
  17. def daily_report(self):
  18. try:
  19. sql = """
  20. select advertiser_id from media_api.adq_material_report_daily where
  21. stat_time_day >= {start_time} and stat_time_day<={end_time} group by advertiser_id
  22. """.format(start_time=self.start_time, end_time=self.start_time)
  23. account_list = TidbConn.quary(self.conn, sql)
  24. for account_id in account_list:
  25. try:
  26. sql = """
  27. replace into application.adq_material_report_daily_dw(account_id,
  28. project_id,
  29. product_id,
  30. advertiser_id,
  31. company_id,
  32. account_name,
  33. project_name,
  34. advertiser_name,
  35. company_name,
  36. sale_id,
  37. user_id,
  38. clip_id,
  39. shot_id,
  40. plan_id,
  41. leader_id,
  42. org_code,
  43. photo_url,
  44. material_id,
  45. stat_date,
  46. material_type,
  47. cost,
  48. view_count,
  49. valid_click_count,
  50. conversions_count,
  51. deep_conversions_count,
  52. activated_count,
  53. reg_pv,
  54. retention_count,
  55. video_outer_play_count,
  56. video_outer_play100_count,
  57. key_behavior_conversions_count,
  58. purchase_pv,
  59. purchase_amount,
  60. first_pay_count,
  61. ad_monetization_amount,
  62. app_ad_paying_users,
  63. income_pv_pla,
  64. income_val_1,
  65. ad_paying_users_d1,
  66. income_pv_1d_pla,
  67. income_val_3,
  68. signature,
  69. channel_type,
  70. clip_name,
  71. shot_name,
  72. plan_name,
  73. leader_name,
  74. video_name,
  75. channel_name,
  76. clip_company_id,
  77. play_3s_count,
  78. shot_leader_id,
  79. shot_leader_name,
  80. key_frame_image_url)
  81. select report.advertiser_id as account_id,
  82. cp.id as project_id,
  83. null as product_id,
  84. null as advertiser_id,
  85. uc.company_id,
  86. cua.auth_name as account_name,
  87. cp.project_name as project_name,
  88. null as advertiser_name,
  89. uc.company_name,
  90. cp.sale_id,
  91. null as user_id,
  92. clip_id,
  93. shot_id,
  94. plan_id,
  95. cma.leader_id,
  96. leader.org_code,
  97. video.preview_url as photo_url,
  98. report.material_id,
  99. report.stat_time_day as stat_date,
  100. report.material_type,
  101. report.cost / 100 as cost,
  102. report.view_count,
  103. report.valid_click_count,
  104. report.conversions_count,
  105. report.deep_conversions_count,
  106. report.activated_count,
  107. report.reg_pv,
  108. report.retention_count,
  109. report.video_outer_play_count,
  110. report.video_outer_play100_count,
  111. report.key_behavior_conversions_count,
  112. report.purchase_pv,
  113. report.purchase_amount / 100 as purchase_amount,
  114. report.first_pay_count,
  115. report.ad_monetization_amount,
  116. report.app_ad_paying_users,
  117. report.income_pv_pla,
  118. report.income_val_1 / 100 as income_val_1,
  119. report.ad_paying_users_d1,
  120. report.income_pv_1d_pla,
  121. report.income_val_3 / 100 as income_val_3,
  122. video.signature,
  123. null as channel_type,
  124. clip.realname,
  125. shot.realname,
  126. plan.realname,
  127. leader.realname,
  128. video.description as video_name,
  129. null channel_name,
  130. uc.company_id,
  131. 0 as play_3s_count,
  132. cma.shot_leader_id,
  133. cma.shot_leader_name,
  134. video.key_frame_image_url
  135. from media_api.adq_material_report_daily report
  136. left join media_api.adq_video_info video
  137. on report.material_id = video.video_id
  138. left join `jeecg-boot`.ctop_material_ascription cma on cma.material_id = video.signature
  139. left join `jeecg-boot`.ctop_user_allocation cua on cua.account_id = report.advertiser_id
  140. left join `jeecg-boot`.ctop_project cp on cua.project_id = cp.id
  141. left join `jeecg-boot`.sys_user clip on clip.id = cma.clip_id
  142. left join `jeecg-boot`.sys_user shot on shot.id = cma.shot_id
  143. left join `jeecg-boot`.sys_user plan on plan.id = cma.plan_id
  144. left join `jeecg-boot`.sys_user leader on leader.id = cma.leader_id
  145. left join `jeecg-boot`.user_company uc on uc.user_id = clip.id
  146. where report.stat_time_day >= {start_time}
  147. and stat_time_day <= {end_time}
  148. and report.advertiser_id = {account_id}
  149. """.format(start_time=self.start_time, end_time=self.start_time, account_id=account_id[0])
  150. print(sql)
  151. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  152. self.conn.commit()
  153. except Exception as e:
  154. logging.error(e)
  155. return -1
  156. TidbConn.conn_close(conn=self.conn)
  157. return 0
  158. except Exception as e:
  159. logging.error(e)
  160. return -1
  161. if __name__ == '__main__':
  162. AdqMaterialReportDaily().daily_report()