def checkNonMatchingTrust(segment, gps_report): closest = { 'match': None, 'time_error': datetime.timedelta(days=1), 'dist_error': 1000000 } for match in segment.matching: if (match['trust'] is not None) and (match['gps'] is None): time_error = abs( match['trust']['event_time'] - gps_report['event_time']) dist_error = geo_distance.calculateDistance( match['trust']['tiploc'], gps_report['tiploc'] ) if dist_error < globals.tolerance['distance']\ and time_error < globals.tolerance['time']: if dist_error < closest['dist_error'] and\ time_error < closest['time_error']: closest['match'] = match closest['dist_error'] = dist_error closest['time_error'] = time_error if closest['match'] is not None: closest['match']['gps'] = gps_report closest['match']['dist_error'] = dist_error if segment.gps_car_id is None: segment.gps_car_id = gps_report['gps_car_id'] segment.isPlanned = db_queries.isPlanned(segment.gps_car_id, segment.headcode) socket_io.emitSegment('update', segment) return True return False
def getBestStopHelper(matching, trust, with_seq): best = { 'match': None, 'time_error': datetime.timedelta(days=1), 'dist_error': 1000000 # km } last_seq = 0 for match in matching: if(match['gps'] is not None) and\ (match['trust'] is None): dist_error = geo_distance.calculateDistance( match['gps']['tiploc'], trust['tiploc']) time_error = abs(match['gps']['event_time'] - trust['event_time']) if(dist_error < globals.tolerance['distance']) and\ (time_error < globals.tolerance['time']): if(dist_error < best['dist_error']) and\ (time_error < best['time_error']): if with_seq and (trust['seq'] > last_seq): setBestStop(best, dist_error, time_error, match) elif not with_seq: setBestStop(best, dist_error, time_error, match) elif match['trust'] is not None: last_seq = match['trust']['seq'] if best['match'] is not None: return best elif with_seq: return getBestStopHelper(matching, trust, False) return None
def isMatching(gps, trust): time_error = abs(gps["event_time"] - trust["event_time"]) if time_error < globals.tolerance["time"]: dist_error = geo_distance.calculateDistance(gps["tiploc"], trust["tiploc"]) if dist_error < globals.tolerance["distance"]: return True return False
def isMatching(gps, trust): time_error = abs(gps['event_time'] - trust['event_time']) if time_error < globals.tolerance['time']: dist_error = geo_distance.calculateDistance( gps['tiploc'], trust['tiploc']) if dist_error < globals.tolerance['distance']: return True return False
def checkEmptyMatches(segment, empty_segment, potential_matches): if len(potential_matches) > globals.min_matching: for i, match in enumerate(potential_matches): if "index" in match: # It can match to a gps dist_error = geo_distance.calculateDistance( match["trust"]["tiploc"], segment.matching[match["index"]]["gps"]["tiploc"] ) segment.matching[match["index"]]["trust"] = match["trust"] segment.matching[match["index"]]["dist_error"] = dist_error del potential_matches[i] for match in potential_matches: segment.matching.append({"dist_err": None, "gps": None, "trust": match["trust"]}) socket_io.emitSegment("update", segment) deleteReports(empty_segment)
def checkEmptyMatches(segment, empty_segment, potential_matches): if len(potential_matches) > globals.min_matching: for i, match in enumerate(potential_matches): if 'index' in match: # It can match to a gps dist_error = geo_distance.calculateDistance( match['trust']['tiploc'], segment.matching[match['index']]['gps']['tiploc']) segment.matching[match['index']]['trust'] = match['trust'] segment.matching[match['index']]['dist_error'] = dist_error del potential_matches[i] for match in potential_matches: segment.matching.append({ 'dist_err': None, 'gps': None, 'trust': match['trust'] }) socket_io.emitSegment('update', segment) deleteReports(empty_segment)
def filterPotentialSegments(segments, trust): potential_segments = [] for segment in segments: for i in range(0, len(segment.matching)): try: if (segment.matching[i]['gps'] is not None) and\ (segment.matching[i]['trust'] is None): time_error = abs( segment.matching[i]['gps']['event_time'] - trust['event_time']) if time_error < globals.tolerance['time']: dist_error = geo_distance.calculateDistance( segment.matching[i]['gps']['tiploc'], trust['tiploc']) if dist_error < globals.tolerance['distance']: potential_segments.append(segment) break except: pass # Do nothing if len(potential_segments) == 0: return segments return potential_segments
def test_calculate_distance(self): result = geo_distance.calculateDistance('BEAULY', 'ABCWM') self.assertLess(result - 647.259510348751, tolerance)