-
Notifications
You must be signed in to change notification settings - Fork 129
/
basicmetrics.py
59 lines (47 loc) · 1.84 KB
/
basicmetrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
from .base import MetricGenerator
from ..types.metric import TimeRangeMetric
from ..types.time import TimeRange
class BasicMetrics(MetricGenerator):
"""Calculates simple metrics like number of tracks, truth and
ratio of track-to-truth"""
def compute_metric(self, manager, *args, **kwargs):
"""Compute the metric using the data in the metric manager
Parameters
----------
manager : MetricManager
containing the data to be used to create the metric(s)
Returns
----------
: list of :class:`~.Metric`
Contains the metric information
"""
metrics = []
# Make a list of all the unique timestamps used
timestamps = {state.timestamp for state in manager.tracks}
timestamps |= {state.timestamp
for path in manager.groundtruth_paths
for state in path}
# Number of tracks
metrics.append(TimeRangeMetric(
title='Number of targets',
value=len(manager.groundtruth_paths),
time_range=TimeRange(
start_timestamp=min(timestamps),
end_timestamp=max(timestamps)),
generator=self))
metrics.append(TimeRangeMetric(
title='Number of tracks',
value=len(manager.tracks),
time_range=TimeRange(
start_timestamp=min(timestamps),
end_timestamp=max(timestamps)),
generator=self))
metrics.append(TimeRangeMetric(
title='Track-to-target ratio',
value=len(manager.tracks) / len(manager.groundtruth_paths),
time_range=TimeRange(
start_timestamp=min(timestamps),
end_timestamp=max(timestamps)),
generator=self))
return metrics