export_hour_vid.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import sys
  2. import pandas as pd
  3. from utils import get_data_from_odps
  4. from config import set_config
  5. from log import Log
  6. config_, _ = set_config()
  7. log_ = Log()
  8. features = [
  9. 'apptype',
  10. 'code',
  11. 'videoid',
  12. 'lastonehour_preview', # 过去1小时预曝光人数
  13. 'lastonehour_view', # 过去1小时曝光人数
  14. 'lastonehour_play', # 过去1小时播放人数
  15. 'lastonehour_share', # 过去1小时分享人数
  16. 'lastonehour_return', # 过去1小时分享,过去1小时回流人数
  17. 'lastonehour_preview_total', # 过去1小时预曝光次数
  18. 'lastonehour_view_total', # 过去1小时曝光次数
  19. 'lastonehour_play_total', # 过去1小时播放次数
  20. 'lastonehour_share_total', # 过去1小时分享次数
  21. 'platform_return',
  22. 'lastonehour_show', # 不区分地域
  23. 'lastonehour_show_region', # 地域分组
  24. 'lasttwohour_share', # h-2小时分享人数
  25. 'lasttwohour_return_now', # h-2分享,过去1小时回流人数
  26. 'lasttwohour_return', # h-2分享,h-2回流人数
  27. 'lastthreehour_share', # h-3小时分享人数
  28. 'lastthreehour_return_now', # h-3分享,过去1小时回流人数
  29. 'lastthreehour_return', # h-3分享,h-3回流人数
  30. 'lastonehour_return_new', # 过去1小时分享,过去1小时回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域)
  31. 'lasttwohour_return_now_new', # h-2分享,过去1小时回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域)
  32. 'lasttwohour_return_new', # h-2分享,h-2回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域)
  33. 'lastthreehour_return_now_new', # h-3分享,过去1小时回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域)
  34. 'lastthreehour_return_new', # h-3分享,h-3回流人数(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域)
  35. 'platform_return_new', # 平台分发回流(回流统计为对应地域分享带回的回流,分享限制地域,回流不限制地域)
  36. ]
  37. def get_feature_data(project, table, now_date):
  38. """获取特征数据"""
  39. # dt = datetime.datetime.strftime(now_date, '%Y%m%d%H')
  40. # dt = '2022041310'
  41. records = get_data_from_odps(date=now_date, project=project, table=table)
  42. feature_data = []
  43. for record in records:
  44. item = {}
  45. for feature_name in features:
  46. item[feature_name] = record[feature_name]
  47. feature_data.append(item)
  48. feature_df = pd.DataFrame(feature_data)
  49. return feature_df
  50. if __name__ == "__main__":
  51. project = config_.PROJECT_REGION_APP_TYPE
  52. table = config_.TABLE_REGION_APP_TYPE
  53. now_date = sys.argv[1]
  54. print("now date:", now_date)
  55. data = get_feature_data(project=project, table=table, now_date=now_date)
  56. data = data.fillna(0)
  57. data.to_csv(f"./data/hour_video_data_{now_date}.csv", index=False)
  58. print(f"data shape: {data.shape}")