MateirialVideoHourlyReport.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/15 5:10 下午
  4. # @Site :
  5. # @File : MateirialVideoHourlyReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. import logging
  9. from math import ceil
  10. from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
  11. from Apietl.utlis.Logger import Logger
  12. from Apietl.utlis.Utils import Utils
  13. from Apietl.conn.TidbConn import TidbConn
  14. class MateirialVideoHourlyReport:
  15. def __init__(self):
  16. self.conn = TidbConn.get_connection()
  17. self.parm = Utils.get_args()
  18. self.start_time = self.parm[0]
  19. self.end_time = self.parm[1]
  20. def hourly_report(self):
  21. try:
  22. sql = """select advertiser_id from media_api.kuaishou_material_video_report_hourly where
  23. stat_date between {start_time} and {end_time} group by advertiser_id""".format(
  24. start_time=self.start_time, end_time=self.end_time)
  25. account_list = TidbConn.quary(self.conn, sql)
  26. for account_id in account_list:
  27. sql = """replace into application.kuaishou_material_video_report_hourly_dw
  28. (account_id, project_id, product_id, advertiser_id,
  29. company_id, account_name, project_name,
  30. advertiser_name, company_name, sale_id, user_id,
  31. clip_id, shot_id, plan_id, leader_id, org_code,
  32. photo_url, photo_id, cover_url, image_token,
  33. photo_caption, stat_date, `hour`,charge, `show`, photo_click,
  34. aclick, bclick, photo_click_ratio, play_3s_ratio,
  35. action_ratio, impression_1k_cost, photo_click_cost,
  36. action_cost, share, comment, `like`, follow,
  37. cancel_follow, report, block, negative, submit,
  38. download_started, download_completed, activation,
  39. event_pay_first_day,
  40. event_pay_purchase_amount_first_day,
  41. event_pay_first_day_roi, event_pay,
  42. event_pay_purchase_amount, event_pay_roi,
  43. event_register, event_register_cost,
  44. event_register_ratio, event_jin_jian_app,
  45. event_jin_jian_app_cost, event_credit_grant_app,
  46. event_credit_grant_app_cost,
  47. event_credit_grant_app_ratio, event_order_paid,
  48. event_order_paid_purchase_amount,
  49. event_order_paid_cost, event_next_day_stay,
  50. event_next_day_stay_cost, event_next_day_stay_ratio,
  51. form_count, form_cost, form_action_ratio,
  52. event_jin_jian_landing_page,
  53. event_jin_jian_landing_page_cost,
  54. event_credit_grant_landing_page,
  55. event_credit_grant_landing_page_cost,
  56. event_credit_grant_landing_page_ratio,
  57. event_valid_clues, event_valid_clues_cost,
  58. event_add_wechat, event_add_wechat_cost,
  59. event_add_wechat_ratio, event_get_through,
  60. event_get_through_cost, event_get_through_ratio,
  61. event_app_invoked, event_app_invoked_cost,
  62. event_app_invoked_ratio,
  63. event_credit_grant_landing_ratio, play_5s_ratio,
  64. play_end_ratio, event_new_user_pay,
  65. event_new_user_pay_cost, event_new_user_pay_ratio,
  66. click_1k_cost, ad_product_cnt, event_goods_view,
  67. merchant_reco_fans, event_order_amount_roi,
  68. event_goods_view_cost, merchant_reco_fans_cost,
  69. event_button_click, event_button_click_cost,
  70. event_button_click_ratio, event_order_paid_roi,
  71. event_new_user_jinjian_app,
  72. event_new_user_jinjian_app_cost,
  73. event_new_user_jinjian_app_roi,
  74. event_new_user_credit_grant_app,
  75. event_new_user_credit_grant_app_cost,
  76. event_new_user_credit_grant_app_roi,
  77. event_new_user_jinjian_page,
  78. event_new_user_jinjian_page_cost,
  79. event_new_user_jinjian_page_roi,
  80. event_new_user_credit_grant_page,
  81. event_new_user_credit_grant_page_cost,
  82. event_new_user_credit_grant_page_roi,
  83. event_appoint_form, event_appoint_form_cost,
  84. event_appoint_form_ratio, event_appoint_jump_click,
  85. event_appoint_jump_click_cost,
  86. event_appoint_jump_click_ratio,
  87. union_event_pay_purchase_amount_7d,
  88. union_event_pay_purchase_amount_7d_roi, placement_type,
  89. ad_scene, event_order_successed,
  90. ad_photo_played_10s_ratio, key_action_cost,
  91. event_add_shopping_cart_cost,
  92. event_ad_watch_times_ratio, event_outbound_call_cost,
  93. event_outbound_call, action_new_ratio,
  94. event_watch_app_ad, event_multi_conversion_cost,
  95. event_phone_card_activate,
  96. ad_photo_played_75percent_ratio, key_action_ratio,
  97. event_ad_watch_times_cost, event_add_shopping_cart,
  98. key_action, event_multi_conversion,
  99. event_wechat_connected, event_dsp_gift_form,
  100. event_intention_confirmed, event_phone_get_through,
  101. event_multi_conversion_ratio, event_measurement_house,
  102. ad_photo_played_2s_ratio, event_outbound_call_ratio,
  103. event_ad_watch_times,
  104. signature,
  105. channel_type ,
  106. clip_name,
  107. shot_name,
  108. plan_name,
  109. leader_name,
  110. video_name,
  111. channel_name,
  112. clip_company_id)
  113. select
  114. report.advertiser_id as account_id,
  115. cp.id as project_id,
  116. product.id as product_id,
  117. ca.id as advertiser_id,
  118. uc.company_id,
  119. account_name,
  120. cp.project_name as project_name,
  121. ca.name as advertiser_name,
  122. uc.company_name,
  123. cp.sale_id,
  124. cua.user_id,
  125. clip_id,
  126. shot_id,
  127. plan_id,
  128. cma.leader_id,
  129. su.org_code,
  130. report.photo_url,
  131. report.photo_id,
  132. report.cover_url,
  133. report.image_token,
  134. report.photo_caption,
  135. report.stat_date,
  136. report.`hour`,
  137. charge,
  138. `show`,
  139. photo_click,
  140. aclick,
  141. bclick,
  142. photo_click_ratio,
  143. play_3s_ratio,
  144. action_ratio,
  145. impression_1k_cost,
  146. photo_click_cost,
  147. action_cost,
  148. share,
  149. comment,
  150. `like`,
  151. follow,
  152. cancel_follow,
  153. report,
  154. block,
  155. negative,
  156. submit,
  157. download_started,
  158. download_completed,
  159. activation,
  160. event_pay_first_day,
  161. event_pay_purchase_amount_first_day,
  162. event_pay_first_day_roi,
  163. event_pay,
  164. event_pay_purchase_amount,
  165. event_pay_roi,
  166. event_register,
  167. event_register_cost,
  168. event_register_ratio,
  169. event_jin_jian_app,
  170. event_jin_jian_app_cost,
  171. event_credit_grant_app,
  172. event_credit_grant_app_cost,
  173. event_credit_grant_app_ratio,
  174. event_order_paid,
  175. event_order_paid_purchase_amount,
  176. event_order_paid_cost,
  177. event_next_day_stay,
  178. event_next_day_stay_cost,
  179. event_next_day_stay_ratio,
  180. form_count,
  181. form_cost,
  182. form_action_ratio,
  183. event_jin_jian_landing_page,
  184. event_jin_jian_landing_page_cost,
  185. event_credit_grant_landing_page,
  186. event_credit_grant_landing_page_cost,
  187. event_credit_grant_landing_page_ratio,
  188. event_valid_clues,
  189. event_valid_clues_cost,
  190. event_add_wechat,
  191. event_add_wechat_cost,
  192. event_add_wechat_ratio,
  193. event_get_through,
  194. event_get_through_cost,
  195. event_get_through_ratio,
  196. event_app_invoked,
  197. event_app_invoked_cost,
  198. event_app_invoked_ratio,
  199. event_credit_grant_landing_ratio,
  200. play_5s_ratio,
  201. play_end_ratio,
  202. event_new_user_pay,
  203. event_new_user_pay_cost,
  204. event_new_user_pay_ratio,
  205. click_1k_cost,
  206. ad_product_cnt,
  207. event_goods_view,
  208. merchant_reco_fans,
  209. event_order_amount_roi,
  210. event_goods_view_cost,
  211. merchant_reco_fans_cost,
  212. event_button_click,
  213. event_button_click_cost,
  214. event_button_click_ratio,
  215. event_order_paid_roi,
  216. event_new_user_jinjian_app,
  217. event_new_user_jinjian_app_cost,
  218. event_new_user_jinjian_app_roi,
  219. event_new_user_credit_grant_app,
  220. event_new_user_credit_grant_app_cost,
  221. event_new_user_credit_grant_app_roi,
  222. event_new_user_jinjian_page,
  223. event_new_user_jinjian_page_cost,
  224. event_new_user_jinjian_page_roi,
  225. event_new_user_credit_grant_page,
  226. event_new_user_credit_grant_page_cost,
  227. event_new_user_credit_grant_page_roi,
  228. event_appoint_form,
  229. event_appoint_form_cost,
  230. event_appoint_form_ratio,
  231. event_appoint_jump_click,
  232. event_appoint_jump_click_cost,
  233. event_appoint_jump_click_ratio,
  234. union_event_pay_purchase_amount_7d,
  235. union_event_pay_purchase_amount_7d_roi,
  236. placement_type,
  237. ad_scene,
  238. event_order_successed,
  239. ad_photo_played_10s_ratio,
  240. key_action_cost,
  241. event_add_shopping_cart_cost,
  242. event_ad_watch_times_ratio,
  243. event_outbound_call_cost,
  244. event_outbound_call,
  245. action_new_ratio,
  246. event_watch_app_ad,
  247. event_multi_conversion_cost,
  248. event_phone_card_activate,
  249. ad_photo_played_75percent_ratio,
  250. key_action_ratio,
  251. event_ad_watch_times_cost,
  252. event_add_shopping_cart,
  253. key_action,
  254. event_multi_conversion,
  255. event_wechat_connected,
  256. event_dsp_gift_form,
  257. event_intention_confirmed,
  258. event_phone_get_through,
  259. event_multi_conversion_ratio,
  260. event_measurement_house,
  261. ad_photo_played_2s_ratio,
  262. event_outbound_call_ratio,
  263. event_ad_watch_times,
  264. video.signature,
  265. video.channel_type,
  266. clip.realname,
  267. shot.realname,
  268. plan.realname,
  269. leader.leader_name,
  270. case when cmi.material_name is not null then cmi.material_name else video.photo_name end as video_name,
  271. case when video.channel_type = 1 then '素造' else '内部' end as channel_name,
  272. uc.company_id
  273. from media_api.kuaishou_material_video_report_hourly report
  274. left join media_api.kuaishou_video_list video
  275. on report.advertiser_id = video.account_id and report.photo_id = video.photo_id
  276. left join `jeecg-boot`.ctop_material_info cmi on video.signature = cmi.code
  277. left join `jeecg-boot`.ctop_material_ascription cma on cma.code = video.signature
  278. left join `jeecg-boot`.ctop_user_allocation cua on cua.account_id = report.advertiser_id
  279. left join `jeecg-boot`.ctop_project cp on cua.project_id = cp.id
  280. left join `jeecg-boot`.ctop_advertiser ca on ca.id = cua.advertiser_id
  281. left join `jeecg-boot`.sys_user su on su.id = cua.user_id
  282. left join `jeecg-boot`.sys_user clip on clip.id = cma.clip_id
  283. left join `jeecg-boot`.sys_user shot on shot.id = cma.shot_id
  284. left join `jeecg-boot`.sys_user plan on plan.id = cma.plan_id
  285. left join `jeecg-boot`.sys_user leader on leader.id = cma.leader_id
  286. left join `jeecg-boot`.user_company uc on uc.user_id = clip.id
  287. left join `jeecg-boot`.ctop_product product on product.id = cp.product_id
  288. where report.stat_date between {start_time} and {end_time} and report.photo_id!=0
  289. and report.advertiser_id={account_id}
  290. """.format(
  291. start_time=self.start_time, end_time=self.end_time, account_id=account_id[0])
  292. print(sql)
  293. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  294. self.conn.commit()
  295. TidbConn.conn_close(conn=self.conn)
  296. return 0
  297. except Exception as e:
  298. logging.error(e)
  299. return -1
  300. if __name__ == '__main__':
  301. status = MateirialVideoHourlyReport().hourly_report()
  302. if status == 0:
  303. print("作业执行成功")
  304. exit(0)
  305. else:
  306. print("作业执行失败")
  307. exit(-1)