|
@@ -0,0 +1,320 @@
|
|
|
|
+# Author renyupeng
|
|
|
|
+# coding=utf-8
|
|
|
|
+# @Time : 2021/9/27 10:50 上午
|
|
|
|
+# @Site :
|
|
|
|
+# @File : AdvertiserDailyReport.py
|
|
|
|
+# @Software: PyCharm
|
|
|
|
+# @contact: renyupeng@c-top.com.cn
|
|
|
|
+# @Tel 1501435553
|
|
|
|
+import logging
|
|
|
|
+from math import ceil
|
|
|
|
+
|
|
|
|
+from Apietl.utlis.Logger import Logger
|
|
|
|
+from Apietl.utlis.Utils import Utils
|
|
|
|
+from Apietl.conn.TidbConn import TidbConn
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class AdvertiserSumDailyReport:
|
|
|
|
+ def __init__(self):
|
|
|
|
+ self.conn = TidbConn.get_connection()
|
|
|
|
+ self.parm = Utils.get_args()
|
|
|
|
+ self.start_time = 20250227
|
|
|
|
+
|
|
|
|
+ def daily_report(self):
|
|
|
|
+ try:
|
|
|
|
+ sql = """select count(1) from media_api.bytedance_advertiser_report_hourly where
|
|
|
|
+ stat_datetime = {start_time} """.format(
|
|
|
|
+ start_time=self.start_time)
|
|
|
|
+ totalNum = TidbConn.quary(self.conn, sql)[0][0]
|
|
|
|
+ pageCount = ceil(totalNum / 20000)
|
|
|
|
+ for i in range(pageCount):
|
|
|
|
+ sql = """
|
|
|
|
+ replace into application.bytedance_advertiser_report_daily_dw(account_id, stat_datetime, project_id, product_id,
|
|
|
|
+ advertiser_id, company_id, account_name, project_name,
|
|
|
|
+ advertiser_name, company_name, sale_id, user_id, org_code,
|
|
|
|
+ cost, `show`, avg_show_cost, click, avg_click_cost, ctr,
|
|
|
|
+ `convert`, convert_cost, convert_rate, deep_convert,
|
|
|
|
+ deep_convert_cost, deep_convert_rate, attribution_convert,
|
|
|
|
+ attribution_convert_cost, attribution_deep_convert,
|
|
|
|
+ attribution_deep_convert_cost, download_start,
|
|
|
|
+ download_start_cost, download_start_rate, download_finish,
|
|
|
|
+ download_finish_cost, download_finish_rate, click_install,
|
|
|
|
+ install_finish, install_finish_cost, install_finish_rate,
|
|
|
|
+ active, active_cost, active_rate, register,
|
|
|
|
+ active_register_cost, active_register_rate, next_day_open,
|
|
|
|
+ next_day_open_cost, next_day_open_rate,
|
|
|
|
+ attribution_next_day_open_cnt,
|
|
|
|
+ attribution_next_day_open_cost,
|
|
|
|
+ attribution_next_day_open_rate, game_addiction,
|
|
|
|
+ game_addiction_cost, game_addiction_rate, pay_count,
|
|
|
|
+ active_pay_cost, active_pay_rate, loan_completion,
|
|
|
|
+ loan_completion_cost, loan_completion_rate,
|
|
|
|
+ pre_loan_credit, pre_loan_credit_cost, loan_credit,
|
|
|
|
+ loan_credit_cost, loan_credit_rate, in_app_uv,
|
|
|
|
+ in_app_detail_uv, in_app_cart, in_app_pay, in_app_order,
|
|
|
|
+ attribution_game_pay_7d_count,
|
|
|
|
+ attribution_game_pay_7d_cost,
|
|
|
|
+ attribution_active_pay_7d_per_count, game_pay_cost,
|
|
|
|
+ game_pay_count, phone, form, map_search, button, view,
|
|
|
|
+ download, qq, lottery, vote, message, redirect, shopping,
|
|
|
|
+ consult, wechat, phone_confirm, phone_connect,
|
|
|
|
+ consult_effective, coupon, coupon_single_page,
|
|
|
|
+ redirect_to_shop, poi_collect, poi_address_click,
|
|
|
|
+ luban_order_cnt, luban_order_stat_amount, luban_order_roi,
|
|
|
|
+ luban_live_enter_cnt, live_watch_one_minute_count,
|
|
|
|
+ luban_live_follow_cnt, live_fans_club_join_cnt,
|
|
|
|
+ luban_live_comment_cnt, luban_live_share_cnt,
|
|
|
|
+ luban_live_gift_cnt, luban_live_gift_amount,
|
|
|
|
+ luban_live_slidecart_click_cnt,
|
|
|
|
+ luban_live_click_product_cnt, luban_live_pay_order_count,
|
|
|
|
+ luban_live_pay_order_stat_cost,
|
|
|
|
+ live_component_click_count, live_component_click_cost,
|
|
|
|
+ live_component_click_rate, wechat_login_count,
|
|
|
|
+ attribution_wechat_login_30d_count, wechat_login_cost,
|
|
|
|
+ attribution_wechat_login_30d_cost, wechat_first_pay_count,
|
|
|
|
+ attribution_wechat_first_pay_30d_count,
|
|
|
|
+ wechat_first_pay_cost,
|
|
|
|
+ attribution_wechat_first_pay_30d_cost,
|
|
|
|
+ wechat_first_pay_rate,
|
|
|
|
+ attribution_wechat_first_pay_30d_rate, wechat_pay_amount,
|
|
|
|
+ attribution_wechat_pay_30d_amount,
|
|
|
|
+ attribution_wechat_pay_30d_roi, phone_effective,
|
|
|
|
+ total_play, valid_play, valid_play_cost, valid_play_rate,
|
|
|
|
+ play_25_feed_break, play_50_feed_break,
|
|
|
|
+ play_75_feed_break, play_100_feed_break,
|
|
|
|
+ average_play_time_per_play, play_over_rate,
|
|
|
|
+ wifi_play_rate, wifi_play, play_duration_sum,
|
|
|
|
+ advanced_creative_phone_click,
|
|
|
|
+ advanced_creative_counsel_click,
|
|
|
|
+ advanced_creative_form_click,
|
|
|
|
+ advanced_creative_coupon_addition,
|
|
|
|
+ advanced_creative_form_submit, card_show, share, comment,
|
|
|
|
+ `like`, follow, home_visited, ies_challenge_click,
|
|
|
|
+ ies_music_click, location_click, message_action,
|
|
|
|
+ click_landing_page, click_shopwindow, click_website,
|
|
|
|
+ click_download, click_call_dy, submit_certification_count,
|
|
|
|
+ approval_count, first_rental_order_count,
|
|
|
|
+ first_order_count, commute_first_pay_count,
|
|
|
|
+ attribution_active_pay_intra_one_day_roi
|
|
|
|
+,attribution_active_pay_intra_one_day_amount
|
|
|
|
+,attribution_active_pay_intra_one_day_rate
|
|
|
|
+,attribution_active_pay_intra_one_day_cost
|
|
|
|
+,attribution_active_pay_intra_one_day_count,stat_pay_amount)
|
|
|
|
+select a.advertiser_id account_id,
|
|
|
|
+ a.stat_datetime,
|
|
|
|
+ b.project_id,
|
|
|
|
+ b.product_id,
|
|
|
|
+ b.advertiser_id,
|
|
|
|
+ b.company_id,
|
|
|
|
+ b.account_name,
|
|
|
|
+ b.project_name,
|
|
|
|
+ b.advertiser_name,
|
|
|
|
+ b.company_name,
|
|
|
|
+ b.sale_id,
|
|
|
|
+ b.user_id,
|
|
|
|
+ b.org_code,
|
|
|
|
+ sum(a.cost) as cost,
|
|
|
|
+ sum(a.show) as shows,
|
|
|
|
+ sum(a.avg_show_cost) as avg_show_cost,
|
|
|
|
+ sum(a.click) as click,
|
|
|
|
+ sum(a.avg_click_cost) as avg_click_cost,
|
|
|
|
+ sum(a.ctr) as ctr,
|
|
|
|
+ sum(a.convert) as converts,
|
|
|
|
+ sum(a.convert_cost) as convert_cost,
|
|
|
|
+ sum(a.convert_rate) as convert_rate,
|
|
|
|
+ sum(a.deep_convert) as deep_convert,
|
|
|
|
+ sum(a.deep_convert_cost) as deep_convert_cost,
|
|
|
|
+ sum(a.deep_convert_rate) as deep_convert_rate,
|
|
|
|
+ sum(a.attribution_convert)as attribution_convert,
|
|
|
|
+ sum(a.attribution_convert_cost) as attribution_convert_cost,
|
|
|
|
+ sum(a.attribution_deep_convert) as attribution_deep_convert_cost,
|
|
|
|
+ sum(a.attribution_deep_convert_cost) as attribution_deep_convert_cost,
|
|
|
|
+ sum(a.download_start) as download_start,
|
|
|
|
+ sum(a.download_start_cost) as download_start_cost,
|
|
|
|
+ sum(a.download_start_rate) as download_start_rate,
|
|
|
|
+ sum(a.download_finish) as download_finish,
|
|
|
|
+ sum(a.download_finish_cost) as download_finish_cost,
|
|
|
|
+ sum(a.download_finish_rate) as download_finish_rate,
|
|
|
|
+ sum(a.click_install) as click_install,
|
|
|
|
+ sum(a.install_finish) as install_finish,
|
|
|
|
+ sum(a.install_finish_cost) as install_finish_cost,
|
|
|
|
+ sum(a.install_finish_rate) as install_finish_rate,
|
|
|
|
+ sum(a.active) as active,
|
|
|
|
+ sum(a.active_cost) as active_cost,
|
|
|
|
+ sum(a.active_rate) as active_rate,
|
|
|
|
+ sum(a.register) as register,
|
|
|
|
+ sum(a.active_register_cost) as active_register_cost,
|
|
|
|
+ sum(a.active_register_rate)as active_register_rate,
|
|
|
|
+ sum(a.next_day_open) as next_day_open,
|
|
|
|
+ sum(a.next_day_open_cost)as next_day_open_cost,
|
|
|
|
+ sum(a.next_day_open_rate) as next_day_open_rate,
|
|
|
|
+ sum(a.attribution_next_day_open_cnt)as attribution_next_day_open_cost,
|
|
|
|
+ sum(a.attribution_next_day_open_cost)as attribution_next_day_open_cost ,
|
|
|
|
+ sum(a.attribution_next_day_open_rate)as attribution_next_day_open_cost ,
|
|
|
|
+ sum(a.game_addiction) as game_addiction,
|
|
|
|
+ sum(a.game_addiction_cost) as game_addiction_cost,
|
|
|
|
+ sum(a.game_addiction_rate) as game_addiction_rate,
|
|
|
|
+ sum(a.pay_count)as pay_count,
|
|
|
|
+ sum(a.active_pay_cost) as active_pay_cost,
|
|
|
|
+ sum(a.active_pay_rate) as active_pay_rate,
|
|
|
|
+ sum(a.loan_completion)as loan_completion,
|
|
|
|
+ sum(a.loan_completion_cost) as loan_completion_cost,
|
|
|
|
+ sum(a.loan_completion_rate) as loan_completion_rate,
|
|
|
|
+ sum(a.pre_loan_credit)as pre_loan_credit,
|
|
|
|
+ sum(a.pre_loan_credit_cost) as pre_loan_credit_cost,
|
|
|
|
+ sum(a.loan_credit)as loan_credit,
|
|
|
|
+ sum(a.loan_credit_cost)as loan_credit_cost,
|
|
|
|
+ sum(a.loan_credit_rate) as loan_credit_rate,
|
|
|
|
+ sum(a.in_app_uv)as in_app_uv,
|
|
|
|
+ sum(a.in_app_detail_uv)as in_app_detail_uv,
|
|
|
|
+ sum(a.in_app_cart)as in_app_cart,
|
|
|
|
+ sum(a.in_app_pay)as in_app_pay,
|
|
|
|
+ sum(a.in_app_order)as in_app_order,
|
|
|
|
+ sum(a.attribution_game_pay_7d_count)as attribution_game_pay_7d_count,
|
|
|
|
+ sum(a.attribution_game_pay_7d_cost)as attribution_game_pay_7d_cost,
|
|
|
|
+ sum(a.attribution_active_pay_7d_per_count)as attribution_active_pay_7d_count,
|
|
|
|
+ sum(a.game_pay_cost)as game_pay_cost,
|
|
|
|
+ sum(a.game_pay_count)as game_pay_count,
|
|
|
|
+ sum(a.phone)as phone,
|
|
|
|
+ sum(a.form)as form,
|
|
|
|
+ sum(a.map_search)as map_search,
|
|
|
|
+ sum(a.button)as button,
|
|
|
|
+ sum(a.view)as view,
|
|
|
|
+ sum(a.download)as download,
|
|
|
|
+ sum(a.qq)as qq,
|
|
|
|
+ sum(a.lottery)as lottery,
|
|
|
|
+ sum(a.vote)as vote,
|
|
|
|
+ sum(a.message)as message ,
|
|
|
|
+ sum(a.redirect)as redirect,
|
|
|
|
+ sum(a.shopping) as shopping,
|
|
|
|
+ sum(a.consult)as consult,
|
|
|
|
+ sum(a.wechat)as wechat,
|
|
|
|
+ sum(a.phone_confirm)as phone_confirm,
|
|
|
|
+ sum(a.phone_connect)as phone_connect,
|
|
|
|
+ sum(a.consult_effective)as consult_effective,
|
|
|
|
+ sum(a.coupon)as coupon,
|
|
|
|
+ sum(a.coupon_single_page)as coupon_single_page,
|
|
|
|
+ sum(a.redirect_to_shop)as redirect_to_shop,
|
|
|
|
+ sum(a.poi_collect)as poi_collect,
|
|
|
|
+ sum(a.poi_address_click)as poi_address_click,
|
|
|
|
+ sum(a.luban_order_cnt)as luban_order_cnt,
|
|
|
|
+ sum(a.luban_order_stat_amount)as luban_order_stat_amount,
|
|
|
|
+ sum(a.luban_order_roi)as luban_order_roi,
|
|
|
|
+ sum(a.luban_live_enter_cnt)as luban_live_enter_cnt,
|
|
|
|
+ sum(a.live_watch_one_minute_count)as live_watch_one_minute_count,
|
|
|
|
+ sum(a.luban_live_follow_cnt)as luban_live_follow_cnt,
|
|
|
|
+ sum(a.live_fans_club_join_cnt)as live_fans_club_join_cnt,
|
|
|
|
+ sum(a.luban_live_comment_cnt)as luban_live_comment_cnt,
|
|
|
|
+ sum(a.luban_live_share_cnt)as luban_live_share_cnt,
|
|
|
|
+ sum(a.luban_live_gift_cnt)as luban_live_gift_cnt,
|
|
|
|
+ sum(a.luban_live_gift_amount)as luban_live_gift_amount,
|
|
|
|
+ sum(a.luban_live_slidecart_click_cnt)as luban_live_slidecart_click_cnt,
|
|
|
|
+ sum(a.luban_live_click_product_cnt)as luban_live_click_product_cnt,
|
|
|
|
+ sum(a.luban_live_pay_order_count)as luban_live_pay_order_count,
|
|
|
|
+ sum(a.luban_live_pay_order_stat_cost)as luban_live_pay_order_stat_cost,
|
|
|
|
+ sum(a.live_component_click_count)as live_component_click_count,
|
|
|
|
+ sum(a.live_component_click_cost)as live_component_click_cost,
|
|
|
|
+ sum(a.live_component_click_rate)as live_component_click_rate,
|
|
|
|
+ sum(a.wechat_login_count)as wechat_login_count,
|
|
|
|
+ sum(a.attribution_wechat_login_30d_count)as attribution_wechat_login_30d_count,
|
|
|
|
+ sum(a.wechat_login_cost)as wechat_login_cost,
|
|
|
|
+ sum(a.attribution_wechat_login_30d_cost)as attribution_wechat_login_30d_cost,
|
|
|
|
+ sum(a.wechat_first_pay_count)as wechat_first_pay_count,
|
|
|
|
+ sum(a.attribution_wechat_first_pay_30d_count)as attribution_wechat_first_pay_30d_count,
|
|
|
|
+ sum(a.wechat_first_pay_cost)as wechat_first_pay_cost,
|
|
|
|
+ sum(a.attribution_wechat_first_pay_30d_cost)as attribution_wechat_first_pay_30d_cost,
|
|
|
|
+ sum(a.wechat_first_pay_rate)as wechat_first_pay_rate,
|
|
|
|
+ sum(a.attribution_wechat_first_pay_30d_rate)as attribution_wechat_first_pay_30d_rate,
|
|
|
|
+ sum(a.wechat_pay_amount)as wechat_pay_amount,
|
|
|
|
+ sum(a.attribution_wechat_pay_30d_amount)as attribution_wechat_pay_30d_amount,
|
|
|
|
+ sum(a.attribution_wechat_pay_30d_roi)as attribution_wechat_pay_30d_roi,
|
|
|
|
+ sum(a.phone_effective)as phone_effective,
|
|
|
|
+ sum(a.total_play)as total_play,
|
|
|
|
+ sum(a.valid_play)as valid_play,
|
|
|
|
+ sum(a.valid_play_cost)as valid_play_cost,
|
|
|
|
+ sum(a.valid_play_rate)as valid_play_rate,
|
|
|
|
+ sum(a.play_25_feed_break)as play_25_feed_break,
|
|
|
|
+ sum(a.play_50_feed_break)as play_50_feed_break,
|
|
|
|
+ sum(a.play_75_feed_break)as play_75_feed_break,
|
|
|
|
+ sum(a.play_100_feed_break)as play_100_feed_break,
|
|
|
|
+ sum(a.average_play_time_per_play)as average_play_time_per_play,
|
|
|
|
+ sum(a.play_over_rate)as play_over_rate,
|
|
|
|
+ sum(a.wifi_play_rate)as wifi_play_rate,
|
|
|
|
+ sum(a.wifi_play)as wifi_play,
|
|
|
|
+ sum(a.play_duration_sum)as play_duration_sum,
|
|
|
|
+ sum(a.advanced_creative_phone_click)as advanced_creative_phone_click,
|
|
|
|
+ sum(a.advanced_creative_counsel_click)as advanced_creative_counsel_click,
|
|
|
|
+ sum(a.advanced_creative_form_click)as advanced_creative_form_click,
|
|
|
|
+ sum(a.advanced_creative_coupon_addition)as advanced_creative_coupon_addition,
|
|
|
|
+ sum(a.advanced_creative_form_submit)as advanced_creative_form_submit,
|
|
|
|
+ sum(a.card_show)as card_show,
|
|
|
|
+ sum(a.share)as share,
|
|
|
|
+ sum(a.comment)as comment,
|
|
|
|
+ sum(a.like)as likes,
|
|
|
|
+ sum(a.follow)as follow,
|
|
|
|
+ sum(a.home_visited)as home_visited,
|
|
|
|
+ sum(a.ies_challenge_click)as ies_challenge_click,
|
|
|
|
+ sum(a.ies_music_click)as ies_music_click,
|
|
|
|
+ sum(a.location_click)as location_click,
|
|
|
|
+ sum(a.message_action)as message_action,
|
|
|
|
+ sum(a.click_landing_page)as click_landing_page,
|
|
|
|
+ sum(a.click_shopwindow)as click_shopwindow,
|
|
|
|
+ sum(a.click_website)as click_website,
|
|
|
|
+ sum(a.click_download)as click_download,
|
|
|
|
+ sum(a.click_call_dy)as click_call_dy,
|
|
|
|
+ sum(a.submit_certification_count)as submit_certification_count,
|
|
|
|
+ sum(a.approval_count)as approval_count,
|
|
|
|
+ sum(a.first_rental_order_count)as first_rental_order_count,
|
|
|
|
+ sum(a.first_order_count)as first_order_count,
|
|
|
|
+ sum(a.commute_first_pay_count)as commute_first_pay_count,
|
|
|
|
+ sum(a.attribution_active_pay_intra_one_day_roi)as attribution_active_pay_intra_one_day_roi,
|
|
|
|
+sum(a.attribution_active_pay_intra_one_day_amount)as attribution_active_pay_intra_one_day_amount,
|
|
|
|
+sum(a.attribution_active_pay_intra_one_day_rate)as attribution_active_pay_intra_one_day_rate,
|
|
|
|
+sum(a.attribution_active_pay_intra_one_day_cost)as attribution_active_pay_intra_one_day_cost,
|
|
|
|
+sum(attribution_active_pay_intra_one_day_count)as attribution_active_pay_intra_one_day_count,
|
|
|
|
+sum(a.stat_pay_amount)as stat_pay_amount
|
|
|
|
+from `media_api`.bytedance_advertiser_report_hourly a
|
|
|
|
+ left join
|
|
|
|
+ (select cua.account_id id,
|
|
|
|
+ cua.account_id account_id,
|
|
|
|
+ cp.id project_id,
|
|
|
|
+ product.id product_id,
|
|
|
|
+ ca.id advertiser_id,
|
|
|
|
+ uc.company_id company_id,
|
|
|
|
+ cua.auth_name account_name,
|
|
|
|
+ cp.project_name project_name,
|
|
|
|
+ ca.name advertiser_name,
|
|
|
|
+ uc.company_name company_name,
|
|
|
|
+ cp.sale_id sale_id,
|
|
|
|
+ su.id user_id,
|
|
|
|
+ su.org_code org_code
|
|
|
|
+ from `jeecg-boot`.ctop_user_allocation cua
|
|
|
|
+ left join `jeecg-boot`.ctop_project cp on cua.project_id = cp.id
|
|
|
|
+ left join `jeecg-boot`.ctop_advertiser ca on ca.id = cua.advertiser_id
|
|
|
|
+ left join `jeecg-boot`.sys_user su on su.id = cua.user_id
|
|
|
|
+ left join `jeecg-boot`.user_company uc on uc.user_id = cua.user_id
|
|
|
|
+ left join `jeecg-boot`.ctop_product product on product.id = cp.product_id
|
|
|
|
+ where cua.account_id is not null) b
|
|
|
|
+ on a.advertiser_id = b.account_id
|
|
|
|
+where a.stat_datetime = {start_time}
|
|
|
|
+group by a.advertiser_id
|
|
|
|
+order by account_id limit {num},20000;
|
|
|
|
+ """.format(start_time=self.start_time, num=i * 20000)
|
|
|
|
+ print(sql)
|
|
|
|
+ TidbConn.upsert(conn=self.conn, sql_buff=sql)
|
|
|
|
+ self.conn.commit()
|
|
|
|
+ TidbConn.conn_close(conn=self.conn)
|
|
|
|
+ return 0
|
|
|
|
+ except Exception as e:
|
|
|
|
+ logging.error(e)
|
|
|
|
+ return -1
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ status = AdvertiserSumDailyReport().daily_report()
|
|
|
|
+ if status == 0:
|
|
|
|
+ print("作业执行成功")
|
|
|
|
+ exit(0)
|
|
|
|
+ else:
|
|
|
|
+ print("作业执行失败")
|
|
|
|
+ exit(-1)
|