Пример #1
0
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
Пример #2
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': ''}}]}):
        data_feature[section['_id']] = getRoute(section['_id'])

    return data_feature
Пример #3
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
Пример #4
0
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
Пример #5
0
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 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] = getRoute(_id)
        except Exception as e:
            pass
    #print(data_feature.keys())
    return data_feature
Пример #7
0
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 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] = getRoute(_id)
        except Exception as e:
            pass
    #print(data_feature.keys())
    return data_feature
Пример #9
0
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
Пример #10
0
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 get_ground_truth_sections(username, section_collection):
    """
    Returns all of the routes associated with a username's ground truthed sections
    """
    ground_cluster_collection = get_groundClusters_db()
    clusters = ground_cluster_collection.find_one({"clusters":{"$exists":True}})["clusters"]
    ground_truth_sections = []
    get_username = lambda x: x[0].split("_")[0]
    clusters = filter(lambda x: username == get_username(x), clusters.items())
    for key, section_ids in clusters:
        ground_truth_sections.extend(section_ids)
 
    ground_truth_section_data = {}
    for section_id in ground_truth_sections:
        section_data = section_collection.find_one({'_id' : section_id})        
        if section_data is not None:
            ground_truth_section_data[section_data['_id']] = getRoute(section_data['_id'])
        else:
            print("%s not found" % section_id)
    return ground_truth_section_data
def get_ground_truth_sections(username, section_collection):
    """
    Returns all of the routes associated with a username's ground truthed sections
    """
    ground_cluster_collection = get_groundClusters_db()
    clusters = ground_cluster_collection.find_one(
        {"clusters": {
            "$exists": True
        }})["clusters"]
    ground_truth_sections = []
    get_username = lambda x: x[0].split("_")[0]
    clusters = filter(lambda x: username == get_username(x), clusters.items())
    for key, section_ids in clusters:
        ground_truth_sections.extend(section_ids)

    ground_truth_section_data = {}
    for section_id in ground_truth_sections:
        section_data = section_collection.find_one({'_id': section_id})
        if section_data is not None:
            ground_truth_section_data[section_data['_id']] = getRoute(
                section_data['_id'])
        else:
            print("%s not found" % section_id)
    return ground_truth_section_data