DeleteMateirialVideoDailyReport.py 11 KB

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