示例#1
0
文件: analysis.py 项目: xlees/TgsVis
def stat_tgs_volume(cid, stime,etime):
    tbl = "tr_bay_jun"

    b_cid = shd.byte_cid(cid)
    begtime = long(time.mktime(stime.timetuple())*1000)
    endtime = long(time.mktime(etime.timetuple())*1000)

    (client,trpt) = shd.get_thrift_client(host,port)

    trpt.open()

    scan = htt.TScan()
    scan.columns = ['cf:']
    scan.caching = 110
    # scan.filterString = "RowFilter(=, 'substring:%s') AND KeyOnlyFilter()" % (numb)
    scan.filterString = "KeyOnlyFilter()"
    scan.startRow = struct.pack(">2sQ", b_cid, begtime)
    scan.stopRow = struct.pack(">2sQ", b_cid, endtime)

    scanner = client.scannerOpenWithScan(tbl,scan,None)

    n_records = 0
    while 1:
        dataset = client.scannerGetList(scanner,shd.buf_max_size)
        n_records += len(dataset)

        if len(dataset) < shd.buf_max_size:
            break

        del dataset[:]

    trpt.close()

    return n_records
示例#2
0
文件: analysis.py 项目: xlees/TgsVis
def query_vehicle_trajetory(numb,ptype,stime,etime):
    tbl = "tr_plate_jun"

    begtime = long(time.mktime(stime.timetuple())*1000)
    endtime = long(time.mktime(etime.timetuple())*1000)

    (client,trpt) = shd.get_thrift_client(host,port)

    trpt.open()

    scan = htt.TScan()
    scan.columns = ['cf:']
    scan.caching = 110
    # scan.filterString = "RowFilter(=, 'substring:%s') AND KeyOnlyFilter()" % (numb)
    # scan.filterString = "KeyOnlyFilter()"
    scan.startRow = struct.pack(">10sQ", numb, begtime)
    scan.stopRow = struct.pack(">10sQ", numb, endtime)

    scanner = client.scannerOpenWithScan(tbl,scan,None)

    traj = []
    while 1:
        dataset = client.scannerGetList(scanner,shd.buf_max_size)
        for elem in dataset:
            numb_type = struct.unpack("B",elem.columns['cf:'].value[35:36])[0]
            if numb_type != int(ptype):
                continue

            passtime = datetime.fromtimestamp(struct.unpack(">Q",elem.row[10:18])[0]/1000.0).strftime("%Y-%m-%d %H:%M:%S")
            cid = shd.unbyte_cid(elem.row[18:20])
            drivedir = struct.unpack("B",elem.columns['cf:'].value[37:38])[0]

            traj.append((passtime,cid,drivedir))

        if len(dataset) < shd.buf_max_size:
            break

    trpt.close()

    return traj
示例#3
0
文件: analysis.py 项目: xlees/TgsVis
def query_traj(stime,etime, numb):
    tbl = 'tr_plate_jun'

    (client,trpt) = shd.get_thrift_client(host,port)

    begtime = long(time.mktime(stime.timetuple())*1000)
    endtime = long(time.mktime(etime.timetuple())*1000)

    scan = htt.TScan()
    scan.columns = ['cf:']
    scan.caching = 110
    # scan.filterString = "RowFilter(=, 'substring:%s') AND KeyOnlyFilter()" % (numb)
    scan.filterString = "KeyOnlyFilter()"
    scan.startRow = struct.pack(">10sQ", numb, begtime)
    scan.stopRow = struct.pack(">10sQ", numb, endtime)

    trpt.open()

    scanner = client.scannerOpenWithScan(tbl, scan, None)

    result = []
    while 1:
        dataset = client.scannerGetList(scanner, buf_max_size)

        for elem in dataset:
            result.append({
                'passtime': datetime.fromtimestamp(struct.unpack('>Q',elem.row[10:18])[0]/1000.0).strftime('%Y-%m-%d %H:%M:%S'),
                'cid': unbyte_cid(elem.row[18:20]),
            })

        if len(dataset) < buf_max_size:
            break

    trpt.close()

    result.sort(key=lambda x: x['passtime'],reverse=False)

    print 'traj: %d records fetched.' % (len(result))

    return result