MateirialVideoDailyReport.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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.utlis.Logger import Logger
  11. from Apietl.utlis.Utils import Utils
  12. from TidbConn import TidbConn
  13. class MateirialVideoDailyReport:
  14. def __init__(self):
  15. self.conn = TidbConn.get_connection()
  16. self.parm = Utils.get_args()
  17. self.start_time = self.parm[0]
  18. self.end_time = self.parm[1]
  19. def daily_report(self):
  20. try:
  21. sql = """select count(1) from media_api.kuaishou_material_video_report_daily where
  22. stat_date between {start_time} and {end_time}""".format(
  23. start_time=self.start_time, end_time=self.end_time)
  24. totalNum = TidbConn.quary(sql)[0][0]
  25. pageCount = ceil(totalNum / 20000)
  26. for i in range(pageCount):
  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. select report.advertiser_id as account_id,
  106. project_id,
  107. product_id,
  108. sys.advertiser_id,
  109. company_id,
  110. account_name,
  111. project_name,
  112. advertiser_name,
  113. company_name,
  114. sale_id,
  115. user_id,
  116. clip_id,
  117. shot_id,
  118. plan_id,
  119. leader_id,
  120. org_code,
  121. report.photo_url,
  122. report.photo_id,
  123. report.cover_url,
  124. report.image_token,
  125. report.photo_caption,
  126. stat_date,
  127. charge,
  128. `show`,
  129. photo_click,
  130. aclick,
  131. bclick,
  132. photo_click_ratio,
  133. play_3s_ratio,
  134. action_ratio,
  135. impression_1k_cost,
  136. photo_click_cost,
  137. action_cost,
  138. share,
  139. comment,
  140. `like`,
  141. follow,
  142. cancel_follow,
  143. report,
  144. block,
  145. negative,
  146. submit,
  147. download_started,
  148. download_completed,
  149. activation,
  150. event_pay_first_day,
  151. event_pay_purchase_amount_first_day,
  152. event_pay_first_day_roi,
  153. event_pay,
  154. event_pay_purchase_amount,
  155. event_pay_roi,
  156. event_register,
  157. event_register_cost,
  158. event_register_ratio,
  159. event_jin_jian_app,
  160. event_jin_jian_app_cost,
  161. event_credit_grant_app,
  162. event_credit_grant_app_cost,
  163. event_credit_grant_app_ratio,
  164. event_order_paid,
  165. event_order_paid_purchase_amount,
  166. event_order_paid_cost,
  167. event_next_day_stay,
  168. event_next_day_stay_cost,
  169. event_next_day_stay_ratio,
  170. form_count,
  171. form_cost,
  172. form_action_ratio,
  173. event_jin_jian_landing_page,
  174. event_jin_jian_landing_page_cost,
  175. event_credit_grant_landing_page,
  176. event_credit_grant_landing_page_cost,
  177. event_credit_grant_landing_page_ratio,
  178. event_valid_clues,
  179. event_valid_clues_cost,
  180. event_add_wechat,
  181. event_add_wechat_cost,
  182. event_add_wechat_ratio,
  183. event_get_through,
  184. event_get_through_cost,
  185. event_get_through_ratio,
  186. event_app_invoked,
  187. event_app_invoked_cost,
  188. event_app_invoked_ratio,
  189. event_credit_grant_landing_ratio,
  190. play_5s_ratio,
  191. play_end_ratio,
  192. event_new_user_pay,
  193. event_new_user_pay_cost,
  194. event_new_user_pay_ratio,
  195. click_1k_cost,
  196. ad_product_cnt,
  197. event_goods_view,
  198. merchant_reco_fans,
  199. event_order_amount_roi,
  200. event_goods_view_cost,
  201. merchant_reco_fans_cost,
  202. event_button_click,
  203. event_button_click_cost,
  204. event_button_click_ratio,
  205. event_order_paid_roi,
  206. event_new_user_jinjian_app,
  207. event_new_user_jinjian_app_cost,
  208. event_new_user_jinjian_app_roi,
  209. event_new_user_credit_grant_app,
  210. event_new_user_credit_grant_app_cost,
  211. event_new_user_credit_grant_app_roi,
  212. event_new_user_jinjian_page,
  213. event_new_user_jinjian_page_cost,
  214. event_new_user_jinjian_page_roi,
  215. event_new_user_credit_grant_page,
  216. event_new_user_credit_grant_page_cost,
  217. event_new_user_credit_grant_page_roi,
  218. event_appoint_form,
  219. event_appoint_form_cost,
  220. event_appoint_form_ratio,
  221. event_appoint_jump_click,
  222. event_appoint_jump_click_cost,
  223. event_appoint_jump_click_ratio,
  224. union_event_pay_purchase_amount_7d,
  225. union_event_pay_purchase_amount_7d_roi,
  226. placement_type,
  227. ad_scene,
  228. event_order_successed,
  229. ad_photo_played_10s_ratio,
  230. key_action_cost,
  231. event_add_shopping_cart_cost,
  232. event_ad_watch_times_ratio,
  233. event_outbound_call_cost,
  234. event_outbound_call,
  235. action_new_ratio,
  236. event_watch_app_ad,
  237. event_multi_conversion_cost,
  238. event_phone_card_activate,
  239. ad_photo_played_75percent_ratio,
  240. key_action_ratio,
  241. event_ad_watch_times_cost,
  242. event_add_shopping_cart,
  243. key_action,
  244. event_multi_conversion,
  245. event_wechat_connected,
  246. event_dsp_gift_form,
  247. event_intention_confirmed,
  248. event_phone_get_through,
  249. event_multi_conversion_ratio,
  250. event_measurement_house,
  251. ad_photo_played_2s_ratio,
  252. event_outbound_call_ratio,
  253. event_ad_watch_times,
  254. video.signature,
  255. sys.channel_type ,
  256. sys.clip_name,
  257. sys.shot_name,
  258. sys.plan_name,
  259. sys.leader_name,
  260. sys.video_name,
  261. sys.channel_name,
  262. sys.clip_company_id
  263. from media_api.kuaishou_material_video_report_daily report
  264. left join media_api.kuaishou_video_list video
  265. on report.advertiser_id=video.advertiser_id and report.photo_id=video.photo_id
  266. left join
  267. `jeecg-boot`.ctop_material_attribution_info sys
  268. on report.advertiser_id = sys.account_id
  269. where report.stat_date between {start_time} and {end_time} and report.photo_id!=0
  270. order by advertiser_id,photo_id ,stat_date limit {num},20000""".format(
  271. start_time=self.start_time, end_time=self.end_time, num=i * 20000)
  272. TidbConn.exec_sql(self.conn, sql)
  273. self.conn.commit()
  274. return 0
  275. except Exception as e:
  276. logging.error(e)
  277. return -1
  278. if __name__ == '__main__':
  279. status = MateirialVideoDailyReport().daily_report()
  280. media_name = 'kwai'
  281. trace_log = Logger().etl_logger(media_name, MateirialVideoDailyReport().start_time)
  282. if status == 0:
  283. trace_log.info("作业执行成功")
  284. else:
  285. trace_log.error("作业执行失败")