AccountDailyReport.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/27 10:50 上午
  4. # @Site :
  5. # @File : AccountDailyReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import logging
  10. from math import ceil
  11. from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
  12. from Apietl.utlis.Logger import Logger
  13. from Apietl.utlis.Utils import Utils
  14. from Apietl.conn.TidbConn import TidbConn
  15. class AccountDailyReport:
  16. def __init__(self):
  17. self.conn = TidbConn.get_connection()
  18. self.parm = Utils.get_args()
  19. self.start_time = self.parm[0]
  20. self.end_time = self.parm[1]
  21. def daily_report(self):
  22. ReplaceAccountInfo.handler()
  23. try:
  24. sql = """
  25. replace into application.kuaishou_account_report_daily_dw
  26. (account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
  27. company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
  28. play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
  29. cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
  30. event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
  31. event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
  32. event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
  33. event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
  34. event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
  35. event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
  36. event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
  37. event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
  38. event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
  39. play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
  40. event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
  41. event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
  42. event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
  43. event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
  44. event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
  45. event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
  46. event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
  47. event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
  48. union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
  49. key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
  50. event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
  51. ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
  52. event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
  53. event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
  54. event_outbound_call_ratio, event_ad_watch_times,event_pay_purchase_amount_one_day_by_conversion,
  55. ad_photo_played_10s,
  56. ad_photo_played_2s,
  57. ad_photo_played_75percent,
  58. approx_pay_cost,
  59. approx_pay_count,
  60. approx_pay_ratio,cancel_like,
  61. click_conversion_ratio,
  62. conversion_cost,conversion_cost_by_impression_7d,conversion_num,conversion_num_by_impression_7d,conversion_num_cost,conversion_ratio,conversion_ratio_by_impression_7d,deep_conversion_cost,deep_conversion_cost_by_impression_7d,deep_conversion_num,deep_conversion_num_by_impression_7d,deep_conversion_ratio,deep_conversion_ratio_by_impression_7d,download_completed_cost,download_completed_ratio,download_conversion_ratio,download_installed,download_started_cost,download_started_ratio,event_24h_stay,event_24h_stay_by_conversion,event_24h_stay_by_conversion_cost,event_24h_stay_by_conversion_ratio,event_24h_stay_cost,event_24h_stay_ratio,event_ad_watch_10_times,event_ad_watch_10_times_cost,event_ad_watch_10_times_ratio,event_ad_watch_20_times,event_ad_watch_20_times_cost,event_ad_watch_20_times_ratio,event_ad_watch_5_times,event_ad_watch_5_times_cost,event_ad_watch_5_times_ratio,event_audition,event_consultation_valid_retained,event_consultation_valid_retained_cost,event_consultation_valid_retained_ratio,event_conversion_click_cost,event_conversion_click_ratio,event_credit_grant_first_day_app,event_credit_grant_first_day_app_cost,event_credit_grant_first_day_app_ratio,event_credit_grant_first_day_landing_page,event_credit_grant_first_day_landing_page_cost,event_credit_grant_first_day_landing_page_ratio,event_making_calls,event_making_calls_cost,event_making_calls_ratio,event_order_submit,event_pay_purchase_amount_one_day,event_pay_purchase_amount_one_day_by_conversion_roi,event_pay_purchase_amount_one_day_roi,event_pay_purchase_amount_three_day_by_conversion,event_pay_purchase_amount_three_day_by_conversion_roi,event_pay_purchase_amount_week_by_conversion,event_pay_purchase_amount_week_by_conversion_roi,event_pay_week_by_conversion,event_pay_week_by_conversion_cost,event_pay_weighted_purchase_amount,event_pay_weighted_purchase_amount_first_day,event_pre_component_consultation_valid_retained,event_three_day_stay_by_conversion,event_three_day_stay_by_conversion_cost,event_three_day_stay_by_conversion_ratio,event_wechat_qr_code_link_click,event_week_stay_by_conversion,event_week_stay_by_conversion_cost,event_week_stay_by_conversion_ratio,live_event_goods_view,live_played_3s,played_end,played_five_seconds,played_three_seconds,event_next_day_stay_new,event_next_day_stay_new_cost,event_next_day_stay_new_ratio,ad_show,event_credit_card_recheck,event_credit_card_recheck_first_day,event_no_intention,event_multi_pay_seven_day_by_conversion,event_multi_pay_seven_day_by_conversion_cost,mcb_left_time_perf_cpa_bid,mcb_left_time_perf_roi_ratio,mcb_all_day_perf_cpa_bid,mcb_all_day_perf_roi_ratio,live_room_avg_played_seconds,ad_live_share,ad_live_comment,live_played_started,live_played_started_cost,ad_live_follow,ad_live_follow_cost,simple_live_played_started,standard_live_played_started,conversion_component_impression,conversion_component_click,conversion_component_rate,ad_landing_page_impression,ad_app_download_half_impression
  63. )
  64. select report.advertiser_id as account_id,
  65. stat_date,
  66. project_id,
  67. product_id,
  68. sys.advertiser_id,
  69. company_id,
  70. account_name,
  71. project_name,
  72. advertiser_name,
  73. company_name,
  74. sale_id,
  75. user_id,
  76. org_code,
  77. charge,
  78. `show`,
  79. photo_click,
  80. aclick,
  81. bclick,
  82. photo_click_ratio,
  83. play_3s_ratio,
  84. action_ratio,
  85. impression_1k_cost,
  86. photo_click_cost,
  87. action_cost,
  88. share,
  89. comment,
  90. `like`,
  91. follow,
  92. cancel_follow,
  93. report,
  94. block,
  95. negative,
  96. submit,
  97. download_started,
  98. download_completed,
  99. activation,
  100. event_pay_first_day,
  101. event_pay_purchase_amount_first_day,
  102. event_pay_first_day_roi,
  103. event_pay,
  104. event_pay_purchase_amount,
  105. event_pay_roi,
  106. event_register,
  107. event_register_cost,
  108. event_register_ratio,
  109. event_jin_jian_app,
  110. event_jin_jian_app_cost,
  111. event_credit_grant_app,
  112. event_credit_grant_app_cost,
  113. event_credit_grant_app_ratio,
  114. event_order_paid,
  115. event_order_paid_purchase_amount,
  116. event_order_paid_cost,
  117. event_next_day_stay,
  118. event_next_day_stay_cost,
  119. event_next_day_stay_ratio,
  120. form_count,
  121. form_cost,
  122. form_action_ratio,
  123. event_jin_jian_landing_page,
  124. event_jin_jian_landing_page_cost,
  125. event_credit_grant_landing_page,
  126. event_credit_grant_landing_page_cost,
  127. event_credit_grant_landing_page_ratio,
  128. event_valid_clues,
  129. event_valid_clues_cost,
  130. event_add_wechat,
  131. event_add_wechat_cost,
  132. event_add_wechat_ratio,
  133. event_get_through,
  134. event_get_through_cost,
  135. event_get_through_ratio,
  136. event_app_invoked,
  137. event_app_invoked_cost,
  138. event_app_invoked_ratio,
  139. event_credit_grant_landing_ratio,
  140. play_5s_ratio,
  141. play_end_ratio,
  142. event_new_user_pay,
  143. event_new_user_pay_cost,
  144. event_new_user_pay_ratio,
  145. click_1k_cost,
  146. ad_product_cnt,
  147. event_goods_view,
  148. merchant_reco_fans,
  149. event_order_amount_roi,
  150. event_goods_view_cost,
  151. merchant_reco_fans_cost,
  152. event_button_click,
  153. event_button_click_cost,
  154. event_button_click_ratio,
  155. event_order_paid_roi,
  156. event_new_user_jinjian_app,
  157. event_new_user_jinjian_app_cost,
  158. event_new_user_jinjian_app_roi,
  159. event_new_user_credit_grant_app,
  160. event_new_user_credit_grant_app_cost,
  161. event_new_user_credit_grant_app_roi,
  162. event_new_user_jinjian_page,
  163. event_new_user_jinjian_page_cost,
  164. event_new_user_jinjian_page_roi,
  165. event_new_user_credit_grant_page,
  166. event_new_user_credit_grant_page_cost,
  167. event_new_user_credit_grant_page_roi,
  168. event_appoint_form,
  169. event_appoint_form_cost,
  170. event_appoint_form_ratio,
  171. event_appoint_jump_click,
  172. event_appoint_jump_click_cost,
  173. event_appoint_jump_click_ratio,
  174. union_event_pay_purchase_amount_7d,
  175. union_event_pay_purchase_amount_7d_roi,
  176. placement_type,
  177. ad_scene,
  178. event_order_successed,
  179. ad_photo_played_10s_ratio,
  180. key_action_cost,
  181. event_add_shopping_cart_cost,
  182. event_ad_watch_times_ratio,
  183. event_outbound_call_cost,
  184. event_outbound_call,
  185. action_new_ratio,
  186. event_watch_app_ad,
  187. event_multi_conversion_cost,
  188. event_phone_card_activate,
  189. ad_photo_played_75percent_ratio,
  190. key_action_ratio,
  191. event_ad_watch_times_cost,
  192. event_add_shopping_cart,
  193. key_action,
  194. event_multi_conversion,
  195. event_wechat_connected,
  196. event_dsp_gift_form,
  197. event_intention_confirmed,
  198. event_phone_get_through,
  199. event_multi_conversion_ratio,
  200. event_measurement_house,
  201. ad_photo_played_2s_ratio,
  202. event_outbound_call_ratio,
  203. event_ad_watch_times,
  204. event_pay_purchase_amount_one_day_by_conversion,
  205. ad_photo_played_10s
  206. ,ad_photo_played_2s
  207. ,ad_photo_played_75percent
  208. ,approx_pay_cost
  209. ,approx_pay_count
  210. ,approx_pay_ratio
  211. ,cancel_like
  212. ,click_conversion_ratio
  213. ,conversion_cost
  214. ,conversion_cost_by_impression_7d
  215. ,conversion_num
  216. ,conversion_num_by_impression_7d
  217. ,conversion_num_cost
  218. ,conversion_ratio
  219. ,conversion_ratio_by_impression_7d
  220. ,deep_conversion_cost
  221. ,deep_conversion_cost_by_impression_7d
  222. ,deep_conversion_num
  223. ,deep_conversion_num_by_impression_7d
  224. ,deep_conversion_ratio
  225. ,deep_conversion_ratio_by_impression_7d
  226. ,download_completed_cost
  227. ,download_completed_ratio
  228. ,download_conversion_ratio
  229. ,download_installed
  230. ,download_started_cost
  231. ,download_started_ratio
  232. ,event_24h_stay
  233. ,event_24h_stay_by_conversion
  234. ,event_24h_stay_by_conversion_cost
  235. ,event_24h_stay_by_conversion_ratio
  236. ,event_24h_stay_cost
  237. ,event_24h_stay_ratio
  238. ,event_ad_watch_10_times
  239. ,event_ad_watch_10_times_cost
  240. ,event_ad_watch_10_times_ratio
  241. ,event_ad_watch_20_times
  242. ,event_ad_watch_20_times_cost
  243. ,event_ad_watch_20_times_ratio
  244. ,event_ad_watch_5_times
  245. ,event_ad_watch_5_times_cost
  246. ,event_ad_watch_5_times_ratio
  247. ,event_audition
  248. ,event_consultation_valid_retained
  249. ,event_consultation_valid_retained_cost
  250. ,event_consultation_valid_retained_ratio
  251. ,event_conversion_click_cost
  252. ,event_conversion_click_ratio
  253. ,event_credit_grant_first_day_app
  254. ,event_credit_grant_first_day_app_cost
  255. ,event_credit_grant_first_day_app_ratio
  256. ,event_credit_grant_first_day_landing_page
  257. ,event_credit_grant_first_day_landing_page_cost
  258. ,event_credit_grant_first_day_landing_page_ratio
  259. ,event_making_calls
  260. ,event_making_calls_cost
  261. ,event_making_calls_ratio
  262. ,event_order_submit
  263. ,event_pay_purchase_amount_one_day
  264. ,event_pay_purchase_amount_one_day_by_conversion_roi
  265. ,event_pay_purchase_amount_one_day_roi
  266. ,event_pay_purchase_amount_three_day_by_conversion
  267. ,event_pay_purchase_amount_three_day_by_conversion_roi
  268. ,event_pay_purchase_amount_week_by_conversion
  269. ,event_pay_purchase_amount_week_by_conversion_roi
  270. ,event_pay_week_by_conversion
  271. ,event_pay_week_by_conversion_cost
  272. ,event_pay_weighted_purchase_amount
  273. ,event_pay_weighted_purchase_amount_first_day
  274. ,event_pre_component_consultation_valid_retained
  275. ,event_three_day_stay_by_conversion
  276. ,event_three_day_stay_by_conversion_cost
  277. ,event_three_day_stay_by_conversion_ratio
  278. ,event_wechat_qr_code_link_click
  279. ,event_week_stay_by_conversion
  280. ,event_week_stay_by_conversion_cost
  281. ,event_week_stay_by_conversion_ratio
  282. ,live_event_goods_view
  283. ,live_played_3s
  284. ,played_end
  285. ,played_five_seconds
  286. ,played_three_seconds
  287. ,event_next_day_stay_new
  288. ,event_next_day_stay_new_cost
  289. ,event_next_day_stay_new_ratio
  290. ,ad_show
  291. ,event_credit_card_recheck
  292. ,event_credit_card_recheck_first_day
  293. ,event_no_intention
  294. ,event_multi_pay_seven_day_by_conversion
  295. ,event_multi_pay_seven_day_by_conversion_cost
  296. ,mcb_left_time_perf_cpa_bid
  297. ,mcb_left_time_perf_roi_ratio
  298. ,mcb_all_day_perf_cpa_bid
  299. ,mcb_all_day_perf_roi_ratio
  300. ,live_room_avg_played_seconds
  301. ,ad_live_share
  302. ,ad_live_comment
  303. ,live_played_started
  304. ,live_played_started_cost
  305. ,ad_live_follow
  306. ,ad_live_follow_cost
  307. ,simple_live_played_started
  308. ,standard_live_played_started
  309. ,conversion_component_impression
  310. ,conversion_component_click
  311. ,conversion_component_rate
  312. ,ad_landing_page_impression
  313. ,ad_app_download_half_impression
  314. from media_api.kuaishou_account_report_daily report
  315. left join
  316. `jeecg-boot`.ctop_account_attribution_info sys
  317. on report.advertiser_id = sys.account_id
  318. where report.stat_date between {start_time} and {end_time}
  319. """.format(start_time=self.start_time, end_time=self.end_time)
  320. print(sql)
  321. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  322. self.conn.commit()
  323. TidbConn.conn_close(conn=self.conn)
  324. return 0
  325. except Exception as e:
  326. logging.error(e)
  327. return -1
  328. if __name__ == '__main__':
  329. status = AccountDailyReport().daily_report()
  330. if status == 0:
  331. print("作业执行成功")
  332. exit(0)
  333. else:
  334. print("作业执行失败")
  335. exit(-1)