def get_match_score(self, service_matching_props): s = service_matching_props service = get_service_key(service_matching_props) unit = s['gps_car_id'] corrected_error = env.get_corrected_error(s['mean_time_error']) close_match = s['total_matching'] > 8 and \ abs(corrected_error) < 1.0 and \ s['variance_time_error'] < 2.0 # intentionally coerces to int to form buckets total_matching_score = int(s['total_matching'] / 5) error_score = int(abs(corrected_error) / 0.4) matched_over_total = float(s['total_matching']) / self.tracker.get_total_for_service(service) matched_over_total_score = int(matched_over_total / 0.25) # 4 buckets essentially meets_low = s['variance_time_error'] < 3.0 or \ (s['variance_time_error'] < 5.0 and s['total_matching'] < 6) return ( -int(close_match), # descending -int(total_matching_score), # descending int(error_score), # ascending -int(matched_over_total_score), # descending -int(meets_low) # descending )
def is_likely_match(self, service_matching_props): s = service_matching_props service = get_service_key(s) unit = s['gps_car_id'] if self.allocations.was_planned(service, unit): return True interval = s['end'] - s['start'] corrected_error = env.get_corrected_error(s['mean_time_error']) matched_over_total = float(s['total_matching']) / self.tracker.get_total_for_service(service) low_error_if_few_reports = s['total_matching'] > 5 or (s['variance_time_error'] < 2.0 and abs(corrected_error) < 1.0) insignificant = matched_over_total < 0.35 and interval < timedelta(minutes=15) return s['total_matching'] > 2 and \ s['variance_time_error'] < 6.0 and \ abs(corrected_error) < 1.5 and \ low_error_if_few_reports and \ not insignificant