MCPcopy Create free account
hub / github.com/ChristopherLu/milliEgo / associate

Function associate

eval/associate.py:72–104  ·  view source on GitHub ↗

Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aim to find the closest match for every input tuple. Input: first_list -- first dictionary of (stamp,data) tuples second_list -- second dictionary of (stamp,data) tuples offset -- time of

(first_list, second_list, offset, max_difference)

Source from the content-addressed store, hash-verified

70
71
72def associate(first_list, second_list, offset, max_difference):
73 """
74 Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aim
75 to find the closest match for every input tuple.
76
77 Input:
78 first_list -- first dictionary of (stamp,data) tuples
79 second_list -- second dictionary of (stamp,data) tuples
80 offset -- time offset between both dictionaries (e.g., to model the delay between the sensors)
81 max_difference -- search radius for candidate generation
82
83 Output:
84 matches -- list of matched tuples ((stamp1,data1),(stamp2,data2))
85
86 """
87 # first_keys = first_list.keys()
88 # second_keys = second_list.keys()
89 first_keys = list(first_list)
90 second_keys = list(second_list)
91 potential_matches = [(abs(a - (b + offset)), a, b)
92 for a in first_keys
93 for b in second_keys
94 if abs(a - (b + offset)) < max_difference]
95 potential_matches.sort()
96 matches = []
97 for diff, a, b in potential_matches:
98 if a in first_keys and b in second_keys:
99 first_keys.remove(a)
100 second_keys.remove(b)
101 matches.append((int(a), int(b)))
102
103 matches.sort()
104 return matches
105
106
107if __name__ == '__main__':

Callers 1

associate.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected