import sys import traceback import pandas as pd from utils import get_data_from_odps, send_msg_to_feishu from config import set_config from log import Log config_, _ = set_config() log_ = Log() features = [ 'apptype', 'code', 'videoid', 'lastonehour_preview', # 过去1小时预曝光人数 'lastonehour_view', # 过去1小时曝光人数 'lastonehour_play', # 过去1小时播放人数 'lastonehour_share', # 过去1小时分享人数 'lastonehour_return', # 过去1小时分享,过去1小时回流人数 'lastonehour_preview_total', # 过去1小时预曝光次数 'lastonehour_view_total', # 过去1小时曝光次数 'lastonehour_play_total', # 过去1小时播放次数 'lastonehour_share_total', # 过去1小时分享次数 'platform_return', 'lastonehour_show', # 不区分地域 'lastonehour_show_region', # 地域分组 'lasttwohour_share', # h-2小时分享人数 'lasttwohour_return_now', # h-2分享,过去1小时回流人数 'lasttwohour_return', # h-2分享,h-2回流人数 'lastthreehour_share', # h-3小时分享人数 'lastthreehour_return_now', # h-3分享,过去1小时回流人数 'lastthreehour_return', # h-3分享,h-3回流人数 'lastonehour_return_new', # 过去1小时分享,过去1小时回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域) 'lasttwohour_return_now_new', # h-2分享,过去1小时回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域) 'lasttwohour_return_new', # h-2分享,h-2回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域) 'lastthreehour_return_now_new', # h-3分享,过去1小时回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域) 'lastthreehour_return_new', # h-3分享,h-3回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域) 'platform_return_new', # 平台分发回流(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域) ] def get_feature_data(project, table, now_date): """获取特征数据""" # dt = datetime.datetime.strftime(now_date, '%Y%m%d%H') # dt = '2022041310' records = get_data_from_odps(date=now_date, project=project, table=table) feature_data = [] for record in records: item = {} for feature_name in features: item[feature_name] = record[feature_name] feature_data.append(item) feature_df = pd.DataFrame(feature_data) return feature_df if __name__ == "__main__": try: project = config_.PROJECT_REGION_APP_TYPE table = config_.TABLE_REGION_APP_TYPE now_date = sys.argv[1] print("now date:", now_date) data = get_feature_data(project=project, table=table, now_date=now_date) data = data.fillna(0) data.to_csv(f"./data/hour_video_data_{now_date}.csv", index=False) print(f"hour video data shape: {data.shape}") except Exception as e: log_.error(f"rank 小时级数据下载失败, exception: {e}, traceback: {traceback.format_exc()}") send_msg_to_feishu( webhook=config_.FEISHU_ROBOT['server_robot'].get('webhook'), key_word=config_.FEISHU_ROBOT['server_robot'].get('key_word'), msg_text=f"rov-offline{config_.ENV_TEXT} - rank 小时级数据下载失败\n" f"exception: {e}\n" f"traceback: {traceback.format_exc()}" )