in src/process_results/ad_placements.py [0:0]
def add_text_presence(self, timestamp):
"""
add a new segment if:
1. there aren't any yet
-or-
2. the new timestamp is beyond the minimum_ad_duration of the latest one
otherwise just extend the latest segment
"""
if len(self.text_shown_segments) == 0:
print(f'Starting new segment at {timestamp}')
self.text_shown_segments.append({'start': timestamp, 'end': timestamp})
else:
latest_segment = self.text_shown_segments[-1]
time_since_last_segment = timestamp - latest_segment['end']
if time_since_last_segment < self.min_ad_duration_in_msec:
print(f'Extending last segment to be {timestamp}')
latest_segment['end'] = timestamp
else:
print(f'Adding new segment at {timestamp}')
self.text_shown_segments.append({'start': timestamp, 'end': timestamp})