Spaces:
Configuration error
Configuration error
| import time | |
| from collections import defaultdict | |
| class MetricsAggregator: | |
| def __init__(self, fps=25.0): | |
| self.fps = fps | |
| self.per_id = defaultdict(lambda: { | |
| 'frames_present': 0, | |
| 'frames_in_corridor': 0, | |
| 'frames_on_phone': 0, | |
| 'frames_chatting': 0, | |
| }) | |
| def step(self, tracks, in_corridor_ids, phone_ids, chatting_ids): | |
| for tid in tracks.keys(): | |
| self.per_id[tid]['frames_present'] += 1 | |
| if tid in in_corridor_ids: | |
| self.per_id[tid]['frames_in_corridor'] += 1 | |
| if tid in phone_ids: | |
| self.per_id[tid]['frames_on_phone'] += 1 | |
| if tid in chatting_ids: | |
| self.per_id[tid]['frames_chatting'] += 1 | |
| def summarize_minutes(self): | |
| out = {} | |
| for tid, m in self.per_id.items(): | |
| out[tid] = { | |
| 'present_min': round(m['frames_present'] / self.fps / 60.0, 2), | |
| 'corridor_min': round(m['frames_in_corridor'] / self.fps / 60.0, 2), | |
| 'phone_min': round(m['frames_on_phone'] / self.fps / 60.0, 2), | |
| 'chat_min': round(m['frames_chatting'] / self.fps / 60.0, 2), | |
| } | |
| return out | |