Esempio n. 1
0
# -*- coding: utf-8 -*-
__author__ = 'lenovo'

from util.tripFlow.base import getFormatGID
from util.tripFlow.base import getDirection
from util.tripFlow.extractGridEdges import ExtractGridEdges

tPoint = [161.12, 40.35]
fPoint = [161.57, 39.79]

PROP = {
    'index': 9,
    'delta': -1,
    'IDIRECTORY': '/datahouse',
    'ODIRECTORY': '/datahouse',
    'suffix': 1
}
task = ExtractGridEdges(PROP)
direction = getDirection(fPoint, tPoint)
fromGid = getFormatGID(fPoint)['gid']
toGid = getFormatGID(tPoint)['gid']
print(direction)
speed = 2.3
task.updateResByLine(fPoint, tPoint, fromGid, toGid, direction, speed)

print(task.resByCate['from'])
print(task.resByCate['to'])

#证明from和to的方向是一样的
Esempio n. 2
0
def processTask(x, eps, K, delta, stdindir, stdoutdir): 
	subfix = "%.2f" % (delta)
	PROP = {
		'index': x, 
		'delta': delta,
		'IDIRECTORY': stdindir, 
		'ODIRECTORY': stdoutdir,
		'subfix': subfix
	}
	task = ExtractGridEdges(PROP)
	res = task.run()
	
	count = res['count']
	min_samples = int(count / K) if count > K else 1

	resByDir = res['res']['resByDir']
	resByCate = res['res']['resByCate']
	dataType = 'angle'  # 确定是按照方向聚类还是角度聚�?direction, category
	EPS_INTERVAL = 0.001 if dataType == 'direction' else 0.4

	clusterofilename = ''
	iterationTimes = 0

	while (True):
		if (iterationTimes == 50):
			eps -= EPS_INTERVAL*50
			min_samples -= 5
			iterationTimes = 0
		
		clusterPROP = {
			'index': x, 
			'ODIRECTORY': stdoutdir,
			'resByDir': resByDir,
			'resByCate': resByCate,
			'resByAng': resByCate,
			'dataType': dataType,
			'eps': eps,
			'min_samples': min_samples,
			'subfix': subfix
		}
		print '''
===	Cluster Parameters	===
index	= %d
stdindir	= %s
stdoutdir	= %s
eps		= %f
min_samples	= %d
===	Cluster Parameters	===
''' % (x, stdindir, stdoutdir, eps, min_samples)

		# 角度聚类单独处理
		if dataType == 'angle':
			clusterTask = LineTFIntersections(clusterPROP)
			noiseRate, clusterofilename = clusterTask.run()
			break

		clusterTask = DBScanTFIntersections(clusterPROP)
		noiseRate, clusterofilename = clusterTask.run()

		if noiseRate <= 0.5:
			break
		else:
			eps += EPS_INTERVAL
			iterationTimes += 1

	mergePROP = {
		'index': x, 
		'IDIRECTORY': stdindir, 
		'ODIRECTORY': stdoutdir,
		'dataType': dataType,
		'subfix': subfix
	}
	mergeTask = MergeClusterEdges(mergePROP)
	mergeTask.run()
def processTask(x, eps, K, delta, stdindir, stdoutdir, locs, city, LngSPLIT,
                LatSPLIT):
    suffix = "%.2f" % (delta)
    PROP = {
        'index': x,
        'delta': delta,
        'IDIRECTORY': stdindir,
        'ODIRECTORY': stdoutdir,
        'suffix': suffix,
        'locs': locs,
        'city': city,
        'LngSPLIT': LngSPLIT,
        'LatSPLIT': LatSPLIT
    }

    extractionStartTime = time.time()

    task = ExtractGridEdges(PROP)
    res = task.run()

    extractionEndTime = time.time()
    print "Extraction seconds: %f" % (extractionEndTime - extractionStartTime)

    count = res['count']
    #min_samples = int(count / K) if count > K else 1
    min_samples = 2

    resByDir = res['res']['resByDir']
    resByCate = res['res']['resByCate']
    dataType = 'angle'  # 确定是按照方向聚类还是角度聚�?direction, category
    #EPS_INTERVAL = 0.001 if dataType == 'direction' else 0.4
    EPS_INTERVAL = 0.001 if dataType == 'direction' else 0.4

    iterationTimes = 0

    while (True):
        if (iterationTimes == 50):
            eps -= EPS_INTERVAL * 50
            min_samples -= 5
            iterationTimes = 0

        clusterPROP = {
            'index': x,
            'ODIRECTORY': stdoutdir,
            'resByDir': resByDir,
            'resByCate': resByCate,
            'resByAng': resByCate,
            'dataType': dataType,
            'eps': eps,
            'min_samples': min_samples,
            'suffix': suffix,
            'locs': locs,
            'city': city,
            'LngSPLIT': LngSPLIT,
            'LatSPLIT': LatSPLIT
        }
        print '''
===	Cluster Parameters	===
index	= %d
stdindir	= %s
stdoutdir	= %s
eps		= %f
min_samples	= %d
===	Cluster Parameters	===
''' % (x, stdindir, stdoutdir, eps, min_samples)

        # 角度聚类单独处理
        if dataType == 'angle':

            clusteringStartTime = time.time()

            clusterTask = LineTFIntersections(clusterPROP)
            noiseRate, clusterofilename = clusterTask.run()

            clusteringEndTime = time.time()
            print "Clustering seconds: %f" % (clusteringEndTime -
                                              clusteringStartTime)
            break

        clusterTask = DBScanTFIntersections(clusterPROP)
        noiseRate, clusterofilename = clusterTask.run()

        if noiseRate <= 0.5:
            print(iterationTimes)
            break
        else:
            eps += EPS_INTERVAL
            iterationTimes += 1

    mergePROP = {
        'index': x,
        'IDIRECTORY': stdindir,
        'ODIRECTORY': stdoutdir,
        'dataType': dataType,
        'suffix': suffix,
        'city': city
    }
    mergeTask = MergeClusterEdges(mergePROP)
    mergeTask.run()