MateirialVideoDailyReport.py 9.6 KB

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