Ejemplo n.º 1
0
    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
        )
Ejemplo n.º 2
0
    def match_trust(self, trust):

        tiploc = trust['tiploc']
        time = trust['event_time']

        service = get_service_key(trust)
        self.tracker.seen_service(service)

        self.trust_cache.add(tiploc, time, trust)

        close_gps_reports = self.gps_cache.get_within(
                                   tiploc, time, env.within_minutes)

        for gps in close_gps_reports:
            self.queue.add(trust, gps)
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def from_service_matching(service_matching):

    matching = service_matching.as_dict()

    service = get_service_key(matching)
    gps_car_id = matching['gps_car_id']

    trust_reports = get_trust_reports(service, start=matching['start'], end=matching['end'])
    gps_reports = get_gps_reports(gps_car_id, start=matching['start'], end=matching['end'])

    return get_segment_template(
        headcode=matching['headcode'],
        origin_location=matching['origin_location'],
        origin_departure=matching['origin_departure'],
        gps_car_id=gps_car_id,
        trust=trust_reports,
        gps=gps_reports,
        start=matching['start'],
        end=matching['end'],
        total_matching=matching['total_matching'],
        mean_time_error=matching['mean_time_error'],
        variance_time_error=matching['variance_time_error'])
Ejemplo n.º 5
0
 def add(self, trust, gps):
     service = get_service_key(trust)
     unit = gps['gps_car_id']
     key = service + (unit,)
     event_matching = self.__get_event_matching_props(trust, gps)
     self.event_matchings[key].append(event_matching)