示例#1
0
def mm(tid, method, interval=1):
    alg = algs[method]

    gw = cg.new_gw()
    trd = cdb.new_track_reader(offset = 0)
    pwd = cdb.new_path_writer_for_method(method = method)
    pt2j = cj.new_pt2geojson(method = method)

    track = trd.fetch_by_id(tid)
    track.sample(interval)
    track.summary()
    pt2j.write_t_geojson(track)

    alg.prepare(gw)

    path = alg.match(gw, track)

    pt2j.write_p_geojson(path)

    # pwd.insert_update(path)

    path.summary()

    del trd,pwd

    return path
示例#2
0
def mm(tid, method, interval=1):
    alg = algs[method]

    gw = cg.new_gw()
    trd = cdb.new_track_reader(offset=0)
    pwd = cdb.new_path_writer_for_method(method=method)
    pt2j = cj.new_pt2geojson(method=method)

    track = trd.fetch_by_id(tid)
    track.sample(interval)
    track.summary()
    pt2j.write_t_geojson(track)

    alg.prepare(gw)

    path = alg.match(gw, track)

    pt2j.write_p_geojson(path)

    # pwd.insert_update(path)

    path.summary()

    del trd, pwd

    return path
示例#3
0
def insert_tracks_attr():
    trd = cdb.new_track_reader()
    if trd is None:
        return

    tawd = cdb.new_track_attr_writer()
    track = trd.fetch_one()
    while track is not None:
        if track.cuid >= from_cuid and track.cuid <= to_cuid:
            print trd.fetched_num, track.tid
            tawd.insert(track)
        track = trd.fetch_one()

    del trd
    del tawd
def insert_tracks_attr():
    trd = cdb.new_track_reader()
    if trd is None:
        return

    tawd = cdb.new_track_attr_writer()
    track = trd.fetch_one()
    while track is not None:
        if track.cuid >= from_cuid and track.cuid <= to_cuid:
            print trd.fetched_num, track.tid
            tawd.insert(track)
        track = trd.fetch_one()
    
    del trd
    del tawd
示例#5
0
def compare():
    gw = cg.new_gw()
    trd = cdb.new_track_reader(offset=0)
    prd = cdb.new_path_reader(gw=gw, tbname="taxi_paths_truth")

    global matched_length, missed_length, false_length

    matched_length = {}
    missed_length = {}
    false_length = {}

    for method in algs.iterkeys():
        matched_length[method] = {}
        missed_length[method] = {}
        false_length[method] = {}
        for interval in intervals:
            matched_length[method][interval] = []
            missed_length[method][interval] = []
            false_length[method][interval] = []

    for method in algs.iterkeys():
        alg = algs[method]
        alg.prepare(gw)
        for tid in tids:
            print method, tid,
            gt_path = prd.fetch_path_by_tid(tid)
            for interval in intervals:
                print interval,
                path = mm(gw, trd, method, tid, interval)
                if path is None:
                    print "failed"
                    continue
                result = path.compare(gt_path)
                matched_length[method][interval].append(
                    result['matched_length'])
                missed_length[method][interval].append(result['missed_length'])
                false_length[method][interval].append(result['false_length'])
            print ""

    for method in algs.iterkeys():
        for interval in intervals:
            print method, interval,
            print sum(matched_length[method][interval]),
            print sum(missed_length[method][interval]),
            print sum(false_length[method][interval])
def compare():
    gw = cg.new_gw()
    trd = cdb.new_track_reader(offset = 0)
    prd = cdb.new_path_reader(gw=gw, tbname="taxi_paths_truth")

    global matched_length, missed_length, false_length

    matched_length = {}
    missed_length  = {}
    false_length   = {}
   
    for method in algs.iterkeys():
        matched_length[method] = {}
        missed_length[method] = {}
        false_length[method] = {}
        for interval in intervals:
            matched_length[method][interval] = []
            missed_length[method][interval] = []
            false_length[method][interval] = []

    for method in algs.iterkeys():
        alg = algs[method]
        alg.prepare(gw)
        for tid in tids:
            print method,tid,
            gt_path = prd.fetch_path_by_tid(tid)
            for interval in intervals:
                print interval,
                path = mm(gw, trd, method, tid, interval)
                if path is None:
                    print "failed"
                    continue
                result = path.compare(gt_path)
                matched_length[method][interval].append(result['matched_length'])
                missed_length[method][interval].append(result['missed_length'])
                false_length[method][interval].append(result['false_length'])
            print ""

    for method in algs.iterkeys():
        for interval in intervals:
            print method,interval,
            print sum(matched_length[method][interval]),
            print sum(missed_length[method][interval]),
            print sum(false_length[method][interval])
def insert_paths_attr():
    gw = cg.new_gw()

    prd = cdb.new_path_reader_for_method(method='bn', gw=gw, limit=10000, offset=0)
    if prd is None:
        return
    trd = cdb.new_track_reader()
    
    pawd = cdb.new_path_attr_writer('taxi_paths_bn_attr')

    path = prd.fetch_one()    
    while path is not None:
        print prd.fetched_num, path.tid
        track = trd.fetch_by_id(path.tid)
        pawd.insert(path, track)
        path = prd.fetch_one()

    del prd
    del pawd
def insert_paths_attr():
    gw = cg.new_gw()

    prd = cdb.new_path_reader_for_method(method='bn',
                                         gw=gw,
                                         limit=10000,
                                         offset=0)
    if prd is None:
        return
    trd = cdb.new_track_reader()

    pawd = cdb.new_path_attr_writer('taxi_paths_bn_attr')

    path = prd.fetch_one()
    while path is not None:
        print prd.fetched_num, path.tid
        track = trd.fetch_by_id(path.tid)
        pawd.insert(path, track)
        path = prd.fetch_one()

    del prd
    del pawd
示例#9
0
 def init_path_track_reader():
     self.prd = cdb.new_path_reader_for_method(method = self.method, offset = 0)
     self.trd = cdb.new_track_reader(offset = 0)