From ff9f5bb7eaacbeb0f2d94e0164154d08492fc8ae Mon Sep 17 00:00:00 2001 From: Paul Leclercq Date: Thu, 26 Sep 2024 11:11:45 +0200 Subject: [PATCH] fix: program name can be null when margin is not enough (#247) --- quotaclimat/data_processing/mediatree/channel_program.py | 6 +++--- quotaclimat/data_processing/mediatree/utils.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/quotaclimat/data_processing/mediatree/channel_program.py b/quotaclimat/data_processing/mediatree/channel_program.py index 63837145..efb895d8 100644 --- a/quotaclimat/data_processing/mediatree/channel_program.py +++ b/quotaclimat/data_processing/mediatree/channel_program.py @@ -3,7 +3,7 @@ import os from datetime import datetime import json -from quotaclimat.data_processing.mediatree.utils import get_epoch_from_datetime, EPOCH__5MIN_MARGIN +from quotaclimat.data_processing.mediatree.utils import get_epoch_from_datetime, EPOCH__5MIN_MARGIN, EPOCH__1MIN_MARGIN def format_hour_minute(time: str) -> pd.Timestamp: date_str = "1970-01-01" @@ -81,8 +81,8 @@ def get_day_of_week(time: pd.Timestamp) -> int: def get_matching_program_hour(df_program: pd.DataFrame, start_time: pd.Timestamp): start_time = get_hour_minute(start_time) matching_rows = df_program[ - (df_program['start'] <= (start_time + pd.Timedelta(seconds=EPOCH__5MIN_MARGIN))) & - (df_program['end'] > (start_time - pd.Timedelta(seconds=EPOCH__5MIN_MARGIN))) # stricly > to avoid overlapping programs + (df_program['start'] <= (start_time + pd.Timedelta(seconds=EPOCH__5MIN_MARGIN + EPOCH__1MIN_MARGIN))) & + (df_program['end'] > (start_time - pd.Timedelta(seconds=EPOCH__5MIN_MARGIN + EPOCH__1MIN_MARGIN))) ] if(len(matching_rows) > 1): # no margin necessary because programs are next to each others return df_program[ diff --git a/quotaclimat/data_processing/mediatree/utils.py b/quotaclimat/data_processing/mediatree/utils.py index 24b0e7ad..8344659b 100644 --- a/quotaclimat/data_processing/mediatree/utils.py +++ b/quotaclimat/data_processing/mediatree/utils.py @@ -9,6 +9,7 @@ timezone='Europe/Paris' EPOCH__5MIN_MARGIN = 300 +EPOCH__1MIN_MARGIN = 60 # to add margin for program def get_keyword_time_separation_ms(duration_seconds: int = 15): return duration_seconds * 1000