MaterialImageDailyReport.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/15 5:10 下午
  4. # @Site :
  5. # @File : MateirialImageDailyReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. import logging
  9. from math import ceil
  10. from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
  11. from Apietl.utlis.Logger import Logger
  12. from Apietl.utlis.Utils import Utils
  13. from Apietl.conn.TidbConn import TidbConn
  14. class MateirialImageDailyReport:
  15. def __init__(self):
  16. self.conn = TidbConn.get_connection()
  17. self.parm = Utils.get_args()
  18. self.start_time = self.parm[0]
  19. self.end_time = self.parm[1]
  20. def daily_report(self):
  21. try:
  22. sql = """select advertiser_id from media_api.bytedance_material_report_daily where
  23. stat_datetime between {start_time} and {end_time} and image_mode in
  24. ('CREATIVE_IMAGE_MODE_SMALL', 'CREATIVE_IMAGE_MODE_LARGE', 'CREATIVE_IMAGE_MODE_LARGE_VERTICAL',
  25. 'CREATIVE_IMAGE_MODE_GROUP', 'CREATIVE_IMAGE_MODE_GIF', 'TOUTIAO_SEARCH_AD_IMAGE', 'SEARCH_AD_SMALL_IMAGE',
  26. 'CREATIVE_IMAGE_MODE_UNION_SPLASH')
  27. group by advertiser_id""".format(
  28. start_time=self.start_time, end_time=self.end_time)
  29. account_list = TidbConn.quary(self.conn, sql)
  30. for account_id in account_list:
  31. sql = """
  32. replace into application.bytedance_material_image_report_daily_dw(account_id, material_id, image_mode, inventory,
  33. stat_datetime, project_id, product_id, advertiser_id,
  34. company_id, account_name, project_name,
  35. advertiser_name, company_name, sale_id, user_id,
  36. image_name,
  37. cost, `show`, avg_show_cost, click,
  38. avg_click_cost, ctr, `convert`, convert_cost,
  39. convert_rate, deep_convert, deep_convert_cost,
  40. deep_convert_rate, attribution_convert,
  41. attribution_convert_cost, attribution_deep_convert,
  42. attribution_deep_convert_cost, download_start,
  43. download_start_cost, download_start_rate,
  44. download_finish, download_finish_cost,
  45. download_finish_rate, click_install, install_finish,
  46. install_finish_cost, install_finish_rate, active,
  47. active_cost, active_rate, register,
  48. active_register_cost, active_register_rate,
  49. active_pay_amount, next_day_open, next_day_open_cost,
  50. next_day_open_rate, attribution_next_day_open_cnt,
  51. attribution_next_day_open_cost,
  52. attribution_next_day_open_rate, game_addiction,
  53. game_addiction_cost, game_addiction_rate, pay_count,
  54. active_pay_cost, active_pay_rate, loan_completion,
  55. loan_completion_cost, loan_completion_rate,
  56. pre_loan_credit, pre_loan_credit_cost, loan_credit,
  57. loan_credit_cost, loan_credit_rate, in_app_uv,
  58. in_app_detail_uv, in_app_cart, in_app_pay,
  59. in_app_order, attribution_game_pay_7d_count,
  60. attribution_game_pay_7d_cost,
  61. attribution_active_pay_7d_per_count, game_pay_cost,
  62. game_pay_count, phone, form, map_search, button, view,
  63. download, qq, lottery, vote, message, redirect,
  64. shopping, consult, wechat, phone_confirm,
  65. phone_connect, consult_effective, coupon,
  66. coupon_single_page, redirect_to_shop, poi_collect,
  67. poi_address_click, luban_order_cnt,
  68. luban_order_stat_amount, luban_order_roi,
  69. luban_live_enter_cnt, live_watch_one_minute_count,
  70. luban_live_follow_cnt, live_fans_club_join_cnt,
  71. luban_live_comment_cnt, luban_live_share_cnt,
  72. luban_live_gift_cnt, luban_live_gift_amount,
  73. luban_live_slidecart_click_cnt,
  74. luban_live_click_product_cnt,
  75. luban_live_pay_order_count,
  76. luban_live_pay_order_stat_cost, wechat_login_count,
  77. attribution_wechat_login_30d_count, wechat_login_cost,
  78. attribution_wechat_login_30d_cost,
  79. wechat_first_pay_count,
  80. attribution_wechat_first_pay_30d_count,
  81. wechat_first_pay_cost,
  82. attribution_wechat_first_pay_30d_cost,
  83. wechat_first_pay_rate,
  84. attribution_wechat_first_pay_30d_rate,
  85. wechat_pay_amount, attribution_wechat_pay_30d_amount,
  86. attribution_wechat_pay_30d_roi, phone_effective,
  87. total_play, valid_play, valid_play_cost,
  88. valid_play_rate, play_25_feed_break,
  89. play_50_feed_break, play_75_feed_break,
  90. play_100_feed_break, average_play_time_per_play,
  91. play_over_rate, wifi_play_rate, wifi_play,
  92. play_duration_sum, advanced_creative_phone_click,
  93. advanced_creative_counsel_click,
  94. advanced_creative_form_click,
  95. advanced_creative_coupon_addition,
  96. advanced_creative_form_submit, card_show, share,
  97. comment, `like`, follow, home_visited,
  98. ies_challenge_click, ies_music_click, location_click,
  99. message_action, click_landing_page, click_shopwindow,
  100. click_website, click_download, click_call_dy, cpc,
  101. cpm, cpa, interact_per_cost, convert_show_rate,
  102. play_duration_10s_rate, play_50_feed_break_rate,
  103. play_25_feed_break_rate, play_duration_5s_rate,
  104. play_duration_2s_rate, average_play_progress,
  105. play_100_feed_break_rate, play_duration_3s_rate,
  106. play_75_feed_break_rate, play_duration,
  107. play_duration_3s, play_duration_2s, play_duration_10s,
  108. average_video_play, avg_rank,
  109. submit_certification_count, approval_count,
  110. first_order_count, first_rental_order_count,
  111. commute_first_pay_count,image_url,signature)
  112. select report.advertiser_id account_id, #'账户ID'
  113. report.material_id, #头条素材id
  114. report.image_mode, #素材类型
  115. report.inventory, #广告位
  116. report.stat_datetime, #数据起始时间
  117. cua.project_id, #项目id
  118. product.id product_id, #项目中产品id
  119. cua.advertiser_id, #广告主id
  120. uc.company_id, #运营人的公司id
  121. cua.auth_name account_name, #账户名称
  122. cp.project_name, #项目名称
  123. ca.name advertiser_name, #广告主名称
  124. uc.company_name, #运营人的公司名称
  125. cp.sale_id, #项目里的销售id
  126. cua.user_id, #运营id
  127. image.filename,
  128. report.`cost`,
  129. report.`show`,
  130. report.`avg_show_cost`,
  131. report.`click`,
  132. report.`avg_click_cost`,
  133. report.`ctr`,
  134. report.`convert`,
  135. report.`convert_cost`,
  136. report.`convert_rate`,
  137. report.`deep_convert`,
  138. report.`deep_convert_cost`,
  139. report.`deep_convert_rate`,
  140. report.`attribution_convert`,
  141. report.`attribution_convert_cost`,
  142. report.`attribution_deep_convert`,
  143. report.`attribution_deep_convert_cost`,
  144. report.`download_start`,
  145. report.`download_start_cost`,
  146. report.`download_start_rate`,
  147. report.`download_finish`,
  148. report.`download_finish_cost`,
  149. report.`download_finish_rate`,
  150. report.`click_install`,
  151. report.`install_finish`,
  152. report.`install_finish_cost`,
  153. report.`install_finish_rate`,
  154. report.`active`,
  155. report.`active_cost`,
  156. report.`active_rate`,
  157. report.`register`,
  158. report.`active_register_cost`,
  159. report.`active_register_rate`,
  160. report.`active_pay_amount`,
  161. report.`next_day_open`,
  162. report.`next_day_open_cost`,
  163. report.`next_day_open_rate`,
  164. report.`attribution_next_day_open_cnt`,
  165. report.`attribution_next_day_open_cost`,
  166. report.`attribution_next_day_open_rate`,
  167. report.`game_addiction`,
  168. report.`game_addiction_cost`,
  169. report.`game_addiction_rate`,
  170. report.`pay_count`,
  171. report.`active_pay_cost`,
  172. report.`active_pay_rate`,
  173. report.`loan_completion`,
  174. report.`loan_completion_cost`,
  175. report.`loan_completion_rate`,
  176. report.`pre_loan_credit`,
  177. report.`pre_loan_credit_cost`,
  178. report.`loan_credit`,
  179. report.`loan_credit_cost`,
  180. report.`loan_credit_rate`,
  181. report.`in_app_uv`,
  182. report.`in_app_detail_uv`,
  183. report.`in_app_cart`,
  184. report.`in_app_pay`,
  185. report.`in_app_order`,
  186. report.`attribution_game_pay_7d_count`,
  187. report.`attribution_game_pay_7d_cost`,
  188. report.`attribution_active_pay_7d_per_count`,
  189. report.`game_pay_cost`,
  190. report.`game_pay_count`,
  191. report.`phone`,
  192. report.`form`,
  193. report.`map_search`,
  194. report.`button`,
  195. report.`view`,
  196. report.`download`,
  197. report.`qq`,
  198. report.`lottery`,
  199. report.`vote`,
  200. report.`message`,
  201. report.`redirect`,
  202. report.`shopping`,
  203. report.`consult`,
  204. report.`wechat`,
  205. report.`phone_confirm`,
  206. report.`phone_connect`,
  207. report.`consult_effective`,
  208. report.`coupon`,
  209. report.`coupon_single_page`,
  210. report.`redirect_to_shop`,
  211. report.`poi_collect`,
  212. report.`poi_address_click`,
  213. report.`luban_order_cnt`,
  214. report.`luban_order_stat_amount`,
  215. report.`luban_order_roi`,
  216. report.`luban_live_enter_cnt`,
  217. report.`live_watch_one_minute_count`,
  218. report.`luban_live_follow_cnt`,
  219. report.`live_fans_club_join_cnt`,
  220. report.`luban_live_comment_cnt`,
  221. report.`luban_live_share_cnt`,
  222. report.`luban_live_gift_cnt`,
  223. report.`luban_live_gift_amount`,
  224. report.`luban_live_slidecart_click_cnt`,
  225. report.`luban_live_click_product_cnt`,
  226. report.`luban_live_pay_order_count`,
  227. report.`luban_live_pay_order_stat_cost`,
  228. report.`wechat_login_count`,
  229. report.`attribution_wechat_login_30d_count`,
  230. report.`wechat_login_cost`,
  231. report.`attribution_wechat_login_30d_cost`,
  232. report.`wechat_first_pay_count`,
  233. report.`attribution_wechat_first_pay_30d_count`,
  234. report.`wechat_first_pay_cost`,
  235. report.`attribution_wechat_first_pay_30d_cost`,
  236. report.`wechat_first_pay_rate`,
  237. report.`attribution_wechat_first_pay_30d_rate`,
  238. report.`wechat_pay_amount`,
  239. report.`attribution_wechat_pay_30d_amount`,
  240. report.`attribution_wechat_pay_30d_roi`,
  241. report.`phone_effective`,
  242. report.`total_play`,
  243. report.`valid_play`,
  244. report.`valid_play_cost`,
  245. report.`valid_play_rate`,
  246. report.`play_25_feed_break`,
  247. report.`play_50_feed_break`,
  248. report.`play_75_feed_break`,
  249. report.`play_100_feed_break`,
  250. report.`average_play_time_per_play`,
  251. report.`play_over_rate`,
  252. report.`wifi_play_rate`,
  253. report.`wifi_play`,
  254. report.`play_duration_sum`,
  255. report.`advanced_creative_phone_click`,
  256. report.`advanced_creative_counsel_click`,
  257. report.`advanced_creative_form_click`,
  258. report.`advanced_creative_coupon_addition`,
  259. report.`advanced_creative_form_submit`,
  260. report.`card_show`,
  261. report.`share`,
  262. report.`comment`,
  263. report.`like`,
  264. report.`follow`,
  265. report.`home_visited`,
  266. report.`ies_challenge_click`,
  267. report.`ies_music_click`,
  268. report.`location_click`,
  269. report.`message_action`,
  270. report.`click_landing_page`,
  271. report.`click_shopwindow`,
  272. report.`click_website`,
  273. report.`click_download`,
  274. report.`click_call_dy`,
  275. report.`cpc`,
  276. report.`cpm`,
  277. report.`cpa`,
  278. report.`interact_per_cost`,
  279. report.`convert_show_rate`,
  280. report.`play_duration_10s_rate`,
  281. report.`play_50_feed_break_rate`,
  282. report.`play_25_feed_break_rate`,
  283. report.`play_duration_5s_rate`,
  284. report.`play_duration_2s_rate`,
  285. report.`average_play_progress`,
  286. report.`play_100_feed_break_rate`,
  287. report.`play_duration_3s_rate`,
  288. report.`play_75_feed_break_rate`,
  289. report.`play_duration`,
  290. report.`play_duration_3s`,
  291. report.`play_duration_2s`,
  292. report.`play_duration_10s`,
  293. report.`average_video_play`,
  294. report.`avg_rank`,
  295. report.`submit_certification_count`,
  296. report.`approval_count`,
  297. report.`first_order_count`,
  298. report.`first_rental_order_count`,
  299. report.`commute_first_pay_count`,
  300. image.image_url,
  301. image.signature
  302. from media_api.bytedance_material_report_daily report
  303. left join
  304. `media_api`.bytedance_file_image_get image
  305. on report.material_id = image.material_id
  306. and report.advertiser_id = image.advertiser_id
  307. left join `jeecg-boot`.ctop_user_allocation cua
  308. on report.advertiser_id = cua.account_id
  309. left join `jeecg-boot`.ctop_advertiser ca
  310. on cua.advertiser_id = ca.id
  311. left join `jeecg-boot`.ctop_project cp
  312. on cua.project_id = cp.id
  313. left join `jeecg-boot`.user_company uc
  314. on cua.user_id = uc.user_id
  315. left join `jeecg-boot`.ctop_product product
  316. on cp.product_id = product.id
  317. left join `jeecg-boot`.sys_user su
  318. on cua.user_id = su.id
  319. where report.image_mode in
  320. ('CREATIVE_IMAGE_MODE_SMALL', 'CREATIVE_IMAGE_MODE_LARGE', 'CREATIVE_IMAGE_MODE_LARGE_VERTICAL',
  321. 'CREATIVE_IMAGE_MODE_GROUP', 'CREATIVE_IMAGE_MODE_GIF', 'TOUTIAO_SEARCH_AD_IMAGE', 'SEARCH_AD_SMALL_IMAGE',
  322. 'CREATIVE_IMAGE_MODE_UNION_SPLASH')
  323. and report.stat_datetime between {start_time} and {end_time}
  324. and report.advertiser_id = {account_id}
  325. """.format( start_time=self.start_time, end_time=self.end_time, account_id=account_id[0])
  326. print(sql)
  327. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  328. self.conn.commit()
  329. TidbConn.conn_close(conn=self.conn)
  330. return 0
  331. except Exception as e:
  332. logging.error(e)
  333. return -1
  334. if __name__ == '__main__':
  335. status = MateirialImageDailyReport().daily_report()
  336. if status == 0:
  337. print("作业执行成功")
  338. exit(0)
  339. else:
  340. print("作业执行失败")
  341. exit(-1)