-
Notifications
You must be signed in to change notification settings - Fork 0
/
track_holder.py
153 lines (143 loc) · 4.29 KB
/
track_holder.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from track_object import TrackObject
class TrackHolder:
def __init__(self):
self.confirmed_tracks = []
self.candidate_tracks = []
self.old_tracks = []
track_id_counter = 0
def get_confirmed_tracks(self):
"""
Returns the list of confirmed tracks.
Parameters
----------
None
Returns
-------
list
List of confirmed tracks.
"""
return self.confirmed_tracks
def get_candidate_tracks(self):
"""
Returns the list of candidate tracks.
Parameters
----------
None
Returns
-------
list
List of candidate tracks.
"""
return self.candidate_tracks
def get_all_tracks(self):
"""
Returns the list of all tracks.
Parameters
----------
None
Returns
-------
list
List of all tracks.
"""
return self.confirmed_tracks + self.candidate_tracks
def get_old_tracks(self):
"""
Returns the list of old tracks.
Parameters
----------
None
Returns
-------
list
List of old tracks.
"""
return self.old_tracks
def kill_confirmed_tracks(self):
"""
Removes a track from the list of confirmed tracks.
Parameters
----------
track : TrackObject
Track to be removed.
Returns
-------
None
"""
M = 8
N = 8
for track in self.confirmed_tracks:
mn_vector = track.get_streak_vector()
for i in range(len(mn_vector)):
# Get the last N samples or less if not enough data
window = mn_vector[max(0, i-N+1):i+1]
# Check if the number of 0's in the window is at least M
if window.count(0) >= M:
self.confirmed_tracks.remove(track)
self.old_tracks.append(track)
break
def kill_candidate_tracks(self):
"""
Removes a track from the list of candidate tracks.
Parameters
----------
None
Returns
-------
None
"""
M = 2
N = 2
for track in self.candidate_tracks:
mn_vector = track.get_streak_vector()
for i in range(len(mn_vector)):
# Get the last N samples or less if not enough data
window = mn_vector[max(0, i-N+1):i+1]
# Check if the number of 1's in the window is at least M
if window.count(0) >= M:
self.candidate_tracks.remove(track)
break
# track.set_confirmed(False)
def kill_all_tracks(self):
for track in self.candidate_tracks:
self.candidate_tracks.remove(track)
for track in self.confirmed_tracks:
self.confirmed_tracks.remove(track)
def add_candidate_track(self, track):
"""
Adds a track to the list of candidate tracks.
Parameters
----------
track : TrackObject
Track to be added.
Returns
-------
None
"""
self.candidate_tracks.append(track)
def confirm_candidate_tracks(self):
"""
Confirms a track and adds it to the list of confirmed tracks.
Parameters
----------
None
Returns
-------
None
"""
M = 2
N = 3
for track in self.candidate_tracks:
mn_vector = track.get_streak_vector()
for i in range(len(mn_vector)):
# Get the last N samples or less if not enough data
window = mn_vector[max(0, i-N+1):i+1]
# print(window)
# Check if the number of 1's in the window is at least M
if window.count(1) >= M:
self.confirmed_tracks.append(track)
self.candidate_tracks.remove(track)
# track.set_confirmed(True)
# track.set_track_id(self.track_id_counter)
# self.track_id_counter = self.track_id_counter + 1
break