| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 | # Author renyupeng# coding=utf-8# @Time    : 2021/11/10 3:37 下午# @Site    :# @File    : AppKuaishouProductReportBusiMonth.py# @Software: PyCharm# @contact: renyupeng@c-top.com.cn# @Tel 1501435553import loggingfrom Apietl.conn.TidbConn import TidbConnfrom Apietl.utlis.Utils import Utilsclass AppKuaishouProductReportBusiMonth:    def __init__(self):        self.conn = TidbConn.get_connection()        self.parm = Utils.get_task_args()        self.date_time = self.parm[0]        self.day_count = Utils.get_days()    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 app_kuaishou_product_report_busi_mSELECTdate_format({date_time},'%Y%m') stat_mon,uc.company_id,CASE WHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN '北京汇创思拓数字科技有限公司'       WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN '广州汇创思拓数字科技有限公司'       WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN '上海汇创思拓数字科技有限公司' ELSE uc.company_name END company_name, cp.product_id, cn.product_name, count(report.advertiser_id) account_num, sum(charge) charge,  sum(`show`) `show`,  sum(photo_click)photo_click,  sum(aclick)  aclick,  sum(bclick) bclick,  round(sum(photo_click)/sum(`show`),3) photo_click_ratio,  round(sum(play_3s_ratio)/{day_count}*100,3)  play_3s_ratio,  round(sum(bclick)/sum(aclick)*100,3) action_ratio,  round(sum(impression_1k_cost)/{day_count},3) impression_1k_cost,  round(sum(charge)/sum(photo_click),3) photo_click_cost,  round(sum(charge)/sum(bclick),3) 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,  round(sum(event_pay_purchase_amount_first_day)/sum(charge)*100,3) event_pay_first_day_roi ,  sum(event_pay) event_pay,  sum(event_pay_purchase_amount) event_pay_purchase_amount,  round(sum(event_pay_purchase_amount)/sum(charge)*100,3) event_pay_roi,  sum(event_register) event_register,  round(sum(charge)/sum(event_register),3) event_register_cost,  round(sum(event_register)/sum(activation)*100,3)  event_register_ratio,  sum(event_jin_jian_app) event_jin_jian_app,  round(sum(charge)/sum(event_jin_jian_app),3) event_jin_jian_app_cost,  sum(event_credit_grant_app) event_credit_grant_app,  round(sum(charge)/sum(event_credit_grant_app),3) event_credit_grant_app_cost ,  round(sum(event_credit_grant_app_ratio)/{day_count}*100,3) event_credit_grant_app_ratio,  sum(event_order_paid) event_order_paid,  sum(event_order_paid_purchase_amount) event_order_paid_purchase_amount,  round(sum(event_order_paid_purchase_amount)/sum(event_order_paid) ,3) event_order_paid_cost,  sum(event_next_day_stay) event_next_day_stay,  round(sum(charge)/sum(event_next_day_stay),3) event_next_day_stay_cost,  round(sum(event_next_day_stay)/sum(activation)*100,3) event_next_day_stay_ratio,  sum(form_count) form_count,  round(sum(charge)/sum(form_count),3) form_cost,  round(sum(form_count)/sum(`bclick`)*100,3) form_action_ratio,  sum(event_jin_jian_landing_page) event_jin_jian_landing_page,  round(sum(charge)/sum(event_jin_jian_landing_page),3) event_jin_jian_landing_page_cost,  sum(event_credit_grant_landing_page) event_credit_grant_landing_page,  round(sum(charge)/sum(event_credit_grant_landing_page),3) event_credit_grant_landing_page_cost,  round(sum(event_credit_grant_landing_page)/{day_count}*100,3) event_credit_grant_landing_page_ratio,  sum(event_valid_clues) event_valid_clues,  round(sum(charge)/sum(event_valid_clues),3) event_valid_clues_cost,  sum(event_add_wechat) event_add_wechat,  round(sum(charge)/sum(event_add_wechat),3) event_add_wechat_cost,  round(sum(event_add_wechat)/sum(bclick)*100,3) event_add_wechat_ratio,  sum(event_get_through) event_get_through,  round(sum(charge)/sum(event_get_through),3) event_get_through_cost,  round(sum(event_get_through)/sum(bclick)*100,3) event_get_through_ratio,  sum(event_app_invoked) event_app_invoked,  round(sum(charge)/sum(event_app_invoked),3) event_app_invoked_cost ,  round(sum(event_app_invoked)/sum(bclick)*100,3) event_app_invoked_ratio,  round(sum(event_credit_grant_landing_ratio)/{day_count}*100,3) event_credit_grant_landing_ratio,  round(sum(play_5s_ratio)/{day_count}*100,3) play_5s_ratio,  round(sum(play_end_ratio)/{day_count}*100,3) play_end_ratio,  sum(event_new_user_pay) event_new_user_pay,  round(sum(charge)/sum(event_new_user_pay),3) event_new_user_pay_cost,  round(sum(event_new_user_pay)/sum(activation)*100,3) event_new_user_pay_ratio,  round(sum(click_1k_cost)/{day_count}*100) click_1k_cost,  sum(ad_product_cnt) ad_product_cnt,  sum(event_goods_view) event_goods_view,  sum(merchant_reco_fans) merchant_reco_fans,  round(sum(event_order_amount_roi)/{day_count}*100,3) event_order_amount_roi,  round(sum(charge)/sum(event_goods_view) ,3) event_goods_view_cost,  round(sum(charge)/sum(merchant_reco_fans),3) merchant_reco_fans_cost,  sum(event_button_click) event_button_click,  round(sum(charge)/sum(event_button_click),3) event_button_click_cost,  round(sum(event_button_click)/sum(bclick)*100,3) event_button_click_ratio ,  round(sum(event_order_paid_roi)/{day_count}*100,3) event_order_paid_roi,  sum(event_new_user_jinjian_app) event_new_user_jinjian_app,  round(sum(charge)/sum(event_new_user_jinjian_app),3) event_new_user_jinjian_app_cost,  round(sum(event_new_user_jinjian_app)/sum(form_count)*100,3) event_new_user_jinjian_app_roi ,  sum(event_new_user_credit_grant_app) event_new_user_credit_grant_app,  round(sum(charge)/sum(event_new_user_credit_grant_app),3)  event_new_user_credit_grant_app_cost,  round(sum(event_new_user_credit_grant_app)/sum(form_count)*100,3) event_new_user_credit_grant_app_roi,  sum(event_new_user_jinjian_page) event_new_user_jinjian_page,  round(sum(charge)/sum(event_new_user_jinjian_page),3) event_new_user_jinjian_page_cost,  round(sum(event_new_user_jinjian_page)/sum(form_count)*100,3) event_new_user_jinjian_page_roi ,  sum(event_new_user_credit_grant_page) event_new_user_credit_grant_page,  round(sum(charge)/sum(event_new_user_credit_grant_page) ,3) event_new_user_credit_grant_page_cost,  round(sum(event_new_user_credit_grant_page)/sum(form_count)*100,3) event_new_user_credit_grant_page_roi,  sum(event_appoint_form)  event_appoint_form,  round(sum(charge)/sum(event_appoint_form),3) event_appoint_form_cost,  round(sum(event_appoint_form)/sum(form_count)*100,3) event_appoint_form_ratio,  sum(event_appoint_jump_click) event_appoint_jump_click,  round(sum(charge)/sum(event_appoint_jump_click),3)  event_appoint_jump_click_cost,  round(sum(event_appoint_jump_click_cost)/sum(form_count)*100,3) event_appoint_jump_click_ratio,  sum(union_event_pay_purchase_amount_7d) union_event_pay_purchase_amount_7d,  round(sum(union_event_pay_purchase_amount_7d_roi)/{day_count}*100,3) union_event_pay_purchase_amount_7d_roi,  sum(event_order_successed) event_order_successed,  round(sum(ad_photo_played_10s_ratio)/{day_count}*100,3) ad_photo_played_10s_ratio,  round(sum(charge)/sum(key_action),3) key_action_cost,  round(sum(charge)/sum(event_add_shopping_cart) ,3) event_add_shopping_cart_cost ,  round(sum(event_ad_watch_times)/sum(bclick)*100,3) event_ad_watch_times_ratio,  round(sum(charge)/sum(event_outbound_call),3) event_outbound_call_cost,  sum(event_outbound_call) event_outbound_call,  round(sum(action_new_ratio)/{day_count}*100,3) action_new_ratio,  sum(event_watch_app_ad) event_watch_app_ad,  round(sum(charge)/sum(event_multi_conversion) ,3) event_multi_conversion_cost,  sum(event_phone_card_activate) event_phone_card_activate,  round(sum(ad_photo_played_75percent_ratio)/{day_count}*100,3) ad_photo_played_75percent_ratio,  round(sum(key_action)/sum(activation)*100,3) key_action_ratio ,  round(sum(charge)/sum(event_ad_watch_times),3) 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,  round(sum(event_multi_conversion)/sum(activation)*100,3)  event_multi_conversion_ratio,  sum(event_measurement_house) event_measurement_house,  round(sum(ad_photo_played_2s_ratio)/{day_count}*100,3) ad_photo_played_2s_ratio,  round(sum(event_outbound_call_ratio)/sum(activation)*100,3) event_outbound_call_ratio,  sum(event_ad_watch_times) event_ad_watch_times from   (select * from  media_api.kuaishou_account_report_daily   where stat_date >= date_format(date_sub({date_time}, INTERVAL {day_count}  DAY),'%Y%m%d')) reportLEFT JOIN `jeecg-boot`.ctop_user_allocation cua ON report.advertiser_id = cua.account_idLEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.idLEFT JOIN `jeecg-boot`.ctop_product cn ON cp.product_id = cn.idLEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_idGROUP BYuc.company_id,CASEWHEN uc.company_id = 'd57fecdcf7a94d009736d9c850731582' THEN'北京汇创思拓数字科技有限公司'WHEN uc.company_id = '6608ed13c0dd42de93c790dbdf124234' THEN'广州汇创思拓数字科技有限公司'WHEN uc.company_id = '4b10089775c040119e139087517aed88' THEN'上海汇创思拓数字科技有限公司'ELSEuc.company_nameEND, cp.product_id, cn.product_name;            """.format(date_time=self.date_time, day_count=self.day_count)            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 -1if __name__ == '__main__':    status = AppKuaishouProductReportBusiMonth().taskHandler()    if status == 0:        print("作业执行成功")        exit(0)    else:        print("作业执行失败")        exit(-1)
 |