AccountReport.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/15 5:10 下午
  4. # @Site :
  5. # @File : AccountReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. import logging
  9. from Apietl.conn.TidbConn import TidbConn
  10. from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
  11. from Apietl.utlis.Utils import Utils
  12. class AccountReport:
  13. def __init__(self):
  14. self.conn = TidbConn.get_connection()
  15. def daily_report(self, account_id, start_date, end_date):
  16. ReplaceAccountInfo.handler()
  17. try:
  18. sql = """
  19. replace into application.kuaishou_account_report_daily_dw
  20. (account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
  21. company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
  22. play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
  23. cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
  24. event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
  25. event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
  26. event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
  27. event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
  28. event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
  29. event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
  30. event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
  31. event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
  32. event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
  33. play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
  34. event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
  35. event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
  36. event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
  37. event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
  38. event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
  39. event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
  40. event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
  41. event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
  42. union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
  43. key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
  44. event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
  45. ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
  46. event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
  47. event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
  48. event_outbound_call_ratio, event_ad_watch_times,event_pay_purchase_amount_one_day_by_conversion,
  49. ad_photo_played_10s
  50. ,ad_photo_played_2s
  51. ,ad_photo_played_75percent
  52. ,approx_pay_cost
  53. ,approx_pay_count
  54. ,approx_pay_ratio
  55. ,cancel_like
  56. ,click_conversion_ratio
  57. ,conversion_cost
  58. ,conversion_cost_by_impression_7d
  59. ,conversion_num
  60. ,conversion_num_by_impression_7d
  61. ,conversion_num_cost
  62. ,conversion_ratio
  63. ,conversion_ratio_by_impression_7d
  64. ,deep_conversion_cost
  65. ,deep_conversion_cost_by_impression_7d
  66. ,deep_conversion_num
  67. ,deep_conversion_num_by_impression_7d
  68. ,deep_conversion_ratio
  69. ,deep_conversion_ratio_by_impression_7d
  70. ,download_completed_cost
  71. ,download_completed_ratio
  72. ,download_conversion_ratio
  73. ,download_installed
  74. ,download_started_cost
  75. ,download_started_ratio
  76. ,event_24h_stay
  77. ,event_24h_stay_by_conversion
  78. ,event_24h_stay_by_conversion_cost
  79. ,event_24h_stay_by_conversion_ratio
  80. ,event_24h_stay_cost
  81. ,event_24h_stay_ratio
  82. ,event_ad_watch_10_times
  83. ,event_ad_watch_10_times_cost
  84. ,event_ad_watch_10_times_ratio
  85. ,event_ad_watch_20_times
  86. ,event_ad_watch_20_times_cost
  87. ,event_ad_watch_20_times_ratio
  88. ,event_ad_watch_5_times
  89. ,event_ad_watch_5_times_cost
  90. ,event_ad_watch_5_times_ratio
  91. ,event_audition
  92. ,event_consultation_valid_retained
  93. ,event_consultation_valid_retained_cost
  94. ,event_consultation_valid_retained_ratio
  95. ,event_conversion_click_cost
  96. ,event_conversion_click_ratio
  97. ,event_credit_grant_first_day_app
  98. ,event_credit_grant_first_day_app_cost
  99. ,event_credit_grant_first_day_app_ratio
  100. ,event_credit_grant_first_day_landing_page
  101. ,event_credit_grant_first_day_landing_page_cost
  102. ,event_credit_grant_first_day_landing_page_ratio
  103. ,event_making_calls
  104. ,event_making_calls_cost
  105. ,event_making_calls_ratio
  106. ,event_order_submit
  107. ,event_pay_purchase_amount_one_day
  108. ,event_pay_purchase_amount_one_day_by_conversion_roi
  109. ,event_pay_purchase_amount_one_day_roi
  110. ,event_pay_purchase_amount_three_day_by_conversion
  111. ,event_pay_purchase_amount_three_day_by_conversion_roi
  112. ,event_pay_purchase_amount_week_by_conversion
  113. ,event_pay_purchase_amount_week_by_conversion_roi
  114. ,event_pay_week_by_conversion
  115. ,event_pay_week_by_conversion_cost
  116. ,event_pay_weighted_purchase_amount
  117. ,event_pay_weighted_purchase_amount_first_day
  118. ,event_pre_component_consultation_valid_retained
  119. ,event_three_day_stay_by_conversion
  120. ,event_three_day_stay_by_conversion_cost
  121. ,event_three_day_stay_by_conversion_ratio
  122. ,event_wechat_qr_code_link_click
  123. ,event_week_stay_by_conversion
  124. ,event_week_stay_by_conversion_cost
  125. ,event_week_stay_by_conversion_ratio
  126. ,live_event_goods_view
  127. ,live_played_3s
  128. ,played_end
  129. ,played_five_seconds
  130. ,played_three_seconds
  131. ,event_next_day_stay_new
  132. ,event_next_day_stay_new_cost
  133. ,event_next_day_stay_new_ratio
  134. ,ad_show
  135. ,event_credit_card_recheck
  136. ,event_credit_card_recheck_first_day
  137. ,event_no_intention
  138. ,event_multi_pay_seven_day_by_conversion
  139. ,event_multi_pay_seven_day_by_conversion_cost
  140. ,mcb_left_time_perf_cpa_bid
  141. ,mcb_left_time_perf_roi_ratio
  142. ,mcb_all_day_perf_cpa_bid
  143. ,mcb_all_day_perf_roi_ratio
  144. ,live_room_avg_played_seconds
  145. ,ad_live_share
  146. ,ad_live_comment
  147. ,live_played_started
  148. ,live_played_started_cost
  149. ,ad_live_follow
  150. ,ad_live_follow_cost
  151. ,simple_live_played_started
  152. ,standard_live_played_started
  153. ,conversion_component_impression
  154. ,conversion_component_click
  155. ,conversion_component_rate
  156. ,ad_landing_page_impression
  157. ,ad_app_download_half_impression
  158. )
  159. select report.advertiser_id as account_id,
  160. stat_date,
  161. project_id,
  162. product_id,
  163. sys.advertiser_id,
  164. company_id,
  165. account_name,
  166. project_name,
  167. advertiser_name,
  168. company_name,
  169. sale_id,
  170. user_id,
  171. org_code,
  172. charge,
  173. `show`,
  174. photo_click,
  175. aclick,
  176. bclick,
  177. photo_click_ratio,
  178. play_3s_ratio,
  179. action_ratio,
  180. impression_1k_cost,
  181. photo_click_cost,
  182. action_cost,
  183. share,
  184. comment,
  185. `like`,
  186. follow,
  187. cancel_follow,
  188. report,
  189. block,
  190. negative,
  191. submit,
  192. download_started,
  193. download_completed,
  194. activation,
  195. event_pay_first_day,
  196. event_pay_purchase_amount_first_day,
  197. event_pay_first_day_roi,
  198. event_pay,
  199. event_pay_purchase_amount,
  200. event_pay_roi,
  201. event_register,
  202. event_register_cost,
  203. event_register_ratio,
  204. event_jin_jian_app,
  205. event_jin_jian_app_cost,
  206. event_credit_grant_app,
  207. event_credit_grant_app_cost,
  208. event_credit_grant_app_ratio,
  209. event_order_paid,
  210. event_order_paid_purchase_amount,
  211. event_order_paid_cost,
  212. event_next_day_stay,
  213. event_next_day_stay_cost,
  214. event_next_day_stay_ratio,
  215. form_count,
  216. form_cost,
  217. form_action_ratio,
  218. event_jin_jian_landing_page,
  219. event_jin_jian_landing_page_cost,
  220. event_credit_grant_landing_page,
  221. event_credit_grant_landing_page_cost,
  222. event_credit_grant_landing_page_ratio,
  223. event_valid_clues,
  224. event_valid_clues_cost,
  225. event_add_wechat,
  226. event_add_wechat_cost,
  227. event_add_wechat_ratio,
  228. event_get_through,
  229. event_get_through_cost,
  230. event_get_through_ratio,
  231. event_app_invoked,
  232. event_app_invoked_cost,
  233. event_app_invoked_ratio,
  234. event_credit_grant_landing_ratio,
  235. play_5s_ratio,
  236. play_end_ratio,
  237. event_new_user_pay,
  238. event_new_user_pay_cost,
  239. event_new_user_pay_ratio,
  240. click_1k_cost,
  241. ad_product_cnt,
  242. event_goods_view,
  243. merchant_reco_fans,
  244. event_order_amount_roi,
  245. event_goods_view_cost,
  246. merchant_reco_fans_cost,
  247. event_button_click,
  248. event_button_click_cost,
  249. event_button_click_ratio,
  250. event_order_paid_roi,
  251. event_new_user_jinjian_app,
  252. event_new_user_jinjian_app_cost,
  253. event_new_user_jinjian_app_roi,
  254. event_new_user_credit_grant_app,
  255. event_new_user_credit_grant_app_cost,
  256. event_new_user_credit_grant_app_roi,
  257. event_new_user_jinjian_page,
  258. event_new_user_jinjian_page_cost,
  259. event_new_user_jinjian_page_roi,
  260. event_new_user_credit_grant_page,
  261. event_new_user_credit_grant_page_cost,
  262. event_new_user_credit_grant_page_roi,
  263. event_appoint_form,
  264. event_appoint_form_cost,
  265. event_appoint_form_ratio,
  266. event_appoint_jump_click,
  267. event_appoint_jump_click_cost,
  268. event_appoint_jump_click_ratio,
  269. union_event_pay_purchase_amount_7d,
  270. union_event_pay_purchase_amount_7d_roi,
  271. placement_type,
  272. ad_scene,
  273. event_order_successed,
  274. ad_photo_played_10s_ratio,
  275. key_action_cost,
  276. event_add_shopping_cart_cost,
  277. event_ad_watch_times_ratio,
  278. event_outbound_call_cost,
  279. event_outbound_call,
  280. action_new_ratio,
  281. event_watch_app_ad,
  282. event_multi_conversion_cost,
  283. event_phone_card_activate,
  284. ad_photo_played_75percent_ratio,
  285. key_action_ratio,
  286. event_ad_watch_times_cost,
  287. event_add_shopping_cart,
  288. key_action,
  289. event_multi_conversion,
  290. event_wechat_connected,
  291. event_dsp_gift_form,
  292. event_intention_confirmed,
  293. event_phone_get_through,
  294. event_multi_conversion_ratio,
  295. event_measurement_house,
  296. ad_photo_played_2s_ratio,
  297. event_outbound_call_ratio,
  298. event_ad_watch_times,
  299. event_pay_purchase_amount_one_day_by_conversion,
  300. ad_photo_played_10s
  301. ,ad_photo_played_2s
  302. ,ad_photo_played_75percent
  303. ,approx_pay_cost
  304. ,approx_pay_count
  305. ,approx_pay_ratio
  306. ,cancel_like
  307. ,click_conversion_ratio
  308. ,conversion_cost
  309. ,conversion_cost_by_impression_7d
  310. ,conversion_num
  311. ,conversion_num_by_impression_7d
  312. ,conversion_num_cost
  313. ,conversion_ratio
  314. ,conversion_ratio_by_impression_7d
  315. ,deep_conversion_cost
  316. ,deep_conversion_cost_by_impression_7d
  317. ,deep_conversion_num
  318. ,deep_conversion_num_by_impression_7d
  319. ,deep_conversion_ratio
  320. ,deep_conversion_ratio_by_impression_7d
  321. ,download_completed_cost
  322. ,download_completed_ratio
  323. ,download_conversion_ratio
  324. ,download_installed
  325. ,download_started_cost
  326. ,download_started_ratio
  327. ,event_24h_stay
  328. ,event_24h_stay_by_conversion
  329. ,event_24h_stay_by_conversion_cost
  330. ,event_24h_stay_by_conversion_ratio
  331. ,event_24h_stay_cost
  332. ,event_24h_stay_ratio
  333. ,event_ad_watch_10_times
  334. ,event_ad_watch_10_times_cost
  335. ,event_ad_watch_10_times_ratio
  336. ,event_ad_watch_20_times
  337. ,event_ad_watch_20_times_cost
  338. ,event_ad_watch_20_times_ratio
  339. ,event_ad_watch_5_times
  340. ,event_ad_watch_5_times_cost
  341. ,event_ad_watch_5_times_ratio
  342. ,event_audition
  343. ,event_consultation_valid_retained
  344. ,event_consultation_valid_retained_cost
  345. ,event_consultation_valid_retained_ratio
  346. ,event_conversion_click_cost
  347. ,event_conversion_click_ratio
  348. ,event_credit_grant_first_day_app
  349. ,event_credit_grant_first_day_app_cost
  350. ,event_credit_grant_first_day_app_ratio
  351. ,event_credit_grant_first_day_landing_page
  352. ,event_credit_grant_first_day_landing_page_cost
  353. ,event_credit_grant_first_day_landing_page_ratio
  354. ,event_making_calls
  355. ,event_making_calls_cost
  356. ,event_making_calls_ratio
  357. ,event_order_submit
  358. ,event_pay_purchase_amount_one_day
  359. ,event_pay_purchase_amount_one_day_by_conversion_roi
  360. ,event_pay_purchase_amount_one_day_roi
  361. ,event_pay_purchase_amount_three_day_by_conversion
  362. ,event_pay_purchase_amount_three_day_by_conversion_roi
  363. ,event_pay_purchase_amount_week_by_conversion
  364. ,event_pay_purchase_amount_week_by_conversion_roi
  365. ,event_pay_week_by_conversion
  366. ,event_pay_week_by_conversion_cost
  367. ,event_pay_weighted_purchase_amount
  368. ,event_pay_weighted_purchase_amount_first_day
  369. ,event_pre_component_consultation_valid_retained
  370. ,event_three_day_stay_by_conversion
  371. ,event_three_day_stay_by_conversion_cost
  372. ,event_three_day_stay_by_conversion_ratio
  373. ,event_wechat_qr_code_link_click
  374. ,event_week_stay_by_conversion
  375. ,event_week_stay_by_conversion_cost
  376. ,event_week_stay_by_conversion_ratio
  377. ,live_event_goods_view
  378. ,live_played_3s
  379. ,played_end
  380. ,played_five_seconds
  381. ,played_three_seconds
  382. ,event_next_day_stay_new
  383. ,event_next_day_stay_new_cost
  384. ,event_next_day_stay_new_ratio
  385. ,ad_show
  386. ,event_credit_card_recheck
  387. ,event_credit_card_recheck_first_day
  388. ,event_no_intention
  389. ,event_multi_pay_seven_day_by_conversion
  390. ,event_multi_pay_seven_day_by_conversion_cost
  391. ,mcb_left_time_perf_cpa_bid
  392. ,mcb_left_time_perf_roi_ratio
  393. ,mcb_all_day_perf_cpa_bid
  394. ,mcb_all_day_perf_roi_ratio
  395. ,live_room_avg_played_seconds
  396. ,ad_live_share
  397. ,ad_live_comment
  398. ,live_played_started
  399. ,live_played_started_cost
  400. ,ad_live_follow
  401. ,ad_live_follow_cost
  402. ,simple_live_played_started
  403. ,standard_live_played_started
  404. ,conversion_component_impression
  405. ,conversion_component_click
  406. ,conversion_component_rate
  407. ,ad_landing_page_impression
  408. ,ad_app_download_half_impression
  409. from media_api.kuaishou_account_report_daily report
  410. left join
  411. `jeecg-boot`.ctop_account_attribution_info sys
  412. on report.advertiser_id = sys.account_id
  413. where report.stat_date between {start_date} and {end_date}
  414. and report.advertiser_id={account_id}
  415. """.format(start_date=start_date, end_date=end_date, account_id=account_id)
  416. print(sql)
  417. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  418. self.conn.commit()
  419. TidbConn.conn_close(conn=self.conn)
  420. except Exception as e:
  421. logging.error('失败详细信息:', repr(e))
  422. def hourly_report(self, account_id, start_date, end_date):
  423. try:
  424. sql = """
  425. replace into application.kuaishou_account_report_hourly_dw
  426. (account_id, stat_date,`hour`, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
  427. company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
  428. play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
  429. cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
  430. event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
  431. event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
  432. event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
  433. event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
  434. event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
  435. event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
  436. event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
  437. event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
  438. event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
  439. play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
  440. event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
  441. event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
  442. event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
  443. event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
  444. event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
  445. event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
  446. event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
  447. event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
  448. union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
  449. key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
  450. event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
  451. ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
  452. event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
  453. event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
  454. event_outbound_call_ratio, event_ad_watch_times,event_pay_purchase_amount_one_day_by_conversion, ad_photo_played_10s
  455. ,ad_photo_played_2s
  456. ,ad_photo_played_75percent
  457. ,approx_pay_cost
  458. ,approx_pay_count
  459. ,approx_pay_ratio
  460. ,cancel_like
  461. ,click_conversion_ratio
  462. ,conversion_cost
  463. ,conversion_cost_by_impression_7d
  464. ,conversion_num
  465. ,conversion_num_by_impression_7d
  466. ,conversion_num_cost
  467. ,conversion_ratio
  468. ,conversion_ratio_by_impression_7d
  469. ,deep_conversion_cost
  470. ,deep_conversion_cost_by_impression_7d
  471. ,deep_conversion_num
  472. ,deep_conversion_num_by_impression_7d
  473. ,deep_conversion_ratio
  474. ,deep_conversion_ratio_by_impression_7d
  475. ,download_completed_cost
  476. ,download_completed_ratio
  477. ,download_conversion_ratio
  478. ,download_installed
  479. ,download_started_cost
  480. ,download_started_ratio
  481. ,event_24h_stay
  482. ,event_24h_stay_by_conversion
  483. ,event_24h_stay_by_conversion_cost
  484. ,event_24h_stay_by_conversion_ratio
  485. ,event_24h_stay_cost
  486. ,event_24h_stay_ratio
  487. ,event_ad_watch_10_times
  488. ,event_ad_watch_10_times_cost
  489. ,event_ad_watch_10_times_ratio
  490. ,event_ad_watch_20_times
  491. ,event_ad_watch_20_times_cost
  492. ,event_ad_watch_20_times_ratio
  493. ,event_ad_watch_5_times
  494. ,event_ad_watch_5_times_cost
  495. ,event_ad_watch_5_times_ratio
  496. ,event_audition
  497. ,event_consultation_valid_retained
  498. ,event_consultation_valid_retained_cost
  499. ,event_consultation_valid_retained_ratio
  500. ,event_conversion_click_cost
  501. ,event_conversion_click_ratio
  502. ,event_credit_grant_first_day_app
  503. ,event_credit_grant_first_day_app_cost
  504. ,event_credit_grant_first_day_app_ratio
  505. ,event_credit_grant_first_day_landing_page
  506. ,event_credit_grant_first_day_landing_page_cost
  507. ,event_credit_grant_first_day_landing_page_ratio
  508. ,event_making_calls
  509. ,event_making_calls_cost
  510. ,event_making_calls_ratio
  511. ,event_order_submit
  512. ,event_pay_purchase_amount_one_day
  513. ,event_pay_purchase_amount_one_day_by_conversion_roi
  514. ,event_pay_purchase_amount_one_day_roi
  515. ,event_pay_purchase_amount_three_day_by_conversion
  516. ,event_pay_purchase_amount_three_day_by_conversion_roi
  517. ,event_pay_purchase_amount_week_by_conversion
  518. ,event_pay_purchase_amount_week_by_conversion_roi
  519. ,event_pay_week_by_conversion
  520. ,event_pay_week_by_conversion_cost
  521. ,event_pay_weighted_purchase_amount
  522. ,event_pay_weighted_purchase_amount_first_day
  523. ,event_pre_component_consultation_valid_retained
  524. ,event_three_day_stay_by_conversion
  525. ,event_three_day_stay_by_conversion_cost
  526. ,event_three_day_stay_by_conversion_ratio
  527. ,event_wechat_qr_code_link_click
  528. ,event_week_stay_by_conversion
  529. ,event_week_stay_by_conversion_cost
  530. ,event_week_stay_by_conversion_ratio
  531. ,live_event_goods_view
  532. ,live_played_3s
  533. ,played_end
  534. ,played_five_seconds
  535. ,played_three_seconds
  536. ,event_next_day_stay_new
  537. ,event_next_day_stay_new_cost
  538. ,event_next_day_stay_new_ratio
  539. ,ad_show
  540. ,event_credit_card_recheck
  541. ,event_credit_card_recheck_first_day
  542. ,event_no_intention
  543. ,event_multi_pay_seven_day_by_conversion
  544. ,event_multi_pay_seven_day_by_conversion_cost
  545. ,mcb_left_time_perf_cpa_bid
  546. ,mcb_left_time_perf_roi_ratio
  547. ,mcb_all_day_perf_cpa_bid
  548. ,mcb_all_day_perf_roi_ratio
  549. ,live_room_avg_played_seconds
  550. ,ad_live_share
  551. ,ad_live_comment
  552. ,live_played_started
  553. ,live_played_started_cost
  554. ,ad_live_follow
  555. ,ad_live_follow_cost
  556. ,simple_live_played_started
  557. ,standard_live_played_started
  558. ,conversion_component_impression
  559. ,conversion_component_click
  560. ,conversion_component_rate
  561. ,ad_landing_page_impression
  562. ,ad_app_download_half_impression
  563. )
  564. select report.advertiser_id as account_id,
  565. stat_date,
  566. `hour`,
  567. project_id,
  568. product_id,
  569. sys.advertiser_id,
  570. company_id,
  571. account_name,
  572. project_name,
  573. advertiser_name,
  574. company_name,
  575. sale_id,
  576. user_id,
  577. org_code,
  578. charge,
  579. `show`,
  580. photo_click,
  581. aclick,
  582. bclick,
  583. photo_click_ratio,
  584. play_3s_ratio,
  585. action_ratio,
  586. impression_1k_cost,
  587. photo_click_cost,
  588. action_cost,
  589. share,
  590. comment,
  591. `like`,
  592. follow,
  593. cancel_follow,
  594. report,
  595. block,
  596. negative,
  597. submit,
  598. download_started,
  599. download_completed,
  600. activation,
  601. event_pay_first_day,
  602. event_pay_purchase_amount_first_day,
  603. event_pay_first_day_roi,
  604. event_pay,
  605. event_pay_purchase_amount,
  606. event_pay_roi,
  607. event_register,
  608. event_register_cost,
  609. event_register_ratio,
  610. event_jin_jian_app,
  611. event_jin_jian_app_cost,
  612. event_credit_grant_app,
  613. event_credit_grant_app_cost,
  614. event_credit_grant_app_ratio,
  615. event_order_paid,
  616. event_order_paid_purchase_amount,
  617. event_order_paid_cost,
  618. event_next_day_stay,
  619. event_next_day_stay_cost,
  620. event_next_day_stay_ratio,
  621. form_count,
  622. form_cost,
  623. form_action_ratio,
  624. event_jin_jian_landing_page,
  625. event_jin_jian_landing_page_cost,
  626. event_credit_grant_landing_page,
  627. event_credit_grant_landing_page_cost,
  628. event_credit_grant_landing_page_ratio,
  629. event_valid_clues,
  630. event_valid_clues_cost,
  631. event_add_wechat,
  632. event_add_wechat_cost,
  633. event_add_wechat_ratio,
  634. event_get_through,
  635. event_get_through_cost,
  636. event_get_through_ratio,
  637. event_app_invoked,
  638. event_app_invoked_cost,
  639. event_app_invoked_ratio,
  640. event_credit_grant_landing_ratio,
  641. play_5s_ratio,
  642. play_end_ratio,
  643. event_new_user_pay,
  644. event_new_user_pay_cost,
  645. event_new_user_pay_ratio,
  646. click_1k_cost,
  647. ad_product_cnt,
  648. event_goods_view,
  649. merchant_reco_fans,
  650. event_order_amount_roi,
  651. event_goods_view_cost,
  652. merchant_reco_fans_cost,
  653. event_button_click,
  654. event_button_click_cost,
  655. event_button_click_ratio,
  656. event_order_paid_roi,
  657. event_new_user_jinjian_app,
  658. event_new_user_jinjian_app_cost,
  659. event_new_user_jinjian_app_roi,
  660. event_new_user_credit_grant_app,
  661. event_new_user_credit_grant_app_cost,
  662. event_new_user_credit_grant_app_roi,
  663. event_new_user_jinjian_page,
  664. event_new_user_jinjian_page_cost,
  665. event_new_user_jinjian_page_roi,
  666. event_new_user_credit_grant_page,
  667. event_new_user_credit_grant_page_cost,
  668. event_new_user_credit_grant_page_roi,
  669. event_appoint_form,
  670. event_appoint_form_cost,
  671. event_appoint_form_ratio,
  672. event_appoint_jump_click,
  673. event_appoint_jump_click_cost,
  674. event_appoint_jump_click_ratio,
  675. union_event_pay_purchase_amount_7d,
  676. union_event_pay_purchase_amount_7d_roi,
  677. placement_type,
  678. ad_scene,
  679. event_order_successed,
  680. ad_photo_played_10s_ratio,
  681. key_action_cost,
  682. event_add_shopping_cart_cost,
  683. event_ad_watch_times_ratio,
  684. event_outbound_call_cost,
  685. event_outbound_call,
  686. action_new_ratio,
  687. event_watch_app_ad,
  688. event_multi_conversion_cost,
  689. event_phone_card_activate,
  690. ad_photo_played_75percent_ratio,
  691. key_action_ratio,
  692. event_ad_watch_times_cost,
  693. event_add_shopping_cart,
  694. key_action,
  695. event_multi_conversion,
  696. event_wechat_connected,
  697. event_dsp_gift_form,
  698. event_intention_confirmed,
  699. event_phone_get_through,
  700. event_multi_conversion_ratio,
  701. event_measurement_house,
  702. ad_photo_played_2s_ratio,
  703. event_outbound_call_ratio,
  704. event_ad_watch_times,
  705. event_pay_purchase_amount_one_day_by_conversion,
  706. ad_photo_played_10s
  707. ,ad_photo_played_2s
  708. ,ad_photo_played_75percent
  709. ,approx_pay_cost
  710. ,approx_pay_count
  711. ,approx_pay_ratio
  712. ,cancel_like
  713. ,click_conversion_ratio
  714. ,conversion_cost
  715. ,conversion_cost_by_impression_7d
  716. ,conversion_num
  717. ,conversion_num_by_impression_7d
  718. ,conversion_num_cost
  719. ,conversion_ratio
  720. ,conversion_ratio_by_impression_7d
  721. ,deep_conversion_cost
  722. ,deep_conversion_cost_by_impression_7d
  723. ,deep_conversion_num
  724. ,deep_conversion_num_by_impression_7d
  725. ,deep_conversion_ratio
  726. ,deep_conversion_ratio_by_impression_7d
  727. ,download_completed_cost
  728. ,download_completed_ratio
  729. ,download_conversion_ratio
  730. ,download_installed
  731. ,download_started_cost
  732. ,download_started_ratio
  733. ,event_24h_stay
  734. ,event_24h_stay_by_conversion
  735. ,event_24h_stay_by_conversion_cost
  736. ,event_24h_stay_by_conversion_ratio
  737. ,event_24h_stay_cost
  738. ,event_24h_stay_ratio
  739. ,event_ad_watch_10_times
  740. ,event_ad_watch_10_times_cost
  741. ,event_ad_watch_10_times_ratio
  742. ,event_ad_watch_20_times
  743. ,event_ad_watch_20_times_cost
  744. ,event_ad_watch_20_times_ratio
  745. ,event_ad_watch_5_times
  746. ,event_ad_watch_5_times_cost
  747. ,event_ad_watch_5_times_ratio
  748. ,event_audition
  749. ,event_consultation_valid_retained
  750. ,event_consultation_valid_retained_cost
  751. ,event_consultation_valid_retained_ratio
  752. ,event_conversion_click_cost
  753. ,event_conversion_click_ratio
  754. ,event_credit_grant_first_day_app
  755. ,event_credit_grant_first_day_app_cost
  756. ,event_credit_grant_first_day_app_ratio
  757. ,event_credit_grant_first_day_landing_page
  758. ,event_credit_grant_first_day_landing_page_cost
  759. ,event_credit_grant_first_day_landing_page_ratio
  760. ,event_making_calls
  761. ,event_making_calls_cost
  762. ,event_making_calls_ratio
  763. ,event_order_submit
  764. ,event_pay_purchase_amount_one_day
  765. ,event_pay_purchase_amount_one_day_by_conversion_roi
  766. ,event_pay_purchase_amount_one_day_roi
  767. ,event_pay_purchase_amount_three_day_by_conversion
  768. ,event_pay_purchase_amount_three_day_by_conversion_roi
  769. ,event_pay_purchase_amount_week_by_conversion
  770. ,event_pay_purchase_amount_week_by_conversion_roi
  771. ,event_pay_week_by_conversion
  772. ,event_pay_week_by_conversion_cost
  773. ,event_pay_weighted_purchase_amount
  774. ,event_pay_weighted_purchase_amount_first_day
  775. ,event_pre_component_consultation_valid_retained
  776. ,event_three_day_stay_by_conversion
  777. ,event_three_day_stay_by_conversion_cost
  778. ,event_three_day_stay_by_conversion_ratio
  779. ,event_wechat_qr_code_link_click
  780. ,event_week_stay_by_conversion
  781. ,event_week_stay_by_conversion_cost
  782. ,event_week_stay_by_conversion_ratio
  783. ,live_event_goods_view
  784. ,live_played_3s
  785. ,played_end
  786. ,played_five_seconds
  787. ,played_three_seconds
  788. ,event_next_day_stay_new
  789. ,event_next_day_stay_new_cost
  790. ,event_next_day_stay_new_ratio
  791. ,ad_show
  792. ,event_credit_card_recheck
  793. ,event_credit_card_recheck_first_day
  794. ,event_no_intention
  795. ,event_multi_pay_seven_day_by_conversion
  796. ,event_multi_pay_seven_day_by_conversion_cost
  797. ,mcb_left_time_perf_cpa_bid
  798. ,mcb_left_time_perf_roi_ratio
  799. ,mcb_all_day_perf_cpa_bid
  800. ,mcb_all_day_perf_roi_ratio
  801. ,live_room_avg_played_seconds
  802. ,ad_live_share
  803. ,ad_live_comment
  804. ,live_played_started
  805. ,live_played_started_cost
  806. ,ad_live_follow
  807. ,ad_live_follow_cost
  808. ,simple_live_played_started
  809. ,standard_live_played_started
  810. ,conversion_component_impression
  811. ,conversion_component_click
  812. ,conversion_component_rate
  813. ,ad_landing_page_impression
  814. ,ad_app_download_half_impression
  815. from media_api.kuaishou_account_report_hourly report
  816. left join
  817. `jeecg-boot`.ctop_account_attribution_info sys
  818. on report.advertiser_id = sys.account_id
  819. where report.stat_date between {start_date} and {end_date}
  820. and report.advertiser_id={account_id}
  821. """.format(start_date=start_date, end_date=end_date, account_id=account_id)
  822. print(sql)
  823. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  824. self.conn.commit()
  825. TidbConn.conn_close(conn=self.conn)
  826. except Exception as e:
  827. logging.error('失败详细信息:', repr(e))
  828. def handler(self, date_type, account_id, start_date, end_date):
  829. if date_type == "daily":
  830. self.daily_report(account_id, start_date, end_date)
  831. else:
  832. self.hourly_report(account_id, start_date, end_date)