zhl 3 年之前
父節點
當前提交
cd0ca3660c
共有 1 個文件被更改,包括 340 次插入0 次删除
  1. 340 0
      Apietl/test/AppBytedanceAdvertiserReportBusiMonth.py

+ 340 - 0
Apietl/test/AppBytedanceAdvertiserReportBusiMonth.py

@@ -0,0 +1,340 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2021/11/10 3:37 下午
+# @Site    :
+# @File    : AppKuaishouVideoReportBusiMonth.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import logging
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class  AppKuaishouAccountReportBusiMonth:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.day_count = 30
+    def taskHandler(self):
+        try:
+            sql = """
+            SET sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
+REPLACE INTO application.app_kuaishou_account_report_busi_m
+SELECT
+date_format(20211101,'%Y%m') stat_mon,
+report.account_id,
+bei.project_id,
+bei.product_id,
+bei.advertiser_id,
+bei.company_id,
+bei.account_name,
+bei.project_name,
+bei.advertiser_name,
+bei.company_name,
+bei.sale_id,
+bei.user_id,
+bei.leader_id,
+bei.org_code,
+report.charge,
+report.`show`,
+report.photo_click,
+report.aclick,
+report.bclick,
+report.photo_click_ratio,
+report.play_3s_ratio,
+report.action_ratio,
+report.impression_1k_cost,
+report.photo_click_cost,
+report.action_cost,
+report.`share`,
+report.`comment`,
+report.`like`,
+report.follow,
+report.cancel_follow,
+report.report,
+report.block,
+report.negative,
+report.submit,
+report.download_started,
+report.download_completed,
+report.activation,
+report.event_pay_first_day,
+report.event_pay_purchase_amount_first_day,
+report.event_pay_first_day_roi,
+report.event_pay,
+report.event_pay_purchase_amount,
+report.event_pay_roi,
+report.event_register,
+report.event_register_cost,
+report.event_register_ratio,
+report.event_jin_jian_app,
+report.event_jin_jian_app_cost,
+report.event_credit_grant_app,
+report.event_credit_grant_app_cost,
+report.event_credit_grant_app_ratio,
+report.event_order_paid,
+report.event_order_paid_purchase_amount,
+report.event_order_paid_cost,
+report.event_next_day_stay,
+report.event_next_day_stay_cost,
+report.event_next_day_stay_ratio,
+report.form_count,
+report.form_cost,
+report.form_action_ratio,
+report.event_jin_jian_landing_page,
+report.event_jin_jian_landing_page_cost,
+report.event_credit_grant_landing_page,
+report.event_credit_grant_landing_page_cost,
+report.event_credit_grant_landing_page_ratio,
+report.event_valid_clues,
+report.event_valid_clues_cost,
+report.event_add_wechat,
+report.event_add_wechat_cost,
+report.event_add_wechat_ratio,
+report.event_get_through,
+report.event_get_through_cost,
+report.event_get_through_ratio,
+report.event_app_invoked,
+report.event_app_invoked_cost,
+report.event_app_invoked_ratio,
+report.event_credit_grant_landing_ratio,
+report.play_5s_ratio,
+report.play_end_ratio,
+report.event_new_user_pay,
+report.event_new_user_pay_cost,
+report.event_new_user_pay_ratio,
+report.click_1k_cost,
+report.ad_product_cnt,
+report.event_goods_view,
+report.merchant_reco_fans,
+report.event_order_amount_roi,
+report.event_goods_view_cost,
+report.merchant_reco_fans_cost,
+report.event_button_click,
+report.event_button_click_cost,
+report.event_button_click_ratio,
+report.event_order_paid_roi,
+report.event_new_user_jinjian_app,
+report.event_new_user_jinjian_app_cost,
+report.event_new_user_jinjian_app_roi,
+report.event_new_user_credit_grant_app,
+report.event_new_user_credit_grant_app_cost,
+report.event_new_user_credit_grant_app_roi,
+report.event_new_user_jinjian_page,
+report.event_new_user_jinjian_page_cost,
+report.event_new_user_jinjian_page_roi,
+report.event_new_user_credit_grant_page,
+report.event_new_user_credit_grant_page_cost,
+report.event_new_user_credit_grant_page_roi,
+report.event_appoint_form,
+report.event_appoint_form_cost,
+report.event_appoint_form_ratio,
+report.event_appoint_jump_click,
+report.event_appoint_jump_click_cost,
+report.event_appoint_jump_click_ratio,
+report.union_event_pay_purchase_amount_7d,
+report.union_event_pay_purchase_amount_7d_roi,
+report.event_order_successed,
+report.ad_photo_played_10s_ratio,
+report.key_action_cost,
+report.event_add_shopping_cart_cost,
+report.event_ad_watch_times_ratio,
+report.event_outbound_call_cost,
+report.event_outbound_call,
+report.action_new_ratio,
+report.event_watch_app_ad,
+report.event_multi_conversion_cost,
+report.event_phone_card_activate,
+report.ad_photo_played_75percent_ratio,
+report.key_action_ratio,
+report.event_ad_watch_times_cost,
+report.event_add_shopping_cart,
+report.key_action,
+report.event_multi_conversion,
+report.event_wechat_connected,
+report.event_dsp_gift_form,
+report.event_intention_confirmed,
+report.event_phone_get_through,
+report.event_multi_conversion_ratio,
+report.event_measurement_house,
+report.ad_photo_played_2s_ratio,
+report.event_outbound_call_ratio,
+report.event_ad_watch_times
+from 
+(select 
+advertiser_id account_id,
+sum(charge) charge,
+sum(`show`) `show`,
+sum(photo_click)photo_click,
+sum(aclick)  aclick,
+sum(bclick) bclick,
+ifnull(round(sum(photo_click)/sum(`show`),3),0) photo_click_ratio,
+ifnull(round(sum(play_3s_ratio)/{day_count}*100,3),0)  play_3s_ratio,
+ifnull(round(sum(bclick)/sum(aclick)*100,3),0) action_ratio,
+ifnull(round(sum(impression_1k_cost)/{day_count},3),0) impression_1k_cost,
+ifnull(round(sum(charge)/sum(photo_click),3),0) photo_click_cost,
+ifnull(round(sum(charge)/sum(bclick),3),0) action_cost,
+sum(`share`) `share`,
+sum(`comment`) `comment`,
+sum(`like`)  `like`,
+sum(follow) follow,
+sum(cancel_follow)  cancel_follow,
+sum(report) report,
+sum(block) block,
+sum(negative) negative,
+sum(submit) submit,
+sum(download_started) download_started,
+sum(download_completed) download_completed,
+sum(activation) activation,
+sum(event_pay_first_day) event_pay_first_day,
+sum(event_pay_purchase_amount_first_day) event_pay_purchase_amount_first_day,
+ifnull(round(sum(event_pay_purchase_amount_first_day)/sum(charge)*100,3),0) event_pay_first_day_roi ,
+sum(event_pay) event_pay,
+sum(event_pay_purchase_amount) event_pay_purchase_amount,
+ifnull(round(sum(event_pay_purchase_amount)/sum(charge)*100,3),0) event_pay_roi,
+sum(event_register) event_register,
+ifnull(round(sum(charge)/sum(event_register),3),0) event_register_cost,
+ifnull(round(sum(event_register)/sum(activation)*100,3),0) event_register_ratio,
+sum(event_jin_jian_app) event_jin_jian_app,
+ifnull(round(sum(charge)/sum(event_jin_jian_app),3),0) event_jin_jian_app_cost,
+sum(event_credit_grant_app) event_credit_grant_app,
+ifnull(round(sum(charge)/sum(event_credit_grant_app),3),0) event_credit_grant_app_cost ,
+ifnull(round(sum(event_credit_grant_app_ratio)/{day_count}*100,3),0) event_credit_grant_app_ratio,
+sum(event_order_paid) event_order_paid,
+sum(event_order_paid_purchase_amount) event_order_paid_purchase_amount,
+ifnull(round(sum(event_order_paid_purchase_amount)/sum(event_order_paid) ,3),0) event_order_paid_cost,
+sum(event_next_day_stay) event_next_day_stay,
+ifnull(round(sum(charge)/sum(event_next_day_stay),3),0) event_next_day_stay_cost,
+ifnull(round(sum(event_next_day_stay)/sum(activation)*100,3),0) event_next_day_stay_ratio,
+sum(form_count) form_count,
+ifnull(round(sum(charge)/sum(form_count),3),0) form_cost,
+ifnull(round(sum(form_count)/sum(`bclick`)*100,3),0) form_action_ratio,
+sum(event_jin_jian_landing_page) event_jin_jian_landing_page,
+ifnull(round(sum(charge)/sum(event_jin_jian_landing_page),3),0) event_jin_jian_landing_page_cost,
+sum(event_credit_grant_landing_page) event_credit_grant_landing_page,
+ifnull(round(sum(charge)/sum(event_credit_grant_landing_page),3),0) event_credit_grant_landing_page_cost,
+ifnull(round(sum(event_credit_grant_landing_page)/{day_count}*100,3),0) event_credit_grant_landing_page_ratio,
+sum(event_valid_clues) event_valid_clues,
+ifnull(round(sum(charge)/sum(event_valid_clues),3),0) event_valid_clues_cost,
+sum(event_add_wechat) event_add_wechat,
+ifnull(round(sum(charge)/sum(event_add_wechat),3),0) event_add_wechat_cost,
+ifnull(round(sum(event_add_wechat)/sum(bclick)*100,3),0) event_add_wechat_ratio,
+sum(event_get_through) event_get_through,
+ifnull(round(sum(charge)/sum(event_get_through),3),0) event_get_through_cost,
+ifnull(round(sum(event_get_through)/sum(bclick)*100,3),0) event_get_through_ratio,
+sum(event_app_invoked) event_app_invoked,
+ifnull(round(sum(charge)/sum(event_app_invoked),3),0) event_app_invoked_cost ,
+ifnull(round(sum(event_app_invoked)/sum(bclick)*100,3),0) event_app_invoked_ratio,
+ifnull(round(sum(event_credit_grant_landing_ratio)/{day_count}*100,3),0) event_credit_grant_landing_ratio,
+ifnull(round(sum(play_5s_ratio)/{day_count}*100,3),0) play_5s_ratio,
+ifnull(round(sum(play_end_ratio)/{day_count}*100,3),0) play_end_ratio,
+sum(event_new_user_pay) event_new_user_pay,
+ifnull(round(sum(charge)/sum(event_new_user_pay),3),0) event_new_user_pay_cost,
+ifnull(round(sum(event_new_user_pay)/sum(activation)*100,3),0) event_new_user_pay_ratio,
+ifnull(round(sum(click_1k_cost)/{day_count}*100,3),0) click_1k_cost,
+sum(ad_product_cnt) ad_product_cnt,
+sum(event_goods_view) event_goods_view,
+sum(merchant_reco_fans) merchant_reco_fans,
+ifnull(round(sum(event_order_amount_roi)/{day_count}*100,3),0) event_order_amount_roi,
+ifnull(round(sum(charge)/sum(event_goods_view) ,3),0) event_goods_view_cost,
+ifnull(round(sum(charge)/sum(merchant_reco_fans),3),0) merchant_reco_fans_cost,
+sum(event_button_click) event_button_click,
+ifnull(round(sum(charge)/sum(event_button_click),3),0) event_button_click_cost,
+ifnull(round(sum(event_button_click)/sum(bclick)*100,3),0) event_button_click_ratio ,
+ifnull(round(sum(event_order_paid_roi)/{day_count}*100,3),0) event_order_paid_roi,
+sum(event_new_user_jinjian_app) event_new_user_jinjian_app,
+ifnull(round(sum(charge)/sum(event_new_user_jinjian_app),3),0) event_new_user_jinjian_app_cost,
+ifnull(round(sum(event_new_user_jinjian_app)/sum(form_count)*100,3),0) event_new_user_jinjian_app_roi ,
+sum(event_new_user_credit_grant_app) event_new_user_credit_grant_app,
+ifnull(round(sum(charge)/sum(event_new_user_credit_grant_app),3),0)  event_new_user_credit_grant_app_cost,
+ifnull(round(sum(event_new_user_credit_grant_app)/sum(form_count)*100,3),0) event_new_user_credit_grant_app_roi,
+sum(event_new_user_jinjian_page) event_new_user_jinjian_page,
+ifnull(round(sum(charge)/sum(event_new_user_jinjian_page),3),0) event_new_user_jinjian_page_cost,
+ifnull(round(sum(event_new_user_jinjian_page)/sum(form_count)*100,3),0) event_new_user_jinjian_page_roi ,
+sum(event_new_user_credit_grant_page) event_new_user_credit_grant_page,
+ifnull(round(sum(charge)/sum(event_new_user_credit_grant_page) ,3),0) event_new_user_credit_grant_page_cost,
+ifnull(round(sum(event_new_user_credit_grant_page)/sum(form_count)*100,3),0) event_new_user_credit_grant_page_roi,
+sum(event_appoint_form)  event_appoint_form,
+ifnull(round(sum(charge)/sum(event_appoint_form),3),0) event_appoint_form_cost,
+ifnull(round(sum(event_appoint_form)/sum(form_count)*100,3),0) event_appoint_form_ratio,
+sum(event_appoint_jump_click) event_appoint_jump_click,
+ifnull(round(sum(charge)/sum(event_appoint_jump_click),3),0)  event_appoint_jump_click_cost,
+ifnull(round(sum(event_appoint_jump_click_cost)/sum(form_count)*100,3),0) event_appoint_jump_click_ratio,
+sum(union_event_pay_purchase_amount_7d) union_event_pay_purchase_amount_7d,
+ifnull(round(sum(union_event_pay_purchase_amount_7d_roi)/{day_count}*100,3),0) union_event_pay_purchase_amount_7d_roi,
+sum(event_order_successed) event_order_successed,
+ifnull(round(sum(ad_photo_played_10s_ratio)/{day_count}*100,3),0) ad_photo_played_10s_ratio,
+ifnull(round(sum(charge)/sum(key_action),3),0) key_action_cost,
+ifnull(round(sum(charge)/sum(event_add_shopping_cart) ,3),0) event_add_shopping_cart_cost ,
+ifnull(round(sum(event_ad_watch_times)/sum(bclick)*100,3),0) event_ad_watch_times_ratio,
+ifnull(round(sum(charge)/sum(event_outbound_call),3),0) event_outbound_call_cost,
+sum(event_outbound_call) event_outbound_call,
+ifnull(round(sum(action_new_ratio)/{day_count}*100,3),0) action_new_ratio,
+sum(event_watch_app_ad) event_watch_app_ad,
+ifnull(round(sum(charge)/sum(event_multi_conversion) ,3),0) event_multi_conversion_cost,
+sum(event_phone_card_activate) event_phone_card_activate,
+ifnull(round(sum(ad_photo_played_75percent_ratio)/{day_count}*100,3),0) ad_photo_played_75percent_ratio,
+ifnull(round(sum(key_action)/sum(activation)*100,3),0) key_action_ratio ,
+ifnull(round(sum(charge)/sum(event_ad_watch_times),3),0) event_ad_watch_times_cost,
+sum(event_add_shopping_cart) event_add_shopping_cart,
+sum(key_action) key_action,
+sum(event_multi_conversion) event_multi_conversion,
+sum(event_wechat_connected) event_wechat_connected,
+sum(event_dsp_gift_form) event_dsp_gift_form,
+sum(event_intention_confirmed) event_intention_confirmed,
+sum(event_phone_get_through) event_phone_get_through,
+ifnull(round(sum(event_multi_conversion)/sum(activation)*100,3),0)  event_multi_conversion_ratio,
+sum(event_measurement_house) event_measurement_house,
+ifnull(round(sum(ad_photo_played_2s_ratio)/{day_count}*100,3),0) ad_photo_played_2s_ratio,
+ifnull(round(sum(event_outbound_call_ratio)/sum(activation)*100,3),0) event_outbound_call_ratio,
+sum(event_ad_watch_times) event_ad_watch_times
+from 
+ media_api.kuaishou_account_report_daily a  
+where stat_date between 20211101 and 20211130
+ group by advertiser_id) report
+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.leader_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) bei 
+ON report.account_id = bei.account_id;
+             """.format(day_count=self.day_count)
+            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 = AppKuaishouAccountReportBusiMonth().taskHandler()
+    if status == 0:
+        print("作业执行成功")
+        exit(0)
+    else:
+        print("作业执行失败")
+        exit(-1)