def cluster_route_match_score(segment,step1=100000,step2=100000,method='lcs',radius1=2000,threshold=0.5):
    userRouteClusters=get_routeCluster_db().find_one({'$and':[{'user':segment['user_id']},{'method':method}]})['clusters']
    route_seg = getRoute(segment['_id'])

    dis=999999
    medoid_ids=userRouteClusters.keys()
    if len(medoid_ids)!=0:
        choice=medoid_ids[0]
        for idx in userRouteClusters.keys():
            route_idx=getRoute(idx)
            try:
                dis_new=fullMatchDistance(route_seg,route_idx,step1,step2,method,radius1)
            except RuntimeError:

                dis_new=999999
            if dis_new<dis:
                dis=dis_new
                choice=idx
    # print(dis)
    # print(userRouteClusters[choice])
    if dis<=threshold:
        cluster=userRouteClusters[choice]
        cluster.append(choice)
        ModePerc=get_mode_share_by_count(cluster)
    else:
        ModePerc=get_mode_share_by_count([])

    return ModePerc
def user_route_data(user_id, database):
    data_feature = {}

    # for section in database.find({'$and':[{'user_id': user_id},{'type': 'move'},{'confirmed_mode': {'$ne': ''}}]}):
    for section in database.find({'$and':[{'user_id': user_id},{'type': 'move'}]}):
        data_feature[section['_id']] = getRoute(section['_id'])
    #print(data_feature.keys())
    return data_feature
def transit_stop_match_score(segment,radius1=300):
    Transits=get_transit_db()
    transitMatch={}
    route_seg=getRoute(segment['_id'])
    for type in Transits.distinct('type'):
        for entry in Transits.find({'type':type}):
            transitMatch[type]=matchTransitStops(route_seg,entry['stops'],radius1)
            if transitMatch[entry['type']]==1:
                break
    return transitMatch
def transit_route_match_score(segment,step1=100000,step2=100000,method='lcs',radius1=2500,threshold=0.5):
    Transits=get_transit_db()
    transitMatch={}
    route_seg=getRoute(segment['_id'])
    for type in Transits.distinct('type'):
        for entry in Transits.find({'type':type}):
            transitMatch[type]=matchTransitRoutes(route_seg,entry['stops'],step1,step2,method,radius1,threshold)
            if transitMatch[entry['type']]==1:
                break
    return transitMatch
def transit_stop_match_score(segment, radius1=300):
    Transits = get_transit_db()
    transitMatch = {}
    route_seg = getRoute(segment["_id"])
    for type in Transits.distinct("type"):
        for entry in Transits.find({"type": type}):
            transitMatch[type] = matchTransitStops(route_seg, entry["stops"], radius1)
            if transitMatch[entry["type"]] == 1:
                break
    return transitMatch
def transit_route_match_score(segment, step1=100000, step2=100000, method="lcs", radius1=2500, threshold=0.5):
    Transits = get_transit_db()
    transitMatch = {}
    route_seg = getRoute(segment["_id"])
    for type in Transits.distinct("type"):
        for entry in Transits.find({"type": type}):
            transitMatch[type] = matchTransitRoutes(route_seg, entry["stops"], step1, step2, method, radius1, threshold)
            if transitMatch[entry["type"]] == 1:
                break
    return transitMatch
Exemple #7
0
def user_route_data2(section_ids):
    data_feature = {}

    # for section in database.find({'$and':[{'user_id': user_id},{'type': 'move'},{'confirmed_mode': {'$ne': ''}}]}):
    for _id in section_ids:
        try:
            data_feature[_id] = eart.getRoute(_id)
        except Exception as e:
            pass
    #print(data_feature.keys())
    return data_feature
def user_route_data2(section_ids):
    data_feature = {}

    # for section in database.find({'$and':[{'user_id': user_id},{'type': 'move'},{'confirmed_mode': {'$ne': ''}}]}):
    for _id in section_ids:
        try:
            data_feature[_id] = eart.getRoute(_id)
        except Exception as e:
            pass
    #print(data_feature.keys())
    return data_feature
Exemple #9
0
def user_route_data(user_id, database):
    data_feature = {}

    # for section in database.find({'$and':[{'user_id': user_id},{'type': 'move'},{'confirmed_mode': {'$ne': ''}}]}):
    for section in database.find(
        {'$and': [{
            'user_id': user_id
        }, {
            'type': 'move'
        }]}):
        data_feature[section['_id']] = getRoute(section['_id'])
    #print(data_feature.keys())
    return data_feature