alg_growth_common.py 846 B

1234567891011121314151617181920212223242526
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # vim:fenc=utf-8
  4. #
  5. # Copyright © 2024 StrayWarrior <i@straywarrior.com>
  6. """
  7. Common functions for growth jobs
  8. """
  9. UNSAFE_VIDEO_IDS = [14403867, 13696461, 13671819, 13587868, 13680796, 14050873,
  10. 26348326, 28623786]
  11. def check_unsafe_video(df, force_replace=True):
  12. unsafe_video_condition = ','.join([str(x) for x in UNSAFE_VIDEO_IDS])
  13. unsafe_rows = df.query(f'video_id in ({unsafe_video_condition})')
  14. if len(unsafe_rows) > 0:
  15. print(unsafe_rows)
  16. if not force_replace:
  17. raise Exception("video unsafe")
  18. df.loc[unsafe_rows.index, 'video_id'] = 20463342
  19. def filter_unsafe_video(df):
  20. unsafe_video_condition = ','.join([str(x) for x in UNSAFE_VIDEO_IDS])
  21. df = df.query(f'video_id not in ({unsafe_video_condition})')
  22. return df