| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 | # Author renyupeng# coding=utf-8# @Time    : 2021/9/15 5:10 下午# @Site    :# @File    : NewMaterialimageDailyReport.py# @Software: PyCharm# @contact: renyupeng@c-top.com.cnimport loggingfrom Apietl.utlis.Utils import Utilsfrom Apietl.conn.TidbConn import TidbConnclass NewMaterialimageDailyReport:    def __init__(self):        self.conn = TidbConn.get_connection()        self.parm = Utils.get_live_args()        self.start_time = self.parm    def daily_report(self):        try:            sql = """replace into application.bytedance_material_image_report_daily_dw(account_id, material_id, image_mode, inventory,                                                                  stat_datetime, project_id, product_id, advertiser_id,                                                                  company_id, account_name, project_name,                                                                  advertiser_name, company_name, sale_id, user_id,                                                                  image_name,                                                                  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,                                                                  active_pay_amount, 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, 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, cpc,                                                                  cpm, cpa, interact_per_cost, convert_show_rate,                                                                  play_duration_10s_rate, play_50_feed_break_rate,                                                                  play_25_feed_break_rate, play_duration_5s_rate,                                                                  play_duration_2s_rate, average_play_progress,                                                                  play_100_feed_break_rate, play_duration_3s_rate,                                                                  play_75_feed_break_rate, play_duration,                                                                  play_duration_3s, play_duration_2s, play_duration_10s,                                                                  average_video_play, avg_rank,                                                                  submit_certification_count, approval_count,                                                                  first_order_count, first_rental_order_count,                                                                  commute_first_pay_count, image_url, signature)select report.advertiser_id account_id,      #'账户ID'       report.material_id,                   #头条素材id       '' as                image_mode,      #素材类型       '' as                inventory,       #广告位       report.stat_datetime,                 #数据起始时间       cua.project_id,                       #项目id       product.id           product_id,      #项目中产品id       cua.advertiser_id,                    #广告主id       uc.company_id,                        #运营人的公司id       cua.auth_name        account_name,    #账户名称       cp.project_name,                      #项目名称       ca.name              advertiser_name, #广告主名称       uc.company_name,                      #运营人的公司名称       cp.sale_id,                           #项目里的销售id       cua.user_id,                          #运营id       image.filename,       report.stat_cost,       report.show_cnt,       0 as                show_cost,       report.`convert_cnt`,       report.`cpc_platform`,       report.`ctr`,       report.`convert_cnt`,       report.`conversion_cost`,       report.`conversion_rate`,       report.`deep_convert_cnt`,       report.`deep_convert_cost`,       report.`deep_convert_rate`,       0 as                `attribution_convert`,       0 as                `attribution_convert_cost`,       0 as                `attribution_deep_convert`,       0 as                `attribution_deep_convert_cost`,       report.`click_start_cnt`,       report.`click_start_cost`,       report.`click_start_rate`,       report.`download_finish_cnt`,       report.`download_finish_cost`,       report.`download_finish_rate`,       0 as                `click_install`,       report.`install_finish_cnt`,       report.`install_finish_cost`,       report.`install_finish_rate`,       report.`active`,       report.`active_cost`,       report.`active_rate`,       report.`active_register`,       report.`active_register_cost`,       report.`active_register_rate`,       0 as                `active_pay_amount`,       report.`next_day_open`,       0 as                `next_day_open_cost`,       0 as                `next_day_open_rate`,       report.`attribution_next_day_open_cnt`,       report.`attribution_next_day_open_cost`,       report.`attribution_next_day_open_rate`,       report.`game_addiction`,       report.`game_addiction_cost`,       report.`game_addiction_rate`,       0 as                `cnt`,       report.`active_pay_cost`,       report.`active_pay_rate`,       0 as                `loan_completion`,       0 as                `loan_completion_cost`,       0 as                `loan_completion_rate`,       0 as                `pre_loan_credit`,       0 as                `pre_loan_credit_cost`,       0 as                `loan_credit`,       0 as                `loan_credit_cost`,       0 as                `loan_credit_rate`,       report.`in_app_uv`,       report.`in_app_detail_uv`,       report.`in_app_cart`,       report.`in_app_pay`,       report.`in_app_order`,       report.`attribution_game_pay_7d_count`,       report.`attribution_game_pay_7d_cost`,       0 as                `attribution_active_pay_7d_per_count`,       report.`game_pay_cost`,       report.`game_pay_count`,       0 as                `phone`,       0 as                `form`,       0 as                `map_search`,       0 as                `button`,       0 as                `view`,       0 as                `download`,       0 as                `qq`,       0 as                `lottery`,       0 as                `vote`,       0 as                `message`,       0 as                `redirect`,       0 as                `shopping`,       0 as                `consult`,       0 as                `wechat`,       0 as                `phone_confirm`,       0 as                `phone_connect`,       0 as                `consult_effective`,       0 as                `coupon`,       0 as                `coupon_single_page`,       0 as                `redirect_to_shop`,       0 as                `poi_collect`,       0 as                `poi_address_click`,       0 as                `luban_order_cnt`,       0 as                `luban_order_stat_amount`,       0 as                `luban_order_roi`,       0 as                `luban_live_enter_cnt`,       0 as                `live_watch_one_minute_count`,       0 as                `luban_live_follow_cnt`,       0 as                `live_fans_club_join_cnt`,       0 as                `luban_live_comment_cnt`,       0 as                `luban_live_share_cnt`,       0 as                `luban_live_gift_cnt`,       0 as                `luban_live_gift_amount`,       0 as                `luban_live_slidecart_click_cnt`,       0 as                `luban_live_click_product_cnt`,       0 as                `luban_live_pay_order_count`,       0 as                `luban_live_pay_order_stat_cost`,       0 as                `wechat_login_count`,       0 as                `attribution_wechat_login_30d_count`,       0 as                `wechat_login_cost`,       0 as                `attribution_wechat_login_30d_cost`,       0 as                `wechat_first_pay_count`,       0 as                `attribution_wechat_first_pay_30d_count`,       0 as                `wechat_first_pay_cost`,       0 as                `attribution_wechat_first_pay_30d_cost`,       0 as                `wechat_first_pay_rate`,       0 as                `attribution_wechat_first_pay_30d_rate`,       0 as                `wechat_pay_amount`,       0 as                `attribution_wechat_pay_30d_amount`,       0 as                `attribution_wechat_pay_30d_roi`,       0 as                `phone_effective`,       0 as                `total_play`,       0 as                `valid_play`,       0 as                `valid_play_cost`,       0 as                `valid_play_rate`,       0 as                `play_25_feed_break`,       0 as                `play_50_feed_break`,       0 as                `play_75_feed_break`,       0 as                `play_100_feed_break`,       0 as                `average_play_time_per_play`,       0 as                `play_over_rate`,       0 as                `wifi_play_rate`,       0 as                `wifi_play`,       0 as                `play_duration_sum`,       0 as                `advanced_creative_phone_click`,       0 as                `advanced_creative_counsel_click`,       0 as                `advanced_creative_form_click`,       0 as                `advanced_creative_coupon_addition`,       0 as                `advanced_creative_form_submit`,       0 as                `card_show`,       0 as                `share`,       0 as                `comment`,       0 as                `like`,       0 as                `follow`,       0 as                `home_visited`,       0 as                `ies_challenge_click`,       0 as                `ies_music_click`,       0 as                `location_click`,       0 as                `message_action`,       0 as                `click_landing_page`,       0 as                `click_shopwindow`,       0 as                `click_website`,       0 as                `click_download`,       0 as                `click_call_dy`,       0 as                `cpc`,       0 as                `cpm`,       0 as                `cpa`,       0 as                `interact_per_cost`,       0 as                `convert_show_rate`,       0 as                `play_duration_10s_rate`,       0 as                `play_50_feed_break_rate`,       0 as                `play_25_feed_break_rate`,       0 as                `play_duration_5s_rate`,       0 as                `play_duration_2s_rate`,       0 as                `average_play_progress`,       0 as                `play_100_feed_break_rate`,       0 as                `play_duration_3s_rate`,       0 as                `play_75_feed_break_rate`,       0 as                `play_duration`,       0 as                `play_duration_3s`,       0 as                `play_duration_2s`,       0 as                `play_duration_10s`,       0 as                `average_video_play`,       0 as                `avg_rank`,       0 as                `submit_certification_count`,       0 as                `approval_count`,       0 as                `first_order_count`,       0 as                `first_rental_order_count`,       0 as                `commute_first_pay_count`,       image.image_url,       image.signaturefrom media_api.bytedance_material_image_daily report         left join     `media_api`.bytedance_file_image_get image     on report.material_id = image.material_id         and report.advertiser_id = image.advertiser_id         left join `jeecg-boot`.ctop_user_allocation cua                   on report.advertiser_id = cua.account_id         left join `jeecg-boot`.ctop_advertiser ca                   on cua.advertiser_id = ca.id         left join `jeecg-boot`.ctop_project cp                   on cua.project_id = cp.id         left join `jeecg-boot`.user_company uc                   on cua.user_id = uc.user_id         left join `jeecg-boot`.ctop_product product                   on cp.product_id = product.id         left join `jeecg-boot`.sys_user su                   on cua.user_id = su.idwhere report.stat_datetime = {start_time}                                    """.format(start_time=self.start_time)            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 -1if __name__ == '__main__':    status = NewMaterialimageDailyReport().daily_report()    if status == 0:        print("作业执行成功")        exit(0)    else:        print("作业执行失败")        exit(-1)
 |