MateirialVideoDailyReport.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 Apietl.conn.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 = """select advertiser_id from media_api.kuaishou_material_video_report_daily 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_daily_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, 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. play_3s_count,
  114. shot_leader_id,
  115. shot_leader_name)
  116. select report.advertiser_id as account_id,
  117. cp.id as project_id,
  118. product.id as product_id,
  119. ca.id as advertiser_id,
  120. uc.company_id,
  121. cua.auth_name as account_name,
  122. cp.project_name as project_name,
  123. ca.name as advertiser_name,
  124. uc.company_name,
  125. cp.sale_id,
  126. cua.user_id,
  127. clip_id,
  128. shot_id,
  129. plan_id,
  130. cma.leader_id,
  131. leader.org_code,
  132. report.photo_url,
  133. report.photo_id,
  134. report.cover_url,
  135. report.image_token,
  136. report.photo_caption,
  137. report.stat_date,
  138. charge,
  139. `show`,
  140. photo_click,
  141. aclick,
  142. bclick,
  143. photo_click_ratio,
  144. play_3s_ratio,
  145. action_ratio,
  146. impression_1k_cost,
  147. photo_click_cost,
  148. action_cost,
  149. share,
  150. comment,
  151. `like`,
  152. follow,
  153. cancel_follow,
  154. report,
  155. block,
  156. negative,
  157. submit,
  158. download_started,
  159. download_completed,
  160. activation,
  161. event_pay_first_day,
  162. event_pay_purchase_amount_first_day,
  163. event_pay_first_day_roi,
  164. event_pay,
  165. event_pay_purchase_amount,
  166. event_pay_roi,
  167. event_register,
  168. event_register_cost,
  169. event_register_ratio,
  170. event_jin_jian_app,
  171. event_jin_jian_app_cost,
  172. event_credit_grant_app,
  173. event_credit_grant_app_cost,
  174. event_credit_grant_app_ratio,
  175. event_order_paid,
  176. event_order_paid_purchase_amount,
  177. event_order_paid_cost,
  178. event_next_day_stay,
  179. event_next_day_stay_cost,
  180. event_next_day_stay_ratio,
  181. form_count,
  182. form_cost,
  183. form_action_ratio,
  184. event_jin_jian_landing_page,
  185. event_jin_jian_landing_page_cost,
  186. event_credit_grant_landing_page,
  187. event_credit_grant_landing_page_cost,
  188. event_credit_grant_landing_page_ratio,
  189. event_valid_clues,
  190. event_valid_clues_cost,
  191. event_add_wechat,
  192. event_add_wechat_cost,
  193. event_add_wechat_ratio,
  194. event_get_through,
  195. event_get_through_cost,
  196. event_get_through_ratio,
  197. event_app_invoked,
  198. event_app_invoked_cost,
  199. event_app_invoked_ratio,
  200. event_credit_grant_landing_ratio,
  201. play_5s_ratio,
  202. play_end_ratio,
  203. event_new_user_pay,
  204. event_new_user_pay_cost,
  205. event_new_user_pay_ratio,
  206. click_1k_cost,
  207. ad_product_cnt,
  208. event_goods_view,
  209. merchant_reco_fans,
  210. event_order_amount_roi,
  211. event_goods_view_cost,
  212. merchant_reco_fans_cost,
  213. event_button_click,
  214. event_button_click_cost,
  215. event_button_click_ratio,
  216. event_order_paid_roi,
  217. event_new_user_jinjian_app,
  218. event_new_user_jinjian_app_cost,
  219. event_new_user_jinjian_app_roi,
  220. event_new_user_credit_grant_app,
  221. event_new_user_credit_grant_app_cost,
  222. event_new_user_credit_grant_app_roi,
  223. event_new_user_jinjian_page,
  224. event_new_user_jinjian_page_cost,
  225. event_new_user_jinjian_page_roi,
  226. event_new_user_credit_grant_page,
  227. event_new_user_credit_grant_page_cost,
  228. event_new_user_credit_grant_page_roi,
  229. event_appoint_form,
  230. event_appoint_form_cost,
  231. event_appoint_form_ratio,
  232. event_appoint_jump_click,
  233. event_appoint_jump_click_cost,
  234. event_appoint_jump_click_ratio,
  235. union_event_pay_purchase_amount_7d,
  236. union_event_pay_purchase_amount_7d_roi,
  237. placement_type,
  238. ad_scene,
  239. event_order_successed,
  240. ad_photo_played_10s_ratio,
  241. key_action_cost,
  242. event_add_shopping_cart_cost,
  243. event_ad_watch_times_ratio,
  244. event_outbound_call_cost,
  245. event_outbound_call,
  246. action_new_ratio,
  247. event_watch_app_ad,
  248. event_multi_conversion_cost,
  249. event_phone_card_activate,
  250. ad_photo_played_75percent_ratio,
  251. key_action_ratio,
  252. event_ad_watch_times_cost,
  253. event_add_shopping_cart,
  254. key_action,
  255. event_multi_conversion,
  256. event_wechat_connected,
  257. event_dsp_gift_form,
  258. event_intention_confirmed,
  259. event_phone_get_through,
  260. event_multi_conversion_ratio,
  261. event_measurement_house,
  262. ad_photo_played_2s_ratio,
  263. event_outbound_call_ratio,
  264. event_ad_watch_times,
  265. video.signature,
  266. video.channel_type,
  267. clip.realname,
  268. shot.realname,
  269. plan.realname,
  270. leader.realname,
  271. case when cmi.material_name is not null then cmi.material_name else video.photo_name end as video_name,
  272. case when video.channel_type = 1 then '素造' else '内部' end,
  273. uc.company_id,
  274. round(play_3s_ratio*aclick) as play_3s_count,
  275. cma.shot_leader_id,
  276. cma.shot_leader_name
  277. from media_api.kuaishou_material_video_report_daily report
  278. left join media_api.signature_photo_id video
  279. on report.photo_id = video.photo_id
  280. left join (select code,material_name from `jeecg-boot`.ctop_material_info where status=1) cmi on video.signature = cmi.code
  281. left join `jeecg-boot`.ctop_material_ascription cma on cma.material_id = video.signature
  282. left join `jeecg-boot`.ctop_user_allocation cua on cua.account_id = report.advertiser_id
  283. left join `jeecg-boot`.ctop_project cp on cua.project_id = cp.id
  284. left join `jeecg-boot`.ctop_advertiser ca on ca.id = cua.advertiser_id
  285. left join `jeecg-boot`.sys_user clip on clip.id = cma.clip_id
  286. left join `jeecg-boot`.sys_user shot on shot.id = cma.shot_id
  287. left join `jeecg-boot`.sys_user plan on plan.id = cma.plan_id
  288. left join `jeecg-boot`.sys_user leader on leader.id = cma.leader_id
  289. left join `jeecg-boot`.user_company uc on uc.user_id = clip.id
  290. left join `jeecg-boot`.ctop_product product on product.id = cp.product_id
  291. where report.stat_date between {start_time} and {end_time}
  292. and report.advertiser_id={account_id}""".format(
  293. start_time=self.start_time, end_time=self.end_time, account_id=account_id[0])
  294. print(sql)
  295. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  296. self.conn.commit()
  297. TidbConn.conn_close(conn=self.conn)
  298. return 0
  299. except Exception as e:
  300. logging.error(e)
  301. return -1
  302. if __name__ == '__main__':
  303. status = MateirialVideoDailyReport().daily_report()
  304. if status == 0:
  305. print("作业执行成功")
  306. exit(0)
  307. else:
  308. print("作业执行失败")
  309. exit(-1)