|
@@ -0,0 +1,681 @@
|
|
|
|
+# Author renyupeng
|
|
|
|
+# coding=utf-8
|
|
|
|
+# @Time : 2021/9/15 5:10 下午
|
|
|
|
+# @Site :
|
|
|
|
+# @File : AccountReport.py
|
|
|
|
+# @Software: PyCharm
|
|
|
|
+# @contact: renyupeng@c-top.com.cn
|
|
|
|
+
|
|
|
|
+import logging
|
|
|
|
+from Apietl.conn.TidbConn import TidbConn
|
|
|
|
+from Apietl.utlis.Utils import Utils
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class AccountReport:
|
|
|
|
+ def __init__(self):
|
|
|
|
+ self.conn = TidbConn.get_connection()
|
|
|
|
+
|
|
|
|
+ def daily_report(self, account_id, start_date, end_date):
|
|
|
|
+ try:
|
|
|
|
+ sql = """
|
|
|
|
+ set sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
|
|
|
|
+ insert into application.kuaishou_account_report_daily_dw
|
|
|
|
+(account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
|
|
|
|
+ company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
|
|
|
|
+ play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
|
|
|
|
+ cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
|
|
|
|
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
|
|
|
|
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
|
|
|
|
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
|
|
|
|
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
|
|
|
|
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
|
|
|
|
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
|
|
|
|
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
|
|
|
|
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
|
|
|
|
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
|
|
|
|
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
|
|
|
|
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
|
|
|
|
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
|
|
|
|
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
|
|
|
|
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
|
|
|
|
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
|
|
|
|
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
|
|
|
|
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
|
|
|
|
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
|
|
|
|
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
|
|
|
|
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
|
|
|
|
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
|
|
|
|
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
|
|
|
|
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
|
|
|
|
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
|
|
|
|
+ event_outbound_call_ratio, event_ad_watch_times)
|
|
|
|
+ (
|
|
|
|
+ select report.advertiser_id as account_id,
|
|
|
|
+ stat_date,
|
|
|
|
+ project_id,
|
|
|
|
+ product_id,
|
|
|
|
+ sys.advertiser_id,
|
|
|
|
+ company_id,
|
|
|
|
+ account_name,
|
|
|
|
+ project_name,
|
|
|
|
+ advertiser_name,
|
|
|
|
+ company_name,
|
|
|
|
+ sale_id,
|
|
|
|
+ user_id,
|
|
|
|
+ org_code,
|
|
|
|
+ charge,
|
|
|
|
+ `show`,
|
|
|
|
+ photo_click,
|
|
|
|
+ aclick,
|
|
|
|
+ bclick,
|
|
|
|
+ photo_click_ratio,
|
|
|
|
+ play_3s_ratio,
|
|
|
|
+ action_ratio,
|
|
|
|
+ impression_1k_cost,
|
|
|
|
+ photo_click_cost,
|
|
|
|
+ action_cost,
|
|
|
|
+ share,
|
|
|
|
+ comment,
|
|
|
|
+ `like`,
|
|
|
|
+ follow,
|
|
|
|
+ cancel_follow,
|
|
|
|
+ report,
|
|
|
|
+ block,
|
|
|
|
+ negative,
|
|
|
|
+ submit,
|
|
|
|
+ download_started,
|
|
|
|
+ download_completed,
|
|
|
|
+ activation,
|
|
|
|
+ event_pay_first_day,
|
|
|
|
+ event_pay_purchase_amount_first_day,
|
|
|
|
+ event_pay_first_day_roi,
|
|
|
|
+ event_pay,
|
|
|
|
+ event_pay_purchase_amount,
|
|
|
|
+ event_pay_roi,
|
|
|
|
+ event_register,
|
|
|
|
+ event_register_cost,
|
|
|
|
+ event_register_ratio,
|
|
|
|
+ event_jin_jian_app,
|
|
|
|
+ event_jin_jian_app_cost,
|
|
|
|
+ event_credit_grant_app,
|
|
|
|
+ event_credit_grant_app_cost,
|
|
|
|
+ event_credit_grant_app_ratio,
|
|
|
|
+ event_order_paid,
|
|
|
|
+ event_order_paid_purchase_amount,
|
|
|
|
+ event_order_paid_cost,
|
|
|
|
+ event_next_day_stay,
|
|
|
|
+ event_next_day_stay_cost,
|
|
|
|
+ event_next_day_stay_ratio,
|
|
|
|
+ form_count,
|
|
|
|
+ form_cost,
|
|
|
|
+ form_action_ratio,
|
|
|
|
+ event_jin_jian_landing_page,
|
|
|
|
+ event_jin_jian_landing_page_cost,
|
|
|
|
+ event_credit_grant_landing_page,
|
|
|
|
+ event_credit_grant_landing_page_cost,
|
|
|
|
+ event_credit_grant_landing_page_ratio,
|
|
|
|
+ event_valid_clues,
|
|
|
|
+ event_valid_clues_cost,
|
|
|
|
+ event_add_wechat,
|
|
|
|
+ event_add_wechat_cost,
|
|
|
|
+ event_add_wechat_ratio,
|
|
|
|
+ event_get_through,
|
|
|
|
+ event_get_through_cost,
|
|
|
|
+ event_get_through_ratio,
|
|
|
|
+ event_app_invoked,
|
|
|
|
+ event_app_invoked_cost,
|
|
|
|
+ event_app_invoked_ratio,
|
|
|
|
+ event_credit_grant_landing_ratio,
|
|
|
|
+ play_5s_ratio,
|
|
|
|
+ play_end_ratio,
|
|
|
|
+ event_new_user_pay,
|
|
|
|
+ event_new_user_pay_cost,
|
|
|
|
+ event_new_user_pay_ratio,
|
|
|
|
+ click_1k_cost,
|
|
|
|
+ ad_product_cnt,
|
|
|
|
+ event_goods_view,
|
|
|
|
+ merchant_reco_fans,
|
|
|
|
+ event_order_amount_roi,
|
|
|
|
+ event_goods_view_cost,
|
|
|
|
+ merchant_reco_fans_cost,
|
|
|
|
+ event_button_click,
|
|
|
|
+ event_button_click_cost,
|
|
|
|
+ event_button_click_ratio,
|
|
|
|
+ event_order_paid_roi,
|
|
|
|
+ event_new_user_jinjian_app,
|
|
|
|
+ event_new_user_jinjian_app_cost,
|
|
|
|
+ event_new_user_jinjian_app_roi,
|
|
|
|
+ event_new_user_credit_grant_app,
|
|
|
|
+ event_new_user_credit_grant_app_cost,
|
|
|
|
+ event_new_user_credit_grant_app_roi,
|
|
|
|
+ event_new_user_jinjian_page,
|
|
|
|
+ event_new_user_jinjian_page_cost,
|
|
|
|
+ event_new_user_jinjian_page_roi,
|
|
|
|
+ event_new_user_credit_grant_page,
|
|
|
|
+ event_new_user_credit_grant_page_cost,
|
|
|
|
+ event_new_user_credit_grant_page_roi,
|
|
|
|
+ event_appoint_form,
|
|
|
|
+ event_appoint_form_cost,
|
|
|
|
+ event_appoint_form_ratio,
|
|
|
|
+ event_appoint_jump_click,
|
|
|
|
+ event_appoint_jump_click_cost,
|
|
|
|
+ event_appoint_jump_click_ratio,
|
|
|
|
+ union_event_pay_purchase_amount_7d,
|
|
|
|
+ union_event_pay_purchase_amount_7d_roi,
|
|
|
|
+ placement_type,
|
|
|
|
+ ad_scene,
|
|
|
|
+ event_order_successed,
|
|
|
|
+ ad_photo_played_10s_ratio,
|
|
|
|
+ key_action_cost,
|
|
|
|
+ event_add_shopping_cart_cost,
|
|
|
|
+ event_ad_watch_times_ratio,
|
|
|
|
+ event_outbound_call_cost,
|
|
|
|
+ event_outbound_call,
|
|
|
|
+ action_new_ratio,
|
|
|
|
+ event_watch_app_ad,
|
|
|
|
+ event_multi_conversion_cost,
|
|
|
|
+ event_phone_card_activate,
|
|
|
|
+ ad_photo_played_75percent_ratio,
|
|
|
|
+ key_action_ratio,
|
|
|
|
+ event_ad_watch_times_cost,
|
|
|
|
+ event_add_shopping_cart,
|
|
|
|
+ key_action,
|
|
|
|
+ event_multi_conversion,
|
|
|
|
+ event_wechat_connected,
|
|
|
|
+ event_dsp_gift_form,
|
|
|
|
+ event_intention_confirmed,
|
|
|
|
+ event_phone_get_through,
|
|
|
|
+ event_multi_conversion_ratio,
|
|
|
|
+ event_measurement_house,
|
|
|
|
+ ad_photo_played_2s_ratio,
|
|
|
|
+ event_outbound_call_ratio,
|
|
|
|
+ event_ad_watch_times
|
|
|
|
+ from media_api.kuaishou_account_report_daily report
|
|
|
|
+ left join
|
|
|
|
+ hcst_system.ctop_account_attribution_info sys
|
|
|
|
+ on report.advertiser_id = sys.account_id
|
|
|
|
+ where report.stat_date between {start_date} and {end_date}
|
|
|
|
+ and report.advertiser_id={account_id}
|
|
|
|
+ )
|
|
|
|
+on DUPLICATE KEY UPDATE account_id =values(account_id),
|
|
|
|
+ stat_date =values(stat_date),
|
|
|
|
+ project_id =values(project_id),
|
|
|
|
+ product_id =values(product_id),
|
|
|
|
+ advertiser_id =values(advertiser_id),
|
|
|
|
+ company_id =values(company_id),
|
|
|
|
+ account_name =values(account_name),
|
|
|
|
+ project_name =values(project_name),
|
|
|
|
+ advertiser_name =values(advertiser_name),
|
|
|
|
+ company_name =values(company_name),
|
|
|
|
+ sale_id =values(sale_id),
|
|
|
|
+ user_id =values(user_id),
|
|
|
|
+ org_code =values(org_code),
|
|
|
|
+ charge =values(charge),
|
|
|
|
+ `show` =values(`show`),
|
|
|
|
+ photo_click =values(photo_click),
|
|
|
|
+ aclick =values(aclick),
|
|
|
|
+ bclick =values(bclick),
|
|
|
|
+ photo_click_ratio =values(photo_click_ratio),
|
|
|
|
+ play_3s_ratio =values(play_3s_ratio),
|
|
|
|
+ action_ratio =values(action_ratio),
|
|
|
|
+ impression_1k_cost =values(impression_1k_cost),
|
|
|
|
+ photo_click_cost =values(photo_click_cost),
|
|
|
|
+ action_cost =values(action_cost),
|
|
|
|
+ share =values(share),
|
|
|
|
+ comment =values(comment),
|
|
|
|
+ `like` =values(`like`),
|
|
|
|
+ follow =values(follow),
|
|
|
|
+ cancel_follow =values(cancel_follow),
|
|
|
|
+ report =values(report),
|
|
|
|
+ block =values(block),
|
|
|
|
+ negative =values(negative),
|
|
|
|
+ submit =values(submit),
|
|
|
|
+ download_started =values(download_started),
|
|
|
|
+ download_completed =values(download_completed),
|
|
|
|
+ activation =values(activation),
|
|
|
|
+ event_pay_first_day =values(event_pay_first_day),
|
|
|
|
+ event_pay_purchase_amount_first_day =values(event_pay_purchase_amount_first_day),
|
|
|
|
+ event_pay_first_day_roi =values(event_pay_first_day_roi),
|
|
|
|
+ event_pay =values(event_pay),
|
|
|
|
+ event_pay_purchase_amount =values(event_pay_purchase_amount),
|
|
|
|
+ event_pay_roi =values(event_pay_roi),
|
|
|
|
+ event_register =values(event_register),
|
|
|
|
+ event_register_cost =values(event_register_cost),
|
|
|
|
+ event_register_ratio =values(event_register_ratio),
|
|
|
|
+ event_jin_jian_app =values(event_jin_jian_app),
|
|
|
|
+ event_jin_jian_app_cost =values(event_jin_jian_app_cost),
|
|
|
|
+ event_credit_grant_app =values(event_credit_grant_app),
|
|
|
|
+ event_credit_grant_app_cost =values(event_credit_grant_app_cost),
|
|
|
|
+ event_credit_grant_app_ratio =values(event_credit_grant_app_ratio),
|
|
|
|
+ event_order_paid =values(event_order_paid),
|
|
|
|
+ event_order_paid_purchase_amount =values(event_order_paid_purchase_amount),
|
|
|
|
+ event_order_paid_cost =values(event_order_paid_cost),
|
|
|
|
+ event_next_day_stay =values(event_next_day_stay),
|
|
|
|
+ event_next_day_stay_cost =values(event_next_day_stay_cost),
|
|
|
|
+ event_next_day_stay_ratio =values(event_next_day_stay_ratio),
|
|
|
|
+ form_count =values(form_count),
|
|
|
|
+ form_cost =values(form_cost),
|
|
|
|
+ form_action_ratio =values(form_action_ratio),
|
|
|
|
+ event_jin_jian_landing_page =values(event_jin_jian_landing_page),
|
|
|
|
+ event_jin_jian_landing_page_cost =values(event_jin_jian_landing_page_cost),
|
|
|
|
+ event_credit_grant_landing_page =values(event_credit_grant_landing_page),
|
|
|
|
+ event_credit_grant_landing_page_cost =values(event_credit_grant_landing_page_cost),
|
|
|
|
+ event_credit_grant_landing_page_ratio =values(event_credit_grant_landing_page_ratio),
|
|
|
|
+ event_valid_clues =values(event_valid_clues),
|
|
|
|
+ event_valid_clues_cost =values(event_valid_clues_cost),
|
|
|
|
+ event_add_wechat =values(event_add_wechat),
|
|
|
|
+ event_add_wechat_cost =values(event_add_wechat_cost),
|
|
|
|
+ event_add_wechat_ratio =values(event_add_wechat_ratio),
|
|
|
|
+ event_get_through =values(event_get_through),
|
|
|
|
+ event_get_through_cost =values(event_get_through_cost),
|
|
|
|
+ event_get_through_ratio =values(event_get_through_ratio),
|
|
|
|
+ event_app_invoked =values(event_app_invoked),
|
|
|
|
+ event_app_invoked_cost =values(event_app_invoked_cost),
|
|
|
|
+ event_app_invoked_ratio =values(event_app_invoked_ratio),
|
|
|
|
+ event_credit_grant_landing_ratio =values(event_credit_grant_landing_ratio),
|
|
|
|
+ play_5s_ratio =values(play_5s_ratio),
|
|
|
|
+ play_end_ratio =values(play_end_ratio),
|
|
|
|
+ event_new_user_pay =values(event_new_user_pay),
|
|
|
|
+ event_new_user_pay_cost =values(event_new_user_pay_cost),
|
|
|
|
+ event_new_user_pay_ratio =values(event_new_user_pay_ratio),
|
|
|
|
+ click_1k_cost =values(click_1k_cost),
|
|
|
|
+ ad_product_cnt =values(ad_product_cnt),
|
|
|
|
+ event_goods_view =values(event_goods_view),
|
|
|
|
+ merchant_reco_fans =values(merchant_reco_fans),
|
|
|
|
+ event_order_amount_roi =values(event_order_amount_roi),
|
|
|
|
+ event_goods_view_cost =values(event_goods_view_cost),
|
|
|
|
+ merchant_reco_fans_cost =values(merchant_reco_fans_cost),
|
|
|
|
+ event_button_click =values(event_button_click),
|
|
|
|
+ event_button_click_cost =values(event_button_click_cost),
|
|
|
|
+ event_button_click_ratio =values(event_button_click_ratio),
|
|
|
|
+ event_order_paid_roi =values(event_order_paid_roi),
|
|
|
|
+ event_new_user_jinjian_app =values(event_new_user_jinjian_app),
|
|
|
|
+ event_new_user_jinjian_app_cost =values(event_new_user_jinjian_app_cost),
|
|
|
|
+ event_new_user_jinjian_app_roi =values(event_new_user_jinjian_app_roi),
|
|
|
|
+ event_new_user_credit_grant_app =values(event_new_user_credit_grant_app),
|
|
|
|
+ event_new_user_credit_grant_app_cost =values(event_new_user_credit_grant_app_cost),
|
|
|
|
+ event_new_user_credit_grant_app_roi =values(event_new_user_credit_grant_app_roi),
|
|
|
|
+ event_new_user_jinjian_page =values(event_new_user_jinjian_page),
|
|
|
|
+ event_new_user_jinjian_page_cost =values(event_new_user_jinjian_page_cost),
|
|
|
|
+ event_new_user_jinjian_page_roi =values(event_new_user_jinjian_page_roi),
|
|
|
|
+ event_new_user_credit_grant_page =values(event_new_user_credit_grant_page),
|
|
|
|
+ event_new_user_credit_grant_page_cost =values(event_new_user_credit_grant_page_cost),
|
|
|
|
+ event_new_user_credit_grant_page_roi =values(event_new_user_credit_grant_page_roi),
|
|
|
|
+ event_appoint_form =values(event_appoint_form),
|
|
|
|
+ event_appoint_form_cost =values(event_appoint_form_cost),
|
|
|
|
+ event_appoint_form_ratio =values(event_appoint_form_ratio),
|
|
|
|
+ event_appoint_jump_click =values(event_appoint_jump_click),
|
|
|
|
+ event_appoint_jump_click_cost =values(event_appoint_jump_click_cost),
|
|
|
|
+ event_appoint_jump_click_ratio =values(event_appoint_jump_click_ratio),
|
|
|
|
+ union_event_pay_purchase_amount_7d =values(union_event_pay_purchase_amount_7d),
|
|
|
|
+ union_event_pay_purchase_amount_7d_roi =values(union_event_pay_purchase_amount_7d_roi),
|
|
|
|
+ placement_type =values(placement_type),
|
|
|
|
+ ad_scene =values(ad_scene),
|
|
|
|
+ event_order_successed =values(event_order_successed),
|
|
|
|
+ ad_photo_played_10s_ratio =values(ad_photo_played_10s_ratio),
|
|
|
|
+ key_action_cost =values(key_action_cost),
|
|
|
|
+ event_add_shopping_cart_cost =values(event_add_shopping_cart_cost),
|
|
|
|
+ event_ad_watch_times_ratio =values(event_ad_watch_times_ratio),
|
|
|
|
+ event_outbound_call_cost =values(event_outbound_call_cost),
|
|
|
|
+ event_outbound_call =values(event_outbound_call),
|
|
|
|
+ action_new_ratio =values(action_new_ratio),
|
|
|
|
+ event_watch_app_ad =values(event_watch_app_ad),
|
|
|
|
+ event_multi_conversion_cost =values(event_multi_conversion_cost),
|
|
|
|
+ event_phone_card_activate =values(event_phone_card_activate),
|
|
|
|
+ ad_photo_played_75percent_ratio =values(ad_photo_played_75percent_ratio),
|
|
|
|
+ key_action_ratio =values(key_action_ratio),
|
|
|
|
+ event_ad_watch_times_cost =values(event_ad_watch_times_cost),
|
|
|
|
+ event_add_shopping_cart =values(event_add_shopping_cart),
|
|
|
|
+ key_action =values(key_action),
|
|
|
|
+ event_multi_conversion =values(event_multi_conversion),
|
|
|
|
+ event_wechat_connected =values(event_wechat_connected),
|
|
|
|
+ event_dsp_gift_form =values(event_dsp_gift_form),
|
|
|
|
+ event_intention_confirmed =values(event_intention_confirmed),
|
|
|
|
+ event_phone_get_through =values(event_phone_get_through),
|
|
|
|
+ event_multi_conversion_ratio =values(event_multi_conversion_ratio),
|
|
|
|
+ event_measurement_house =values(event_measurement_house),
|
|
|
|
+ ad_photo_played_2s_ratio =values(ad_photo_played_2s_ratio),
|
|
|
|
+ event_outbound_call_ratio =values(event_outbound_call_ratio),
|
|
|
|
+ event_ad_watch_times =values(event_ad_watch_times);
|
|
|
|
+ """.format(start_date=start_date, end_date=end_date, account_id=account_id)
|
|
|
|
+ print(sql)
|
|
|
|
+ TidbConn.exec_sql(self.conn, sql)
|
|
|
|
+ self.conn.commit()
|
|
|
|
+ except Exception as e:
|
|
|
|
+ logging.error('失败详细信息:', repr(e))
|
|
|
|
+
|
|
|
|
+ def hourly_report(self, account_id, start_date, end_date):
|
|
|
|
+ try:
|
|
|
|
+ sql = """
|
|
|
|
+ insert into application.kuaishou_account_report_hourly_dw
|
|
|
|
+(account_id, stat_date,`hour`, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
|
|
|
|
+ company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
|
|
|
|
+ play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
|
|
|
|
+ cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
|
|
|
|
+ event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
|
|
|
|
+ event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
|
|
|
|
+ event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
|
|
|
|
+ event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
|
|
|
|
+ event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
|
|
|
|
+ event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
|
|
|
|
+ event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
|
|
|
|
+ event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
|
|
|
|
+ event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
|
|
|
|
+ play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
|
|
|
|
+ event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
|
|
|
|
+ event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
|
|
|
|
+ event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
|
|
|
|
+ event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
|
|
|
|
+ event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
|
|
|
|
+ event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
|
|
|
|
+ event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
|
|
|
|
+ event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
|
|
|
|
+ union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
|
|
|
|
+ key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
|
|
|
|
+ event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
|
|
|
|
+ ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
|
|
|
|
+ event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
|
|
|
|
+ event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
|
|
|
|
+ event_outbound_call_ratio, event_ad_watch_times)
|
|
|
|
+ (
|
|
|
|
+ select report.advertiser_id as account_id,
|
|
|
|
+ stat_date,
|
|
|
|
+ `hour`,
|
|
|
|
+ project_id,
|
|
|
|
+ product_id,
|
|
|
|
+ sys.advertiser_id,
|
|
|
|
+ company_id,
|
|
|
|
+ account_name,
|
|
|
|
+ project_name,
|
|
|
|
+ advertiser_name,
|
|
|
|
+ company_name,
|
|
|
|
+ sale_id,
|
|
|
|
+ user_id,
|
|
|
|
+ org_code,
|
|
|
|
+ charge,
|
|
|
|
+ `show`,
|
|
|
|
+ photo_click,
|
|
|
|
+ aclick,
|
|
|
|
+ bclick,
|
|
|
|
+ photo_click_ratio,
|
|
|
|
+ play_3s_ratio,
|
|
|
|
+ action_ratio,
|
|
|
|
+ impression_1k_cost,
|
|
|
|
+ photo_click_cost,
|
|
|
|
+ action_cost,
|
|
|
|
+ share,
|
|
|
|
+ comment,
|
|
|
|
+ `like`,
|
|
|
|
+ follow,
|
|
|
|
+ cancel_follow,
|
|
|
|
+ report,
|
|
|
|
+ block,
|
|
|
|
+ negative,
|
|
|
|
+ submit,
|
|
|
|
+ download_started,
|
|
|
|
+ download_completed,
|
|
|
|
+ activation,
|
|
|
|
+ event_pay_first_day,
|
|
|
|
+ event_pay_purchase_amount_first_day,
|
|
|
|
+ event_pay_first_day_roi,
|
|
|
|
+ event_pay,
|
|
|
|
+ event_pay_purchase_amount,
|
|
|
|
+ event_pay_roi,
|
|
|
|
+ event_register,
|
|
|
|
+ event_register_cost,
|
|
|
|
+ event_register_ratio,
|
|
|
|
+ event_jin_jian_app,
|
|
|
|
+ event_jin_jian_app_cost,
|
|
|
|
+ event_credit_grant_app,
|
|
|
|
+ event_credit_grant_app_cost,
|
|
|
|
+ event_credit_grant_app_ratio,
|
|
|
|
+ event_order_paid,
|
|
|
|
+ event_order_paid_purchase_amount,
|
|
|
|
+ event_order_paid_cost,
|
|
|
|
+ event_next_day_stay,
|
|
|
|
+ event_next_day_stay_cost,
|
|
|
|
+ event_next_day_stay_ratio,
|
|
|
|
+ form_count,
|
|
|
|
+ form_cost,
|
|
|
|
+ form_action_ratio,
|
|
|
|
+ event_jin_jian_landing_page,
|
|
|
|
+ event_jin_jian_landing_page_cost,
|
|
|
|
+ event_credit_grant_landing_page,
|
|
|
|
+ event_credit_grant_landing_page_cost,
|
|
|
|
+ event_credit_grant_landing_page_ratio,
|
|
|
|
+ event_valid_clues,
|
|
|
|
+ event_valid_clues_cost,
|
|
|
|
+ event_add_wechat,
|
|
|
|
+ event_add_wechat_cost,
|
|
|
|
+ event_add_wechat_ratio,
|
|
|
|
+ event_get_through,
|
|
|
|
+ event_get_through_cost,
|
|
|
|
+ event_get_through_ratio,
|
|
|
|
+ event_app_invoked,
|
|
|
|
+ event_app_invoked_cost,
|
|
|
|
+ event_app_invoked_ratio,
|
|
|
|
+ event_credit_grant_landing_ratio,
|
|
|
|
+ play_5s_ratio,
|
|
|
|
+ play_end_ratio,
|
|
|
|
+ event_new_user_pay,
|
|
|
|
+ event_new_user_pay_cost,
|
|
|
|
+ event_new_user_pay_ratio,
|
|
|
|
+ click_1k_cost,
|
|
|
|
+ ad_product_cnt,
|
|
|
|
+ event_goods_view,
|
|
|
|
+ merchant_reco_fans,
|
|
|
|
+ event_order_amount_roi,
|
|
|
|
+ event_goods_view_cost,
|
|
|
|
+ merchant_reco_fans_cost,
|
|
|
|
+ event_button_click,
|
|
|
|
+ event_button_click_cost,
|
|
|
|
+ event_button_click_ratio,
|
|
|
|
+ event_order_paid_roi,
|
|
|
|
+ event_new_user_jinjian_app,
|
|
|
|
+ event_new_user_jinjian_app_cost,
|
|
|
|
+ event_new_user_jinjian_app_roi,
|
|
|
|
+ event_new_user_credit_grant_app,
|
|
|
|
+ event_new_user_credit_grant_app_cost,
|
|
|
|
+ event_new_user_credit_grant_app_roi,
|
|
|
|
+ event_new_user_jinjian_page,
|
|
|
|
+ event_new_user_jinjian_page_cost,
|
|
|
|
+ event_new_user_jinjian_page_roi,
|
|
|
|
+ event_new_user_credit_grant_page,
|
|
|
|
+ event_new_user_credit_grant_page_cost,
|
|
|
|
+ event_new_user_credit_grant_page_roi,
|
|
|
|
+ event_appoint_form,
|
|
|
|
+ event_appoint_form_cost,
|
|
|
|
+ event_appoint_form_ratio,
|
|
|
|
+ event_appoint_jump_click,
|
|
|
|
+ event_appoint_jump_click_cost,
|
|
|
|
+ event_appoint_jump_click_ratio,
|
|
|
|
+ union_event_pay_purchase_amount_7d,
|
|
|
|
+ union_event_pay_purchase_amount_7d_roi,
|
|
|
|
+ placement_type,
|
|
|
|
+ ad_scene,
|
|
|
|
+ event_order_successed,
|
|
|
|
+ ad_photo_played_10s_ratio,
|
|
|
|
+ key_action_cost,
|
|
|
|
+ event_add_shopping_cart_cost,
|
|
|
|
+ event_ad_watch_times_ratio,
|
|
|
|
+ event_outbound_call_cost,
|
|
|
|
+ event_outbound_call,
|
|
|
|
+ action_new_ratio,
|
|
|
|
+ event_watch_app_ad,
|
|
|
|
+ event_multi_conversion_cost,
|
|
|
|
+ event_phone_card_activate,
|
|
|
|
+ ad_photo_played_75percent_ratio,
|
|
|
|
+ key_action_ratio,
|
|
|
|
+ event_ad_watch_times_cost,
|
|
|
|
+ event_add_shopping_cart,
|
|
|
|
+ key_action,
|
|
|
|
+ event_multi_conversion,
|
|
|
|
+ event_wechat_connected,
|
|
|
|
+ event_dsp_gift_form,
|
|
|
|
+ event_intention_confirmed,
|
|
|
|
+ event_phone_get_through,
|
|
|
|
+ event_multi_conversion_ratio,
|
|
|
|
+ event_measurement_house,
|
|
|
|
+ ad_photo_played_2s_ratio,
|
|
|
|
+ event_outbound_call_ratio,
|
|
|
|
+ event_ad_watch_times
|
|
|
|
+ from media_api.kuaishou_account_report_hourly report
|
|
|
|
+ left join
|
|
|
|
+ hcst_system.ctop_account_attribution_info sys
|
|
|
|
+ on report.advertiser_id = sys.account_id
|
|
|
|
+ where report.stat_date between {start_date} and {end_date}
|
|
|
|
+ and report.advertiser_id={account_id}
|
|
|
|
+ )
|
|
|
|
+on DUPLICATE KEY UPDATE account_id =values(account_id),
|
|
|
|
+ stat_date =values(stat_date),
|
|
|
|
+ `hour` =values (`hour`),
|
|
|
|
+ project_id =values(project_id),
|
|
|
|
+ product_id =values(product_id),
|
|
|
|
+ advertiser_id =values(advertiser_id),
|
|
|
|
+ company_id =values(company_id),
|
|
|
|
+ account_name =values(account_name),
|
|
|
|
+ project_name =values(project_name),
|
|
|
|
+ advertiser_name =values(advertiser_name),
|
|
|
|
+ company_name =values(company_name),
|
|
|
|
+ sale_id =values(sale_id),
|
|
|
|
+ user_id =values(user_id),
|
|
|
|
+ org_code =values(org_code),
|
|
|
|
+ charge =values(charge),
|
|
|
|
+ `show` =values(`show`),
|
|
|
|
+ photo_click =values(photo_click),
|
|
|
|
+ aclick =values(aclick),
|
|
|
|
+ bclick =values(bclick),
|
|
|
|
+ photo_click_ratio =values(photo_click_ratio),
|
|
|
|
+ play_3s_ratio =values(play_3s_ratio),
|
|
|
|
+ action_ratio =values(action_ratio),
|
|
|
|
+ impression_1k_cost =values(impression_1k_cost),
|
|
|
|
+ photo_click_cost =values(photo_click_cost),
|
|
|
|
+ action_cost =values(action_cost),
|
|
|
|
+ share =values(share),
|
|
|
|
+ comment =values(comment),
|
|
|
|
+ `like` =values(`like`),
|
|
|
|
+ follow =values(follow),
|
|
|
|
+ cancel_follow =values(cancel_follow),
|
|
|
|
+ report =values(report),
|
|
|
|
+ block =values(block),
|
|
|
|
+ negative =values(negative),
|
|
|
|
+ submit =values(submit),
|
|
|
|
+ download_started =values(download_started),
|
|
|
|
+ download_completed =values(download_completed),
|
|
|
|
+ activation =values(activation),
|
|
|
|
+ event_pay_first_day =values(event_pay_first_day),
|
|
|
|
+ event_pay_purchase_amount_first_day =values(event_pay_purchase_amount_first_day),
|
|
|
|
+ event_pay_first_day_roi =values(event_pay_first_day_roi),
|
|
|
|
+ event_pay =values(event_pay),
|
|
|
|
+ event_pay_purchase_amount =values(event_pay_purchase_amount),
|
|
|
|
+ event_pay_roi =values(event_pay_roi),
|
|
|
|
+ event_register =values(event_register),
|
|
|
|
+ event_register_cost =values(event_register_cost),
|
|
|
|
+ event_register_ratio =values(event_register_ratio),
|
|
|
|
+ event_jin_jian_app =values(event_jin_jian_app),
|
|
|
|
+ event_jin_jian_app_cost =values(event_jin_jian_app_cost),
|
|
|
|
+ event_credit_grant_app =values(event_credit_grant_app),
|
|
|
|
+ event_credit_grant_app_cost =values(event_credit_grant_app_cost),
|
|
|
|
+ event_credit_grant_app_ratio =values(event_credit_grant_app_ratio),
|
|
|
|
+ event_order_paid =values(event_order_paid),
|
|
|
|
+ event_order_paid_purchase_amount =values(event_order_paid_purchase_amount),
|
|
|
|
+ event_order_paid_cost =values(event_order_paid_cost),
|
|
|
|
+ event_next_day_stay =values(event_next_day_stay),
|
|
|
|
+ event_next_day_stay_cost =values(event_next_day_stay_cost),
|
|
|
|
+ event_next_day_stay_ratio =values(event_next_day_stay_ratio),
|
|
|
|
+ form_count =values(form_count),
|
|
|
|
+ form_cost =values(form_cost),
|
|
|
|
+ form_action_ratio =values(form_action_ratio),
|
|
|
|
+ event_jin_jian_landing_page =values(event_jin_jian_landing_page),
|
|
|
|
+ event_jin_jian_landing_page_cost =values(event_jin_jian_landing_page_cost),
|
|
|
|
+ event_credit_grant_landing_page =values(event_credit_grant_landing_page),
|
|
|
|
+ event_credit_grant_landing_page_cost =values(event_credit_grant_landing_page_cost),
|
|
|
|
+ event_credit_grant_landing_page_ratio =values(event_credit_grant_landing_page_ratio),
|
|
|
|
+ event_valid_clues =values(event_valid_clues),
|
|
|
|
+ event_valid_clues_cost =values(event_valid_clues_cost),
|
|
|
|
+ event_add_wechat =values(event_add_wechat),
|
|
|
|
+ event_add_wechat_cost =values(event_add_wechat_cost),
|
|
|
|
+ event_add_wechat_ratio =values(event_add_wechat_ratio),
|
|
|
|
+ event_get_through =values(event_get_through),
|
|
|
|
+ event_get_through_cost =values(event_get_through_cost),
|
|
|
|
+ event_get_through_ratio =values(event_get_through_ratio),
|
|
|
|
+ event_app_invoked =values(event_app_invoked),
|
|
|
|
+ event_app_invoked_cost =values(event_app_invoked_cost),
|
|
|
|
+ event_app_invoked_ratio =values(event_app_invoked_ratio),
|
|
|
|
+ event_credit_grant_landing_ratio =values(event_credit_grant_landing_ratio),
|
|
|
|
+ play_5s_ratio =values(play_5s_ratio),
|
|
|
|
+ play_end_ratio =values(play_end_ratio),
|
|
|
|
+ event_new_user_pay =values(event_new_user_pay),
|
|
|
|
+ event_new_user_pay_cost =values(event_new_user_pay_cost),
|
|
|
|
+ event_new_user_pay_ratio =values(event_new_user_pay_ratio),
|
|
|
|
+ click_1k_cost =values(click_1k_cost),
|
|
|
|
+ ad_product_cnt =values(ad_product_cnt),
|
|
|
|
+ event_goods_view =values(event_goods_view),
|
|
|
|
+ merchant_reco_fans =values(merchant_reco_fans),
|
|
|
|
+ event_order_amount_roi =values(event_order_amount_roi),
|
|
|
|
+ event_goods_view_cost =values(event_goods_view_cost),
|
|
|
|
+ merchant_reco_fans_cost =values(merchant_reco_fans_cost),
|
|
|
|
+ event_button_click =values(event_button_click),
|
|
|
|
+ event_button_click_cost =values(event_button_click_cost),
|
|
|
|
+ event_button_click_ratio =values(event_button_click_ratio),
|
|
|
|
+ event_order_paid_roi =values(event_order_paid_roi),
|
|
|
|
+ event_new_user_jinjian_app =values(event_new_user_jinjian_app),
|
|
|
|
+ event_new_user_jinjian_app_cost =values(event_new_user_jinjian_app_cost),
|
|
|
|
+ event_new_user_jinjian_app_roi =values(event_new_user_jinjian_app_roi),
|
|
|
|
+ event_new_user_credit_grant_app =values(event_new_user_credit_grant_app),
|
|
|
|
+ event_new_user_credit_grant_app_cost =values(event_new_user_credit_grant_app_cost),
|
|
|
|
+ event_new_user_credit_grant_app_roi =values(event_new_user_credit_grant_app_roi),
|
|
|
|
+ event_new_user_jinjian_page =values(event_new_user_jinjian_page),
|
|
|
|
+ event_new_user_jinjian_page_cost =values(event_new_user_jinjian_page_cost),
|
|
|
|
+ event_new_user_jinjian_page_roi =values(event_new_user_jinjian_page_roi),
|
|
|
|
+ event_new_user_credit_grant_page =values(event_new_user_credit_grant_page),
|
|
|
|
+ event_new_user_credit_grant_page_cost =values(event_new_user_credit_grant_page_cost),
|
|
|
|
+ event_new_user_credit_grant_page_roi =values(event_new_user_credit_grant_page_roi),
|
|
|
|
+ event_appoint_form =values(event_appoint_form),
|
|
|
|
+ event_appoint_form_cost =values(event_appoint_form_cost),
|
|
|
|
+ event_appoint_form_ratio =values(event_appoint_form_ratio),
|
|
|
|
+ event_appoint_jump_click =values(event_appoint_jump_click),
|
|
|
|
+ event_appoint_jump_click_cost =values(event_appoint_jump_click_cost),
|
|
|
|
+ event_appoint_jump_click_ratio =values(event_appoint_jump_click_ratio),
|
|
|
|
+ union_event_pay_purchase_amount_7d =values(union_event_pay_purchase_amount_7d),
|
|
|
|
+ union_event_pay_purchase_amount_7d_roi =values(union_event_pay_purchase_amount_7d_roi),
|
|
|
|
+ placement_type =values(placement_type),
|
|
|
|
+ ad_scene =values(ad_scene),
|
|
|
|
+ event_order_successed =values(event_order_successed),
|
|
|
|
+ ad_photo_played_10s_ratio =values(ad_photo_played_10s_ratio),
|
|
|
|
+ key_action_cost =values(key_action_cost),
|
|
|
|
+ event_add_shopping_cart_cost =values(event_add_shopping_cart_cost),
|
|
|
|
+ event_ad_watch_times_ratio =values(event_ad_watch_times_ratio),
|
|
|
|
+ event_outbound_call_cost =values(event_outbound_call_cost),
|
|
|
|
+ event_outbound_call =values(event_outbound_call),
|
|
|
|
+ action_new_ratio =values(action_new_ratio),
|
|
|
|
+ event_watch_app_ad =values(event_watch_app_ad),
|
|
|
|
+ event_multi_conversion_cost =values(event_multi_conversion_cost),
|
|
|
|
+ event_phone_card_activate =values(event_phone_card_activate),
|
|
|
|
+ ad_photo_played_75percent_ratio =values(ad_photo_played_75percent_ratio),
|
|
|
|
+ key_action_ratio =values(key_action_ratio),
|
|
|
|
+ event_ad_watch_times_cost =values(event_ad_watch_times_cost),
|
|
|
|
+ event_add_shopping_cart =values(event_add_shopping_cart),
|
|
|
|
+ key_action =values(key_action),
|
|
|
|
+ event_multi_conversion =values(event_multi_conversion),
|
|
|
|
+ event_wechat_connected =values(event_wechat_connected),
|
|
|
|
+ event_dsp_gift_form =values(event_dsp_gift_form),
|
|
|
|
+ event_intention_confirmed =values(event_intention_confirmed),
|
|
|
|
+ event_phone_get_through =values(event_phone_get_through),
|
|
|
|
+ event_multi_conversion_ratio =values(event_multi_conversion_ratio),
|
|
|
|
+ event_measurement_house =values(event_measurement_house),
|
|
|
|
+ ad_photo_played_2s_ratio =values(ad_photo_played_2s_ratio),
|
|
|
|
+ event_outbound_call_ratio =values(event_outbound_call_ratio),
|
|
|
|
+ event_ad_watch_times =values(event_ad_watch_times);
|
|
|
|
+ """.format(start_date=start_date, end_date=end_date, account_id=account_id)
|
|
|
|
+ print(sql)
|
|
|
|
+ TidbConn.exec_sql(self.conn, sql)
|
|
|
|
+ self.conn.commit()
|
|
|
|
+ except Exception as e:
|
|
|
|
+ logging.error('失败详细信息:', repr(e))
|
|
|
|
+
|
|
|
|
+ def handler(self, date_type, account_id, start_date, end_date):
|
|
|
|
+ if date_type == "daily":
|
|
|
|
+ self.daily_report(account_id, start_date, end_date)
|
|
|
|
+ else:
|
|
|
|
+ self.hourly_report(account_id, start_date, end_date)
|