コード例 #1
0
ファイル: filter_gps.py プロジェクト: ucl-team-8/service
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
コード例 #2
0
ファイル: globals.py プロジェクト: ucl-team-8/service
def createNewSegment(report):
    segment = Segment()
    if 'planned_pass' in report.keys():  # Trust has planned pass
        segment.trust(report)
    else:
        segment.gps(report)
    segments[segment.id] = segment
    socket_io.emitSegment('new', segment)
コード例 #3
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
def deleteReports(segment):
    segment.matching = filter(lambda x: not x['delete'],
        segment.matching[-globals.backmatches:]) + segment.matching[:-globals.backmatches]
    if len(segment.matching) == 0:
        socket_io.emitSegment('delete', segment.id)
        del globals.segments[segment.id]
    else:
        socket_io.emitSegment('update', segment)
コード例 #4
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
def combineSegments(segments, i, j):
    for k in range(i + 1, j + 1):
        if segments[k].gps_car_id != segments[i].gps_car_id:
            removeGPSReports(segments[k], segments[i].gps_car_id)
        segments[i].matching.extend(segments[k].matching)
        segments[k].remove = True
    segments[i].matching.sort(key=lambda x: getReportTime(x), reverse=False)
    socket_io.emitSegment('update', segments[i])
コード例 #5
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
def checkPotentialMatches(segment, potential_matches):
    if len(potential_matches) > globals.min_matching:
        globals.lock.acquire()
        segment.headcode = potential_matches[0]['trust']['headcode']
        segment.cif_uid = db_queries.cif_uidFromHeadcode(segment.headcode)
        segment.origin_location = potential_matches[0]['trust']['origin_location']
        segment.origin_departure = potential_matches[0]['trust']['origin_departure']
        for match in potential_matches:
            segment.matching[match['index']]['trust'] = match['trust']
        socket_io.emitSegment('update', segment)
        globals.lock.release()
コード例 #6
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
def checkPotentialMatches(segment, potential_matches):
    if len(potential_matches) > globals.min_matching:
        globals.lock.acquire()
        segment.headcode = potential_matches[0]["trust"]["headcode"]
        segment.cif_uid = db_queries.cif_uidFromHeadcode(segment.headcode)
        segment.origin_location = potential_matches[0]["trust"]["origin_location"]
        segment.origin_departure = potential_matches[0]["trust"]["origin_departure"]
        for match in potential_matches:
            segment.matching[match["index"]]["trust"] = match["trust"]
        socket_io.emitSegment("update", segment)
        globals.lock.release()
コード例 #7
0
ファイル: filter_trust.py プロジェクト: ucl-team-8/service
def findEmptySegment(segments1, trust):
    segments = filter(lambda x: x['segment'].gps_car_id is None, segments1)
    if len(segments) > 0:
        segments.sort(key=lambda x: isBetterSegment(x), reverse=True)
        segment = segments[0]['segment']
        segment.matching.append({
            'dist_error': None,
            'gps': None,
            'trust': trust
        })
        socket_io.emitSegment('update', segment)
        return True
    return False
コード例 #8
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
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)
コード例 #9
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
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)
コード例 #10
0
ファイル: filter_gps.py プロジェクト: ucl-team-8/service
def addGPS(gps_report):
    if gps_report is None:
        return
    globals.lock.acquire()
    segment = findClosestSegment(globals.segments, gps_report)
    if segment is None:
        globals.createNewSegment(gps_report)
    elif not checkNonMatchingTrust(segment, gps_report):
        segment = findClosestGPSSegment(globals.segments, gps_report)
        if segment is None:
            globals.createNewSegment(gps_report)
        else:
            segment.matching.append({
                'gps': gps_report,
                'trust': None,
                'dist_error': None
            })
            socket_io.emitSegment('update', segment)
    globals.lock.release()
コード例 #11
0
ファイル: filter_trust.py プロジェクト: ucl-team-8/service
def getBestStop(segments1, trust, with_seq):
    segments = filter(lambda x: x['segment'].gps_car_id is not None, segments1)
    segments.sort(key=lambda x: isBetterSegment(x), reverse=True)
    for segment1 in segments:
        segment = segment1['segment']
        segment.matching.sort(key=lambda x: getTimeForMatching(x), reverse=True)
        matching = segment.matching[0: globals.backmatches]
        best = getBestStopHelper(matching, trust, True)
        if best is not None:
            best['match']['trust'] = trust
            best['match']['dist_error'] = best['dist_error']
            if segment.headcode is None:
                segment.headcode = trust['headcode']
                segment.cif_uid = db_queries.cif_uidFromHeadcode(trust['headcode'])
                segment.isPlanned = db_queries.isPlanned(segment.gps_car_id, trust['headcode'])
                segment.origin_location = trust['origin_location']
                segment.origin_departure = trust['origin_departure']
            socket_io.emitSegment('update', segment)
            return True
    return False
コード例 #12
0
ファイル: interpolating.py プロジェクト: ucl-team-8/service
def removeSegments():
    for key, segment in globals.segments.items():
        if segment.remove:
            socket_io.emitSegment('delete', key)
            del globals.segments[key]