AppKuaiShouAccountAdAceneReport.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. # Author zhaohailiang
  2. # coding=utf-8
  3. # @Time : 2021/12/20 2:20 下午
  4. # @Site :
  5. # @File : AppKuaishouAccountAdAceneReport.py
  6. # @Software: PyCharm
  7. # @contact: zhaohailiang@c-top.com.cn
  8. # @Tel 18201631162
  9. import logging
  10. from Apietl.conn.TidbConn import TidbConn
  11. from Apietl.utlis.Utils import Utils
  12. class AppKuaishouAccountAdAceneReport:
  13. def __init__(self):
  14. self.conn = TidbConn.get_connection()
  15. self.parm = Utils.get_task_args()
  16. self.date_time = self.parm[0]
  17. def taskHandler(self):
  18. try:
  19. sql = """
  20. SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
  21. replace into `application`.`app_kuaishou_account_ad_scene_report_d`
  22. (
  23. account_id,
  24. stat_date,
  25. project_id,
  26. product_id,
  27. advertiser_id,
  28. company_id,
  29. account_name,
  30. project_name,
  31. advertiser_name,
  32. company_name,
  33. sale_id,
  34. sale_name,
  35. user_id,
  36. user_name,
  37. leader_id,
  38. leader_name,
  39. org_code,
  40. charge,
  41. `show`,
  42. photo_click,
  43. aclick,
  44. bclick,
  45. photo_click_ratio,
  46. play_3s_ratio,
  47. action_ratio,
  48. impression_1k_cost,
  49. photo_click_cost,
  50. action_cost,
  51. `share`,
  52. `comment`,
  53. `like`,
  54. follow,
  55. cancel_follow,
  56. report,
  57. block,
  58. negative,
  59. submit,
  60. download_started,
  61. download_completed,
  62. activation,
  63. event_pay_first_day,
  64. event_pay_purchase_amount_first_day,
  65. event_pay_first_day_roi,
  66. event_pay,
  67. event_pay_purchase_amount,
  68. event_pay_roi,
  69. event_register,
  70. event_register_cost,
  71. event_register_ratio,
  72. event_jin_jian_app,
  73. event_jin_jian_app_cost,
  74. event_credit_grant_app,
  75. event_credit_grant_app_cost,
  76. event_credit_grant_app_ratio,
  77. event_order_paid,
  78. event_order_paid_purchase_amount,
  79. event_order_paid_cost,
  80. event_next_day_stay,
  81. event_next_day_stay_cost,
  82. event_next_day_stay_ratio,
  83. form_count,
  84. form_cost,
  85. form_action_ratio,
  86. event_jin_jian_landing_page,
  87. event_jin_jian_landing_page_cost,
  88. event_credit_grant_landing_page,
  89. event_credit_grant_landing_page_cost,
  90. event_credit_grant_landing_page_ratio,
  91. event_valid_clues,
  92. event_valid_clues_cost,
  93. event_add_wechat,
  94. event_add_wechat_cost,
  95. event_add_wechat_ratio,
  96. event_get_through,
  97. event_get_through_cost,
  98. event_get_through_ratio,
  99. event_app_invoked,
  100. event_app_invoked_cost,
  101. event_app_invoked_ratio,
  102. event_credit_grant_landing_ratio,
  103. play_5s_ratio,
  104. play_end_ratio,
  105. event_new_user_pay,
  106. event_new_user_pay_cost,
  107. event_new_user_pay_ratio,
  108. click_1k_cost,
  109. ad_product_cnt,
  110. event_goods_view,
  111. merchant_reco_fans,
  112. event_order_amount_roi,
  113. event_goods_view_cost,
  114. merchant_reco_fans_cost,
  115. event_button_click,
  116. event_button_click_cost,
  117. event_button_click_ratio,
  118. event_order_paid_roi,
  119. event_new_user_jinjian_app,
  120. event_new_user_jinjian_app_cost,
  121. event_new_user_jinjian_app_roi,
  122. event_new_user_credit_grant_app,
  123. event_new_user_credit_grant_app_cost,
  124. event_new_user_credit_grant_app_roi,
  125. event_new_user_jinjian_page,
  126. event_new_user_jinjian_page_cost,
  127. event_new_user_jinjian_page_roi,
  128. event_new_user_credit_grant_page,
  129. event_new_user_credit_grant_page_cost,
  130. event_new_user_credit_grant_page_roi,
  131. event_appoint_form,
  132. event_appoint_form_cost,
  133. event_appoint_form_ratio,
  134. event_appoint_jump_click,
  135. event_appoint_jump_click_cost,
  136. event_appoint_jump_click_ratio,
  137. union_event_pay_purchase_amount_7d,
  138. union_event_pay_purchase_amount_7d_roi,
  139. placement_type,
  140. ad_scene,
  141. event_order_successed,
  142. ad_photo_played_10s_ratio,
  143. key_action_cost,
  144. event_add_shopping_cart_cost,
  145. event_ad_watch_times_ratio,
  146. event_outbound_call_cost,
  147. event_outbound_call,
  148. action_new_ratio,
  149. event_watch_app_ad,
  150. event_multi_conversion_cost,
  151. event_phone_card_activate,
  152. ad_photo_played_75percent_ratio,
  153. key_action_ratio,
  154. event_ad_watch_times_cost,
  155. event_add_shopping_cart,
  156. key_action,
  157. event_multi_conversion,
  158. event_wechat_connected,
  159. event_dsp_gift_form,
  160. event_intention_confirmed,
  161. event_phone_get_through,
  162. event_multi_conversion_ratio,
  163. event_measurement_house,
  164. ad_photo_played_2s_ratio,
  165. event_outbound_call_ratio,
  166. event_ad_watch_times
  167. )
  168. select
  169. report.advertiser_id account_id,
  170. report.stat_date,
  171. bei.project_id,
  172. bei.product_id,
  173. bei.advertiser_id,
  174. bei.company_id,
  175. bei.account_name,
  176. bei.project_name,
  177. bei.advertiser_name,
  178. bei.company_name,
  179. bei.sale_id,
  180. bei.sale_name,
  181. bei.user_id,
  182. bei.user_name,
  183. bei.leader_id,
  184. bei.leader_name,
  185. bei.org_code,
  186. report.charge,
  187. report.`show`,
  188. report.photo_click,
  189. report.aclick,
  190. report.bclick,
  191. report.photo_click_ratio,
  192. report.play_3s_ratio,
  193. report.action_ratio,
  194. report.impression_1k_cost,
  195. report.photo_click_cost,
  196. report.action_cost,
  197. report.`share`,
  198. report.`comment`,
  199. report.`like`,
  200. report.follow,
  201. report.cancel_follow,
  202. report.report,
  203. report.block,
  204. report.negative,
  205. report.submit,
  206. report.download_started,
  207. report.download_completed,
  208. report.activation,
  209. report.event_pay_first_day,
  210. report.event_pay_purchase_amount_first_day,
  211. report.event_pay_first_day_roi,
  212. report.event_pay,
  213. report.event_pay_purchase_amount,
  214. report.event_pay_roi,
  215. report.event_register,
  216. report.event_register_cost,
  217. report.event_register_ratio,
  218. report.event_jin_jian_app,
  219. report.event_jin_jian_app_cost,
  220. report.event_credit_grant_app,
  221. report.event_credit_grant_app_cost,
  222. report.event_credit_grant_app_ratio,
  223. report.event_order_paid,
  224. report.event_order_paid_purchase_amount,
  225. report.event_order_paid_cost,
  226. report.event_next_day_stay,
  227. report.event_next_day_stay_cost,
  228. report.event_next_day_stay_ratio,
  229. report.form_count,
  230. report.form_cost,
  231. report.form_action_ratio,
  232. report.event_jin_jian_landing_page,
  233. report.event_jin_jian_landing_page_cost,
  234. report.event_credit_grant_landing_page,
  235. report.event_credit_grant_landing_page_cost,
  236. report.event_credit_grant_landing_page_ratio,
  237. report.event_valid_clues,
  238. report.event_valid_clues_cost,
  239. report.event_add_wechat,
  240. report.event_add_wechat_cost,
  241. report.event_add_wechat_ratio,
  242. report.event_get_through,
  243. report.event_get_through_cost,
  244. report.event_get_through_ratio,
  245. report.event_app_invoked,
  246. report.event_app_invoked_cost,
  247. report.event_app_invoked_ratio,
  248. report.event_credit_grant_landing_ratio,
  249. report.play_5s_ratio,
  250. report.play_end_ratio,
  251. report.event_new_user_pay,
  252. report.event_new_user_pay_cost,
  253. report.event_new_user_pay_ratio,
  254. report.click_1k_cost,
  255. report.ad_product_cnt,
  256. report.event_goods_view,
  257. report.merchant_reco_fans,
  258. report.event_order_amount_roi,
  259. report.event_goods_view_cost,
  260. report.merchant_reco_fans_cost,
  261. report.event_button_click,
  262. report.event_button_click_cost,
  263. report.event_button_click_ratio,
  264. report.event_order_paid_roi,
  265. report.event_new_user_jinjian_app,
  266. report.event_new_user_jinjian_app_cost,
  267. report.event_new_user_jinjian_app_roi,
  268. report.event_new_user_credit_grant_app,
  269. report.event_new_user_credit_grant_app_cost,
  270. report.event_new_user_credit_grant_app_roi,
  271. report.event_new_user_jinjian_page,
  272. report.event_new_user_jinjian_page_cost,
  273. report.event_new_user_jinjian_page_roi,
  274. report.event_new_user_credit_grant_page,
  275. report.event_new_user_credit_grant_page_cost,
  276. report.event_new_user_credit_grant_page_roi,
  277. report.event_appoint_form,
  278. report.event_appoint_form_cost,
  279. report.event_appoint_form_ratio,
  280. report.event_appoint_jump_click,
  281. report.event_appoint_jump_click_cost,
  282. report.event_appoint_jump_click_ratio,
  283. report.union_event_pay_purchase_amount_7d,
  284. report.union_event_pay_purchase_amount_7d_roi,
  285. report.placement_type,
  286. report.ad_scene,
  287. report.event_order_successed,
  288. report.ad_photo_played_10s_ratio,
  289. report.key_action_cost,
  290. report.event_add_shopping_cart_cost,
  291. report.event_ad_watch_times_ratio,
  292. report.event_outbound_call_cost,
  293. report.event_outbound_call,
  294. report.action_new_ratio,
  295. report.event_watch_app_ad,
  296. report.event_multi_conversion_cost,
  297. report.event_phone_card_activate,
  298. report.ad_photo_played_75percent_ratio,
  299. report.key_action_ratio,
  300. report.event_ad_watch_times_cost,
  301. report.event_add_shopping_cart,
  302. report.key_action,
  303. report.event_multi_conversion,
  304. report.event_wechat_connected,
  305. report.event_dsp_gift_form,
  306. report.event_intention_confirmed,
  307. report.event_phone_get_through,
  308. report.event_multi_conversion_ratio,
  309. report.event_measurement_house,
  310. report.ad_photo_played_2s_ratio,
  311. report.event_outbound_call_ratio,
  312. report.event_ad_watch_times
  313. from (select * from `media_api`.kuaishou_account_ad_scene_report_daily where stat_date={date_time}) report
  314. LEFT JOIN (
  315. SELECT
  316. cua.account_id id,
  317. cua.account_id account_id,
  318. cp.id project_id,
  319. product.id product_id,
  320. ca.id advertiser_id,
  321. uc.company_id company_id,
  322. cua.auth_name account_name,
  323. cp.project_name project_name,
  324. ca.`name` advertiser_name,
  325. uc.company_name company_name,
  326. cp.sale_id sale_id,
  327. sale.realname sale_name,
  328. su.id user_id,
  329. su.realname user_name,
  330. su.leader_id,
  331. lea.realname leader_name,
  332. su.org_code org_code
  333. FROM
  334. `jeecg-boot`.ctop_user_allocation cua
  335. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  336. LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
  337. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  338. LEFT JOIN `jeecg-boot`.sys_user sale ON sale.id = cp.sale_id
  339. LEFT JOIN `jeecg-boot`.sys_user lea ON lea.id = su.leader_id
  340. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  341. LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
  342. WHERE
  343. cua.account_id IS NOT NULL) bei
  344. ON report.advertiser_id = bei.account_id;
  345. """.format(date_time=self.date_time)
  346. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  347. self.conn.commit()
  348. TidbConn.conn_close(conn=self.conn)
  349. return 0
  350. except Exception as e:
  351. logging.error(e)
  352. return -1
  353. if __name__ == '__main__':
  354. status = AppKuaishouAccountAdAceneReport().taskHandler()
  355. if status == 0:
  356. print("作业执行成功")
  357. exit(0)
  358. else:
  359. print("作业执行失败")
  360. exit(-1)