예제 #1
0
def testScenario(schemaPath, query, aqRate, deliveryTime, numNodes, outputPath,
                 sneeqlNetFile):

    report(
        "\n\n*********************************************************************\n"
    )
    report(
        "Testing scenario:\nquery=%s\nschema=%s\naqRate=%d\nnumNodes=%d\noutputPath=%s\n"
        % (query, schemaPath, aqRate, numNodes, outputPath))

    #Q3temp, QNest3temp and Q4temp only: Set the fromWindow parameter depending on the acquisiton rate
    if (query == "Q3temp"):
        adjustQ3temp(aqRate)

    #query optimizer parameters
    coreParams = [
        "-nesc-control-radio-off=true", "-nesc-adjust-radio-power=false",
        "-nesc-power-management=true", "-display-graphs=false",
        "-qos-aware-partitioning=false", "-qos-aware-routing=false",
        "-qos-aware-where-scheduling=false",
        "-qos-aware-when-scheduling=false", "-sinks=0",
        "-network-topology-file=" + UtilLib.winpath(sneeqlNetFile),
        "-targets=avrora1",
        "-site-resource-file=input/mica2-site-resources.xml",
        "-display-sensornet-link-properties=true"
    ]

    scenarioParams = [
        "-schema-file=" + UtilLib.winpath(schemaPath),
        "-query=input/Pipes/" + query + ".txt",
        "-qos-acquisition-interval=%d" % (aqRate),
        "-output-root-dir=" + UtilLib.winpath(outputPath)
    ]

    if deliveryTime != None:
        scenarioParams += ["-qos-max-delivery-time=" + str(deliveryTime)]
        scenarioParams += ["-qos-max-buffering-factor=6"
                           ]  #set to 30 to make 30 node networks faster...
    else:
        scenarioParams += ["-qos-max-buffering-factor=1"]

    #compile the query for using the SNEEql optimizer
    queryCompilerParams = coreParams + scenarioParams
    exitVal = SneeqlLib.compileQueryParamStr(queryCompilerParams, query)
    if (exitVal != 0):
        return

    queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % (
        outputPath, query)
    actualBFactor = SneeqlLib.getBufferingFactor(queryPlanSummaryFile)
    simDuration = (aqRate * actualBFactor) / 1000.0

    report("\nAvrora simulation\n=================\n")
    nescDir = "%s/%s/avrora1" % (outputPath, query)
    testAvroraCandidate(nescDir, query, outputPath, numNodes, simDuration,
                        schemaPath, aqRate, deliveryTime, actualBFactor)
예제 #2
0
def plotScatterdiagrams(deltaGraph, epsilonGraph, lambdaGraph, outputDir):
    resultFilename = "%s/delta.eps" % (outputDir)
    deltaCorrelCoeff = deltaGraph.getCorrelCoeff()
    xLabel = "Obj function value\\n\\nSweet spot = SE quadrant, correlation coefficient = " + str(
        deltaCorrelCoeff) + "\\n"
    yLabel = "Measured value"
    title = "Where-scheduling Delivery Time Objective Function Value vs. Minimum Delivery Time Possible"
    deltaGraph.drawScatterDiagram(resultFilename,
                                  xLabel,
                                  yLabel,
                                  title,
                                  labelPoints=False,
                                  xZeroToOne=False)
    print("The delta correlation coefficient is " + str(deltaCorrelCoeff))

    os.system('epstopdf  ' + UtilLib.winpath(resultFilename))
    os.system('rm ' + resultFilename)

    resultFilename = "%s/epsilon.eps" % (outputDir)
    epsilonCorrelCoeff = epsilonGraph.getCorrelCoeff()
    xLabel = "Obj function value\\n\\nSweet spot = SE quadrant, correlation coefficient = " + str(
        epsilonCorrelCoeff) + "\\n"
    yLabel = "Measured value (J)"
    title = "Where-scheduling Total Energy Objective Function Value vs. Simulated Total Energy"
    epsilonGraph.drawScatterDiagram(resultFilename,
                                    xLabel,
                                    yLabel,
                                    title,
                                    labelPoints=False,
                                    xZeroToOne=False)
    print("The epsilon correlation coefficient is " + str(epsilonCorrelCoeff))

    os.system('epstopdf  ' + UtilLib.winpath(resultFilename))
    os.system('rm ' + resultFilename)

    resultFilename = "%s/lambda.eps" % (outputDir)
    lambdaCorrelCoeff = lambdaGraph.getCorrelCoeff()
    xLabel = "Objective function value\\n\\nSweet spot = NE quadrant, correlation coefficient = " + str(
        lambdaCorrelCoeff) + "\\n"
    yLabel = "Measured value (days)"
    title = "Where-scheduling Lifetime Objective Function Value vs. Simulated Lifetime"
    lambdaGraph.drawScatterDiagram(resultFilename,
                                   xLabel,
                                   yLabel,
                                   title,
                                   labelPoints=False,
                                   xZeroToOne=False)
    print("The lambda correlation coefficient is " + str(lambdaCorrelCoeff))

    os.system('epstopdf  ' + UtilLib.winpath(resultFilename))
    os.system('rm ' + resultFilename)

    return (deltaCorrelCoeff, epsilonCorrelCoeff, lambdaCorrelCoeff)
예제 #3
0
    def drawNetworkGeometry(self, outputFilename):

        #first generate plotFile
        outputDir = os.path.dirname(outputFilename)
        if outputDir == "":
            outputDir = os.getenv("PWD")

        plotFilename = "%s/plot.txt" % (outputDir)
        plotFile = open(plotFilename, 'w')
        plotFile.write("Id \"x\" \"y\"\n")
        for n in self.nodes.keys():
            id = str(self.nodes[n].id)
            x = str(self.nodes[n].xPos)
            y = str(self.nodes[n].yPos)
            plotFile.write("%s %s %s\n" % (id, x, y))
        plotFile.close()

        #now generate script file
        #TODO: unhardcode this
        gnuPlotExe = 'gnuplot'

        scriptStr = """
set term postscript eps font "Times-Bold,24" size 7,3.5
set out '%s'

set style data points
set pointsize 5
set key off
set xtics
set xrange [%d:%d]
set yrange [%d:%d]
set datafile missing '?'
linewidth 3 
plot '%s' using 2:3 ti col linewidth 3
		"""

        scriptStr = scriptStr % (UtilLib.winpath(outputFilename), self.xOrigin,
                                 self.xOrigin + self.xDim, self.yOrigin,
                                 self.yOrigin + self.yDim,
                                 UtilLib.winpath(plotFilename))

        scriptFilename = "%s/gnu-plot-script.txt" % (outputDir)
        scriptFile = scriptFilename
        f = open(scriptFile, 'w')
        f.write(scriptStr)
        f.close()

        report('running: ' + gnuPlotExe + ' < ' + scriptFilename)
        exitVal = os.system(gnuPlotExe + ' < ' + scriptFilename)
        if (exitVal != 0):
            reportWarning('Error during graph plotting')
예제 #4
0
	def get(self):
	
		#language parameter
		languageParam = "en"
		languageParamName = 'lan'
		if (languageParamName in self.request.params):
			languageParam = self.request.params[languageParamName]
	
		userLat = ""
		latParamName = 'lat'
		if (latParamName in self.request.params):
			userLat = self.request.params[latParamName]
	
		userLon = ""
		lonParamName = 'lon'
		if (lonParamName in self.request.params):
			userLon = self.request.params[lonParamName]
	
		#keyword parameter
		queryParam = "pain"
		keywordParameterName = 'keyword'
		if (keywordParameterName in self.request.params):
			queryParam = self.request.params[keywordParameterName]
	
		#zip parameter
		zipParam = ""
		zipParameterName = 'zip'
		if (zipParameterName in self.request.params):
			zipParam = self.request.params[zipParameterName]
		
		#type parameter
		typeParam = ""
		typeParameterName = 'type'
		if (typeParameterName in self.request.params):
			typeParam = self.request.params[typeParameterName]
	
		logging.debug('Get: Query=%s, Zip=%s, Language=%s, Type=%s' % (queryParam,zipParam,languageParam,typeParam))
		
		rpcTopic = None
		rpcDiagnosis = None
		diagnosisData = MutableString()
		topicData = MutableString()
		
		userState = 'CA'
		
		if (zipParam):
			#request to get lat,lon,and state based on a zipcode
			try:
				urlStr = 'http://maps.google.com/maps/geo?q=%s&output=json&sensor=true&key=%s' % (zipParam,AppConfig.googleMapsAPIKey)
				jsonData = UtilLib.reverseGeo(urlStr)	
				#lets see if have jsonData from reverse geocoding call
				if (jsonData):
					userLon = jsonData['Placemark'][0]['Point']['coordinates'][0]
					userLat = jsonData['Placemark'][0]['Point']['coordinates'][1]
					userState = jsonData['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName']
				else:
					logging.error('Unable to retrieve geo information based on zipcode')
				
			except Exception,exTD1:
				logging.error('Errors getting geo data based on zipcode: %s' % exTD1)
예제 #5
0
def createResultsByExperiment(currentDir, outputDir):

    outFile = outputDir + '/results-by-exp.tex'
    os.system('mv ' + outFile + ' ' + outFile + '.old')
    addLatexHeader(outFile)

    os.chdir(currentDir)
    for f in os.listdir(currentDir):
        if os.path.isdir(currentDir + '/' + f):
            m = re.match("([23][abcde])\_scenario([\d])-(.*)", f)  #
            if (m != None):
                exp = m.group(1)
                scenario = m.group(2)
                label = m.group(3)
                labels[exp + scenario] = label

                print 'exp=' + exp + ' scenario=' + scenario + ' label=' + label

                #generatePDF(currentDir, f, g, outputDir, exp,scenario,label)

                createSlideByExp(outputDir, exp, scenario, label, outFile)

    addLatexFooter(outFile)
    os.chdir(outputDir)
    os.system('pdflatex ' + UtilLib.winpath(outFile))
    os.chdir(currentDir)
예제 #6
0
	def get(self,query,zip,lan='en',type='keyword',format='json'):
		#set content-type
		self.response.headers['Content-Type'] = Formatter.contentType(format)
		
		logging.debug('Get: Query=%s, Zip=%s, Language=%s, Type=%s, Format=%s' % (query,zip,lan,type,format))
		
		#data to output
		returnData = MutableString()
		returnData = ''
		
		rpcTopic = None
		rpcDiagnosis = None
		rpcClinicalTrials = None
		diagnosisData = MutableString()
		topicData = MutableString()
		clinicalTrialsData = MutableString()
		userState = None
		userLat = None
		userLon = None
		
		#request to get lat,lon,and state based on a zipcode
		try:
			urlStr = 'http://maps.google.com/maps/geo?q=%s&output=json&sensor=true&key=%s' % (zip,AppConfig.googleMapsAPIKey)
			jsonData = UtilLib.reverseGeo(urlStr)	
			#lets see if have jsonData from reverse geocoding call
			if (jsonData):
				userLon = jsonData['Placemark'][0]['Point']['coordinates'][0]
				userLat = jsonData['Placemark'][0]['Point']['coordinates'][1]
				userState = jsonData['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName']
			else:
				logging.error('Unable to retrieve geo information based on zipcode')
		except Exception,exTD1:
			logging.error('Errors getting geo data based on zipcode: %s' % exTD1)
예제 #7
0
def main():
    global logger, superCycleFile

    #parse the command-line arguments
    parseArgs(sys.argv[1:])

    startLogger(UtilLib.getTimeStamp())
    RandomSeeder.setRandom()

    if optCompileQuery:
        SneeqlLib.compileQueryOptimizer()

    if optQueriesList == None:
        doTests(None, None, 0)
    else:
        openSupers()
        for i in range(0, loopLength):
            superCycleFile.write(optMeasurementNameList[i])
            superEnergyFile.write(optMeasurementNameList[i])
            superGreenFile.write(optMeasurementNameList[i])
            superRedFile.write(optMeasurementNameList[i])
            superRAMFile.write(optMeasurementNameList[i])
            superROMFile.write(optMeasurementNameList[i])
            superYellowFile.write(optMeasurementNameList[i])
            doTests(optMeasurementNameList[i], optQueriesList[i], i + 2)
        superCycleFile.close()
        superEnergyFile.close()
        superGreenFile.close()
        superRedFile.close()
        superRAMFile.close()
        superROMFile.close()
        superYellowFile.close()

    report("Done")
    logging.shutdown()
def setOpts(opts):
	global optExitOnTupleError
	
	for o, a in opts:
		if (o == "--exit-on-tuple-error"):
			optExitOnTupleError = UtilLib.convertBool(a)
			continue			
예제 #9
0
def main():
    global optScenarioDir, optOutputDir

    #parse the command-line arguments
    parseArgs(sys.argv[1:])

    if optExp in ['tinydb', '1_2']:
        #30 node scenarios
        #		optScenarioDir += os.sep + "scenarios1"

        #100 node scenarios
        optScenarioDir += os.sep + "scenarios100"
    else:
        optScenarioDir += os.sep + "scenarios2"
    optOutputDir += os.sep + "exp" + optExp

    timeStamp = UtilLib.getTimeStamp()
    #if (not optTimeStampOutput):
    #	timeStamp = ""
    startLogger(timeStamp)

    #RandomSeeder.setRandom()

    #TODO: get SVN latest version

    #compile java
    SneeqlLib.compileQueryOptimizer()

    runScenarios(timeStamp, optStartScenario, optEndScenario, optScenarioDir,
                 optOutputDir + os.sep + timeStamp)
예제 #10
0
def parseArgs(args):
    global optSneeqlRoot, optNumEpochs, optOutputRoot, optTimeStampOutput, optDoTossim, optDoAvrora, optNumAvroraRuns, optTossimSyncTime, optDoAvroraCandidates, optDoTossimCandidates, optGenerateRandomNet, optSneeqlNetFile, optAvroraNetFile, optNetNumNodes, optNetXDim, optNetYDim, optGenerateRandomSchemas, optNumSchemas, optSchemaFile, optQueries, optAcqRates, optMaxBufferingFactors

    try:
        optNames = [
            "help", "short", "sneeql-root=", "num-epochs=", "output-root=",
            "timestamp-output=", "do-tossim=", "do-avrora=",
            "num-avrora-runs=", "tossim-sync-time=", "do-avrora-candidates=",
            "do-tossim-candidates="
        ]
        optNames += [
            "generate-random-network=", "sneeql-network-file=",
            "avrora-network-file=", "net-num-nodes=", "net-x-dim=",
            "net-y-dim="
        ]
        optNames += [
            "generate-random-schemas=", "num-schemas=", "schema-file="
        ]
        optNames += ["queries=", "acq-rates=", "max-buffering-factors="]

        #append the result of getOpNames to all the libraries
        optNames += SneeqlLib.getOptNames()
        optNames += TossimLib.getOptNames()
        optNames += AvroraLib.getOptNames()
        optNames += RandomSeeder.getOptNames()

        optNames = UtilLib.removeDuplicates(optNames)

        opts, args = getopt.getopt(args, "h", optNames)
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)
예제 #11
0
def plotAggrGraph(outputDir, measurementType, exp):

    scriptStr = '''
set term postscript eps enhanced color
set out '%s'

set title "%s summary"
set auto x
set auto y
set style data histogram
set xlabel "Scenarios"
set ylabel "Percentage Improvement"
set key top right
set style histogram cluster gap 1
set style fill pattern border -1
set boxwidth 0.9 absolute
set xtics
set datafile missing '?'
plot '%s' using 2:xtic(1) ti col fillstyle pattern 1, '%s' using 3:xtic(1) ti col fillstyle pattern 2, '%s' using 4:xtic(1) ti col  fillstyle pattern 3, '%s' using 5:xtic(1) ti col fillstyle pattern 8


set term gif
set style fill solid border -1
set out '%s'
plot '%s' using 2:xtic(1) ti col, '%s' using 3:xtic(1) ti col, '%s' using 4:xtic(1) ti col, '%s' using 5:xtic(1) ti col
	
'''

    epsFile = UtilLib.winpath(outputDir + '/' + measurementType +
                              '-summary.eps')
    mType = measurementTypeMap[measurementType]
    plotFile = UtilLib.winpath(outputDir + '/' + measurementType +
                               '-summary.txt')
    gifFile = UtilLib.winpath(outputDir + '/' + measurementType +
                              '-summary.gif')
    scriptStr = scriptStr % (epsFile, mType, plotFile, plotFile, plotFile,
                             plotFile, gifFile, plotFile, plotFile, plotFile,
                             plotFile)

    scriptFile = outputDir + '/' + measurementType + '-script.txt'
    f = open(scriptFile, 'w')
    f.write(scriptStr)
    f.close()

    exitVal = os.system(gnuPlotExe + ' < ' + scriptFile)
    os.system('epstopdf  ' + epsFile)
    os.system('rm ' + epsFile)
예제 #12
0
def runSimulation(nescRootDir, outputDir, desc, numNodes, simulationDuration = 100, networkFilePath = None, useEnergyMonitor = True, deliverToSerial = True, packetMonitor = True, randomSeed = 0):

	#Random sensor data for each sensor
	sensorDataStr = __getSensorData(numNodes)

	#Relevant monitors
	monitorStr = ""	
	if (useEnergyMonitor or deliverToSerial):
		monitors = []
		if (useEnergyMonitor):
			monitors.append("energy")
		if (deliverToSerial):
			monitors.append("serial")
		if (packetMonitor):
			monitors.append("packet")
		
		#Suggest this is a parameter rather than hard-coded in.
		#(see above monitors)
		#monitors.append ("trip-time")
		
		monitorStr = "-monitors=" + string.join(monitors, ",")
		if (deliverToSerial):
			monitorStr += " -node=0 -port=2390 "

		#Suggest this is a parameter rather than hard-coded in.
		#this is a generic library...
		#monitorStr += " -pairs=0x2b52:0x2b92"
		
	#Topology string	
	topologyStr = ''
	if networkFilePath != None:
		if networkFilePath.endswith('.top'):
			topologyStr = '-topology='+UtilLib.winpath(networkFilePath)

	#Count str
	countStr = __getCountStr(numNodes)	
		
	#OD files
	odStr = getODs(nescRootDir, numNodes)
	
	outputFile = outputDir + "/avrora-out.txt"
	deliverOutputFile = outputDir + "/deliver-out.txt"
	tupleOutputFile = outputDir + "/tuple-out.txt"
	
	commandStr = optJava5exe + " -Xms32m -Xmx1024m avrora.Main -simulation=sensor-network -colors=false -random-seed=%d -sensor-data=%s -seconds=%s %s %s -nodecount=%s %s > %s"
	commandStr = commandStr % (randomSeed, sensorDataStr, str(simulationDuration), monitorStr, topologyStr, countStr, odStr, outputFile)
	
	AvroraThread(commandStr, deliverToSerial).start()
	if (deliverToSerial):
		time.sleep(10 + numNodes) #1 second per node seems to be more than enough
		ListenerThread(deliverOutputFile).start() 

		#Wait for both threads to finish
		while (len(threading.enumerate()) > 1):
			time.sleep(10)

		readDeliveredPackets(deliverOutputFile, tupleOutputFile)
	return (outputFile, tupleOutputFile)
예제 #13
0
def generateGraph(dataFile, outputGraphFile):

    scriptStr = '''
set title "Varying Max Neighbourhood Size "
set auto x
set auto y
set style data linespoints
set xlabel "Max neighbourhood size"
set ylabel "Objective function value"
set y2label "num DAFs considered"
set key top right
set style histogram cluster gap 1
set style fill pattern border -1
set boxwidth 0.9 absolute
set yrange [0:]
set y2range [0:]
set y2tics border
set xtics
set datafile missing '?'

set term postscript eps enhanced
set style fill solid border -1
set out '%s'
plot '%s' using 1:2 ti col, '%s' using 1:4 ti col axes x1y2

set term png
set style fill solid border -1
set out '%s'
plot '%s' using 1:2 ti col, '%s' using 1:4 ti col axes x1y2
'''

    epsGraphPath = UtilLib.winpath(outputGraphFile + '.eps')
    pngGraphPath = UtilLib.winpath(outputGraphFile + '.png')
    dataFilePath = UtilLib.winpath(dataFile)

    scriptStr = scriptStr % (epsGraphPath, dataFilePath, dataFilePath,
                             pngGraphPath, dataFilePath, dataFilePath)
    scriptFile = 'c:/gplot-script.txt'
    f = open(scriptFile, 'w')
    f.write(scriptStr)
    f.close()

    exitVal = os.system(gnuPlotExe + ' < ' + scriptFile)
    os.system('epstopdf  ' + epsGraphPath)
    os.system('rm ' + epsGraphPath)
예제 #14
0
def main():
    #parse the command-line arguments
    parseArgs(sys.argv[1:])

    timeStamp = UtilLib.getTimeStamp()
    startLogger(timeStamp)

    SneeqlLib.compileQueryOptimizer()

    mainLoop()
예제 #15
0
def generatePDF(currentDir, f, g, outputDir, exp, scenario, label):
    for g in os.listdir(currentDir + '/' + f):
        if g.endswith('.eps'):
            oldGraphFile = currentDir + '/' + f + '/' + g
            os.system('epstopdf  ' + UtilLib.winpath(oldGraphFile))
            #os.system('rm '+oldGraphFile)
            newGraphFile = outputDir + '/exp' + exp + '-scenario' + scenario + '-' + label + '-' + g.replace(
                '.eps', '.pdf')
            os.system('mv ' + oldGraphFile.replace('.eps', '.pdf') + ' ' +
                      newGraphFile)
예제 #16
0
def main():
    global logger

    #parse the command-line arguments
    parseArgs(sys.argv[1:])

    startLogger(UtilLib.getTimeStamp())
    RandomSeeder.setRandom()

    doTest()

    report("Done")
    logging.shutdown()
예제 #17
0
	def getHospitalDBRecords(self,lat,lon):
		#get hospital data
		gb = geobox2.Geobox(lat, lon)
		box = gb.search_geobox(50)
		query = HospitalInfo.all().filter("geoboxes IN", [box])
		results = query.fetch(50)
		db_recs = {}
		for result in results:
			distance = UtilLib.getEarthDistance(lat, lon, result.location.lat, result.location.lon)
			if (distance and distance > 0):
				db_recs[distance] = result
		
		return db_recs
예제 #18
0
def getODs(nescRootDir, numNodes):
	#print 'nescRootDir:'+nescRootDir
	ods = []
	for i in range(0, numNodes):
		fileName = nescRootDir + "/mote"+str(i)+".od"
		winNescRootDir = UtilLib.winpath(nescRootDir)
		if os.path.exists(fileName):
			ods = ods + ["\"" + winNescRootDir + "/mote"+str(i)+".od\""]
		else:
			ods = ods + ["\"" + winNescRootDir + "/empty.od\""]
			if not os.path.exists(nescRootDir+'/empty.od'):
				os.system("cp " + os.path.dirname(__file__) + "/empty.od "+nescRootDir+"/empty.od")
			
	return string.join(ods,' ')
예제 #19
0
def parseArgs(args):
    global optOutputDir1, optOutputDir2
    try:
        optNames = []

        #append the result of getOpNames to all the libraries
        optNames += SneeqlLib.getOptNames()
        optNames = UtilLib.removeDuplicates(optNames)

        opts, args = getopt.getopt(args, "h", optNames)
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)
예제 #20
0
	def getHospitalData(self,lat,lon,format):
		#get hospital data
		gb = geobox2.Geobox(lat, lon)
		box = gb.search_geobox(100)
		query = HospitalInfo.all().filter("geoboxes IN", [box])
		results = query.fetch(100)
		db_recs = {}
		for result in results:
			distance = UtilLib.getEarthDistance(lat, lon, result.location.lat, result.location.lon)
			if (distance and distance > 0):
				db_recs[distance] = result
		
		returnData = MutableString()
		returnData = ''

		#output this badboy
		if (db_recs and len(db_recs) > 0):
			for key in sorted(db_recs.iterkeys()):
				p = db_recs[key]
				if (format == 'json'):
					startTag = '{'
					endTag = '},'
					distance = Formatter.data(format, 'distance', '%s %s' % (str(math.ceil(key)), "mi"))[:-1]#'%.2g %s' % (key, "mi"))[:-1]
				else:
					startTag = '<record>'
					endTag = '</record>'
					distance = Formatter.data(format, 'distance', '%s %s' % (str(math.ceil(key)), "mi"))
				#build the string	
				returnData = "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" % (returnData,startTag,
															Formatter.data(format, 'hospital_id', p.hospital_id),
															Formatter.data(format, 'name', p.name.replace('&', '&amp;')),
															Formatter.data(format, 'address', p.address.replace('&', '&amp;')),
															Formatter.data(format, 'city', p.city),
															Formatter.data(format, 'state', p.state),
															Formatter.data(format, 'zip_code', p.zip_code),
															Formatter.data(format, 'county', p.county.replace('&', '&amp;')),
															Formatter.data(format, 'phone', p.phone),
															Formatter.data(format, 'hospital_type', p.hospital_type.replace('&', '&amp;')),
															Formatter.data(format, 'hospital_owner', p.hospital_owner.replace('&', '&amp;')),
															Formatter.data(format, 'emergency_service', p.emergency_service),
															Formatter.data(format, 'geo_location', p.location),
															distance,
															endTag
															)
	
			if (format == 'json'):
				return returnData[:-1]
			else:
				return returnData
예제 #21
0
def generateGraph(dataFile, outputGraphFile):

    scriptStr = '''
set title "Varying Max Neighbourhood Size "
set auto x
set auto y
set style data linespoints
set pointsize 5
set xlabel "Max neighbourhood size"
set ylabel "Objective function value"
set y2label "Measured value"
set key top right
set yrange [0:]
set y2range [0:]
set y2tics border
set xtics
set datafile missing '?'

set term postscript eps enhanced
set style fill solid border -1
set out '%s'
plot '%s' using 1:2 ti col, '%s' using 1:3 ti col axes x1y2
'''

    graphPath = UtilLib.winpath(outputGraphFile)
    dataFilePath = UtilLib.winpath(dataFile)

    scriptStr = scriptStr % (graphPath, dataFilePath, dataFilePath)
    scriptFile = 'c:/gplot-script.txt'
    f = open(scriptFile, 'w')
    f.write(scriptStr)
    f.close()

    exitVal = os.system(gnuPlotExe + ' < ' + scriptFile)
    os.system('epstopdf  ' + graphPath)
    os.system('rm ' + graphPath)
예제 #22
0
def main():
    timeStamp = UtilLib.getTimeStamp()
    startLogger(timeStamp)

    if (not os.getcwd().endswith("avrora1")):
        print "This script should be run from the avrora directory"
        sys.exit(-1)

    parseArgs(sys.argv[1:])

    nescDir = os.getcwd()
    if not optSkipODs:
        AvroraLib.compileNesCCode(nescDir)
        AvroraLib.generateODs(nescDir)

    runSimulation(nescDir)
예제 #23
0
def parseArgs(args):
    global optScenarioDir, optOutputDir, optStartScenario, optEndScenario, optRoutingTreesToGenerate, optRoutingTreesToKeep, optQoSA, optTDBAlpha, qosaQoSSpec, fgQoSSpec, optExp
    try:
        optNames = [
            "start=", "end=", "rt-generate=", "rt-keep=", "tdb-alpha=",
            "qa-qos=", "fg-qos=", "qosa=", "exp="
        ]

        #append the result of getOpNames to all the libraries
        optNames += SneeqlLib.getOptNames()
        optNames = UtilLib.removeDuplicates(optNames)

        opts, args = getopt.getopt(args, "h", optNames)
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)
예제 #24
0
def parseArgs(args):
    global optSneeqlRoot, optSimDuration, optOutputRoot
    global optTimeStampOutput, optDoTossim, optDoAvrora
    global optTossimSyncTime, optDoAvroraCandidates, optDoTossimCandidates
    global optSneeqlNetFile
    global optNetNumNodes
    global optSchemaFile
    global optQueries, optAcqRates, optMaxBufferingFactors, optDeliveryTimes
    global optTestAll, optLedDebug, optXValType

    try:
        optNames = [
            "help", "short", "sneeql-root=", "sim-duration=", "output-root="
        ]
        optNames += [
            "timestamp-output=", "compile-sneeql=", "do-tossim=", "do-avrora="
        ]
        optNames += [
            "tossim-sync-time=", "do-avrora-candidates=",
            "do-tossim-candidates="
        ]
        optNames += [
            "generate-random-network=", "sneeql-network-file=",
            "net-num-nodes="
        ]
        optNames += ["schema-file="]
        optNames += [
            "queries=", "acq-rates=", "max-buffering-factors=",
            "delivery-times=", "test-all=", "x-val-type="
        ]

        #append the result of getOpNames to all the libraries
        optNames += SneeqlLib.getOptNames()
        optNames += TossimLib.getOptNames()
        optNames += AvroraLib.getOptNames()
        optNames += RandomSeeder.getOptNames()
        optNames += checkTupleCount.getOptNames()

        optNames = UtilLib.removeDuplicates(optNames)

        opts, args = getopt.getopt(args, "h", optNames)
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)
예제 #25
0
def main():

    #parse the command-line arguments
    parseArgs(sys.argv[1:])

    timeStamp = UtilLib.getTimeStamp()
    if (not optTimeStampOutput):
        timeStamp = ""
    startLogger(timeStamp)

    RandomSeeder.setRandom()

    #TODO: get SVN latest version

    #compile java
    SneeqlLib.compileQueryOptimizer()

    generateAndTestScenarios(timeStamp)
예제 #26
0
def testAvroraCandidate(nescDir, query, outputPath, numNodes, duration, schemaPath, aqRate, avroraNetFile, alphaGraph, deltaGraph, epsilonGraph, lambdaGraph):

	#Compile the nesC
	exitVal = AvroraLib.compileNesCCode(nescDir)
	if (exitVal != 0):
		return;		
	AvroraLib.generateODs(nescDir)

	candidateInfo = getCandidateSummaryInformation(nescDir, query, outputPath)
	candidateInfo['total-energy'] = []
	candidateInfo['network-lifetime'] = []
	alpha = int(candidateInfo['alpha-ms'])
	bufferingFactor = int(candidateInfo['beta'])
	duration = int((float(optNumAgendaEvals) * float(alpha) * float(bufferingFactor)) / 1000.0)
	
	for i in range(0, optNumAvroraRuns):
		if optNumAvroraRuns > 1:
			report("Avrora simulation run #%d for candidate %s\n" % (i, outputPath))
	
		#run avrora simulation
		(avroraOutputFile, traceFilePath) = AvroraLib.runSimulation(nescDir, outputPath, query, numNodes, simulationDuration = duration, networkFilePath = avroraNetFile)

		#check all tuples present
		queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % (outputPath, query)
		checkTupleCount.checkResults(query, traceFilePath, schemaPath, alpha, bufferingFactor, duration)	

		#Report total energy consumption
		siteLifetimeRankFile = "%s/site-lifetime-rank.csv" % nescDir
		(sumEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy, sensorEnergy, otherEnergy, networkLifetime) = AvroraLib.computeEnergyValues(nescDir, duration, inputFile = "avrora-out.txt", ignoreLedEnergy = True, siteLifetimeRankFile = siteLifetimeRankFile)

		lifetimeDays = UtilLib.secondsToDays(networkLifetime) #Put this into avrora lib so rank file has it too
		
		report ("The total energy consumption is %f" % (sumEnergy))
		normSumEnergy = (float(sumEnergy) / float(duration)) * float(optQueryDuration) #to do: use new function (below)
		report ("The normalized total energy consumption is %f" % (normSumEnergy))
		report ("The lifetime for this network is %f" % (lifetimeDays))

		candidateInfo['total-energy'].append(float(normSumEnergy))
		candidateInfo['network-lifetime'].append(float(lifetimeDays))

	print "DEBUG: testAvroraCandidate.candidateInfo = " + str(candidateInfo)
	return candidateInfo
예제 #27
0
def main():
    global logger

    #parse the command-line arguments
    parseArgs(sys.argv[1:])

    startLogger(UtilLib.getTimeStamp())
    RandomSeeder.setRandom()

    openQuerySummarises(optOutputRoot + "/" + SneeqlLib.optQuery + "/")
    for i in range(0, len(optMeasurementsRemoveOperatorsList)):
        doTest(optMeasurementsRemoveOperatorsList[i])
    closeQuerySummarises(queryEnergyFile)
    closeQuerySummary(queryGreenFile)
    closeQuerySummary(queryRedFile)
    closeQuerySummary(queryYellowFile)
    closeQuerySummary(queryYellowMinFile)
    closeQuerySummary(querySizeFile)
    report("Done")
    logging.shutdown()
예제 #28
0
def createResultsByScenario(currentDir, outputDir):
    global measurementTypeMap, scenarioSet, expSet

    outFile = outputDir + '/results-by-scenario.tex'
    os.system('mv ' + outFile + ' ' + outFile + '.old')
    addLatexHeader(outFile)

    measurementTypeMap['pi-ms'] = 'Acquisition Interval'
    measurementTypeMap['delta-ms'] = 'Delivery Time'
    measurementTypeMap['total-energy'] = 'Total Energy'
    measurementTypeMap['network-lifetime'] = 'Network Lifetime'

    for measurementType in measurementTypeMap.keys():
        for scenario in scenarioSet:
            for exp in expSet:
                createSlideByScenario(outputDir, measurementType, scenario,
                                      exp, measurementTypeMap, outFile)

    addLatexFooter(outFile)
    os.chdir(outputDir)
    os.system('pdflatex ' + UtilLib.winpath(outFile))
    os.chdir(currentDir)
예제 #29
0
def parseArgs(args):
	global optSneeqlRoot, optNumAgendaEvals, optQueryDuration, optOutputRoot, optLabel, optTimeStampOutput, optDoTossim, optDoAvrora, optNumAvroraRuns, optTossimSyncTime, optDoAvroraCandidates, optDoTossimCandidates, optDoModel, optGenerateRandomNet, optSneeqlNetFile, optAvroraNetFile, optNetNumNodes, optNetXDim, optNetYDim, optGenerateRandomSchemas, optNumSchemas, optSchemaFile, optQueries, optAcqRates, optMaxBufferingFactors, optQoS, optQoSAwareRouting, optRoutingTreesToGenerate, optRoutingTreesToKeep, optQoSAwareWhereScheduling, optQoSAwareWhenScheduling, optBufferingFactor
	
	try:
		optNames = ["help", "sneeql-root=", "num-agenda-evals=", "query-duration=", "output-root=", "label=", "timestamp-output=", "do-tossim=", "do-avrora=", "num-avrora-runs=", "tossim-sync-time=", "do-avrora-candidates=", "do-tossim-candidates=", "do-model="]
		optNames += ["generate-random-network=", "sneeql-network-file=", "avrora-network-file=", "net-num-nodes=", "net-x-dim=", "net-y-dim="]
		optNames += ["generate-random-schemas=", "num-schemas=", "schema-file="]
		optNames += ["queries=", "acq-rates=", "max-buffering-factors="]
		optNames += ["qos-aware-routing=", "routing-trees-to-generate=", "routing-trees-to-keep=", "qos-aware-where-scheduling=", "qos-aware-when-scheduling=","buffering-factor="]
	
		#append the result of getOpNames to all the libraries 
		optNames += SneeqlLib.getOptNames();
		optNames += TossimLib.getOptNames();
		optNames += AvroraLib.getOptNames();
		optNames += RandomSeeder.getOptNames();

		optNames = UtilLib.removeDuplicates(optNames)
		
		opts, args = getopt.getopt(args, "h",optNames)
	except getopt.GetoptError, err:
		print str(err)
		usage()
		sys.exit(2)
예제 #30
0
def mainLoop():
    queryFile = queryMap[optQuery]
    networkFile = networkMap[optNetworkSize]
    heteroNet = (optNetworkType == 'B')
    schemaFile = numSourcesMap[optNetworkSize + '_' + optNumSources]
    qosFile = optGoalMap[optOptGoal]
    overallOutputDir = optOutputRoot + '/' + optQuery + '-' + optNetworkSize + 'n-type' + optNetworkType + '-' + optNumSources + 's-' + optOptGoal

    duration = 100
    #	for nn in range(optMinNN,optMaxNN+1):
    for nn in [0, 1, 3, 5, 10, 15, 20]:
        runOutputDir = overallOutputDir + '/nn' + str(nn)

        invokeQueryOptimizer(runOutputDir, queryFile, networkFile, heteroNet,
                             schemaFile, qosFile, nn)
        summary = parseOutFile(runOutputDir + '/' + optQuery +
                               '/query-plan/matlab/wheresched/out' + str(nn) +
                               '.txt')

        if optOptGoal == 'min_delivery':
            #check all tuples present
            queryPlanSummaryFile = "%s/%s/query-plan/query-plan-summary.txt" % (
                runOutputDir, optQuery)

            deliveryTime = SneeqlLib.getDeliveryTime(queryPlanSummaryFile)
            logToDataFile(overallOutputDir, nn, summary['min_f'],
                          float(deliveryTime), summary['num DAFs considered'])
        else:
            #Compile the nesC
            nescDir = runOutputDir + '/' + optQuery + '/avrora1'
            exitVal = AvroraLib.compileNesCCode(nescDir)
            if (exitVal != 0):
                reportError("Error compiling avrora nesC code")
                return
            AvroraLib.generateODs(nescDir)

            #Invoke Avrora simulation
            avroraNetFile = UtilLib.winpath(
                os.getenv('SNEEQLROOT')) + '\\\\' + networkFile.replace(
                    '.xml', '.top')
            (avroraOutputFile, traceFilePath) = AvroraLib.runSimulation(
                nescDir,
                runOutputDir,
                optQuery,
                int(optNetworkSize),
                simulationDuration=duration,
                networkFilePath=avroraNetFile)

            #Check query results
            schemaPath = os.getenv('SNEEQLROOT') + '/' + schemaFile
            checkTupleCount.checkResults(optQuery, traceFilePath, schemaPath,
                                         10000, 1, duration)

            #Report total energy consumption
            siteLifetimeRankFile = "%s/site-lifetime-rank.csv" % nescDir
            (sumEnergy, maxEnergy, averageEnergy, radioEnergy, cpu_cycleEnergy,
             sensorEnergy, otherEnergy,
             networkLifetime) = AvroraLib.computeEnergyValues(
                 runOutputDir,
                 duration,
                 inputFile="avrora-out.txt",
                 ignoreLedEnergy=True,
                 siteLifetimeRankFile=siteLifetimeRankFile)
            report("The total energy consumption is %f" % (sumEnergy))
            report("The lifetime for this network is %f" %
                   (networkLifetime))  #seems to be in seconds

            if optOptGoal == 'min_energy':
                logToDataFile(overallOutputDir, nn, summary['min_f'],
                              float(sumEnergy), summary['num DAFs considered'])
            else:
                logToDataFile(overallOutputDir, nn, summary['min_f'],
                              float(networkLifetime),
                              summary['num DAFs considered'])
예제 #31
0
def testScenario(schemaPath, query, aqRate, bFactor, numNodes, outputPath,
                 sneeqlNetFile, avroraNetFile):

    report(
        "\n\n*********************************************************************\n"
    )
    report(
        "Testing scenario:\nquery=%s\nschema=%s\naqRate=%d\nbFactor=%d\nnumNodes=%d\noutputPath=%s\n"
        % (query, schemaPath, aqRate, bFactor, numNodes, outputPath))

    rtscore_lifetime = StatLib.Dataset()

    #Q3temp and Q4temp only: Set the fromWindow parameter depending on the acquisiton rate
    if (query == "Q3temp"):
        adjustQ3temp(aqRate)
    if (query == "Q4temp"):
        adjustQ4temp(aqRate)

    #Set the simulation duration depending on the acquisition rate
    duration = (optNumEpochs * aqRate) / 1000

    #query optimizer parameters
    coreParams = [
        "-nesc-control-radio-off=true", "-nesc-adjust-radio-power=true",
        "-nesc-power-management=true", "-display-graphs=false",
        "-qos-aware-partitioning=false", "-qos-aware-routing=true",
        "-qos-aware-where-scheduling=false",
        "-qos-aware-when-scheduling=false", "-sinks=0",
        "-nesc-led-debug=false",
        "-network-topology-file=" + UtilLib.winpath(sneeqlNetFile),
        "-nesc-generate-tossim-code=" + str(optDoTossim),
        "-nesc-generate-avrora-code=" + str(optDoAvrora),
        "-site-resource-file=input/mica2-site-resources.xml",
        "-display-sensornet-link-properties=true",
        "-routing-trees-to-generate=10", "-routing-trees-to-keep=10"
    ]

    schemaFile = "input/" + os.path.split(schemaPath)[1]
    report("using schema file: %s" % schemaFile)
    schemaFileStr = UtilLib.getFileContents(schemaPath)
    report(schemaFileStr)
    scenarioParams = [
        "-schema-file=" + schemaFile, "-query=" + query + ".txt",
        "-qos-acquisition-interval=%d" % (aqRate),
        "-qos-max-buffering-factor=%d" % (bFactor),
        "-output-root-dir=" + UtilLib.winpath(outputPath)
    ]

    #compile the query for using the SNEEql optimizer
    queryCompilerParams = coreParams + scenarioParams
    exitVal = SneeqlLib.compileQueryParamStr(queryCompilerParams, query)
    if (exitVal != 0):
        return

    if (optDoTossim):
        #best plan
        report("\nBest Query Plan Tossim simulation\n=================\n")
        nescDir = "%s/%s/tossim" % (outputPath, query)
        traceFilePath = "%s/tossim-trace.txt" % (outputPath)
        testTossimCandidate(nescDir, traceFilePath, query, numNodes, duration,
                            outputPath, schemaPath, aqRate)

        #now do other candidate plans
        if (optDoTossimCandidates):
            doTossimCandidates(outputPath, query, numNodes, duration,
                               schemaPath, aqRate)

    if (optDoAvrora):
        #best plan
        report("\nBest Query Plan Avrora simulation\n=================\n")
        nescDir = "%s/%s/avrora" % (outputPath, query)
        testAvroraCandidate(nescDir, query, outputPath, numNodes, duration,
                            schemaPath, aqRate, avroraNetFile,
                            rtscore_lifetime)

        #now do other candidate plans
        if (optDoAvroraCandidates):
            doAvroraCandidates(outputPath, query, numNodes, duration,
                               schemaPath, aqRate, avroraNetFile,
                               rtscore_lifetime)

    #draw the output graph
    resultFilename = "%s/results.eps" % (outputPath)
    xLabel = "Routing tree score"
    yLabel = "Simulated lifetime"
    rtscore_lifetime.drawScatterDiagram(
        resultFilename, xLabel, yLabel,
        "Routing Tree Lifetime Score vs. Simulated Lifetime")
    report("The correlation coefficient is %g" %
           rtscore_lifetime.getCorrelCoeff())
예제 #32
0
            continue

        if (o == "--num-epochs"):
            optNumEpochs = int(a)
            continue

        if (o == "--output-root"):
            optOutputRoot = a
            continue

        if (o == "--timestamp-output"):
            optTimeStampOutput = a
            continue

        if (o == "--do-tossim"):
            optDoTossim = UtilLib.convertBool(a)
            continue

        if (o == "--do-avrora"):
            optDoAvrora = UtilLib.convertBool(a)
            continue

        if (o == "--num-avrora-runs"):
            optNumAvroraRuns = int(a)
            continue

        if (o == "--tossim-sync-time"):
            optTossimSyncTime = int(a)
            continue

        if (o == "--do-avrora-candidates"):
예제 #33
0
def setOpts(opts):
	global optSneeqlRoot, java5CompilerExe, java5exe 
	global optCygwin
	global javaClasspathListSep, javaClasspathPathSep
	global optCompileSneeql, optNumSourceNodes, optNonIntersecting

	#"iniFile"	#"evaluate-all-queries"	
	global optDeleteOldFiles, optQueryDir, optQuery 
	#MQE #"sinks"	#"qos-file"	
	global optSneeqlNetworkTopologyFile	
	#"site-resource-file"	
	global optSchemaFile
	global optOperatorMetadataFile
	#"types-file"	
	global optHaskellUse
	#"haskell-decl-dir"
	#"haskell-main"	#"haskell-decl-file"	#"qos-aware-partitioning"	#"qos-aware-routing"
	#"qos-aware-where-scheduling"	#"qos-aware-when-scheduling	
	global optOutputRootDir
	#"output-query-plan-dir"	#"output-nesc-dir"	
	global optDebugExitOnError
	global optMeasurementsActiveAgendaLoops, optMeasurementsIgnoreIn
	global optMeasurementsRemoveOperators, optMeasurementsThinOperators
	global optMeasurementsMultiAcquire
	#"display-graphs"
	#"display-operator-properties"	#"display-sensornet-link-properties"
	#"display-site-properties"	#"display-config-graphs"
	global optDisplayCostExpressions
	global optRemoveUnrequiredOperators, optPushProjectionDown, optCombineAcquireAndSelect
	#"routing-random-seed"	#"routing-trees-to-generate"	#"routing-trees-to-keep"
	global optWhereSchedulingRemoveRedundantExchanges 
	#"when-scheduling-decrease-bfactor-to-avoid-agenda-overlap"
	global optTargets
	#"nesc-control-radio-off"	#"nesc-adjust-radio-power"	#"nesc-synchronization-period"
	#"nesc-power-management"
	global optNescDeliverLast
	global optNescLedDebug,	optNescYellowExperiment, optNescGreenExperiment
	global optNescRedExperiment, optQosAcquisitionInterval	
	#"qos-min-acquisition-interval"	#"qos-max-acquisition-interval"
	global optQosMaxDeliveryTime	
	#"qos-max-total-energy"	#"qos-min-lifetime"
	global optQosMaxBufferingFactor, optQosBufferingFactor	#"qos-query-duration"
	global optNumSourceNodes
	
	for o, a in opts:
		if (o== "--sneeql-root"):
			optSneeqlRoot = a
			continue
		if (o== "--javac-5-exe"):
			java5CompilerExe = a
			continue
		if (o== "--java-5-exe"):
			java5exe = a
			continue
		if (o== "--cygwin"):
			optCygwin = True
			javaClasspathListSep = ";"
			javaClasspathPathSep = "\\"
			java5CompilerExe = java5CompilerExe + ".exe"
			java5exe = java5exe + ".exe"
			continue
		if (o == "--compile-sneeql"):
			optCompileSneeql = UtilLib.convertBool(a)
			continue			
		if (o== "--num-source-nodes"):
			optNumSourceNodes = int(a)
			continue
		if (o== "--non-intersecting"):
			optNonIntersecting= UtilLib.convertBool(a)
			continue		
		#Java compiler options	
		#"iniFile"	#"evaluate-all-queries"	#"query-dir"		
		if (o == "--delete-old-files"):
			optDeleteOldFiles = UtilLib.convertBool(a)
			continue
		if (o == "--query-dir"):
			optQueryDir = a
			continue
		if (o == "--query"):
			optQuery = a
			continue
		#MQE #"sinks"	#"qos-file"	
		if (o == "--sneeql-network-topology-file"):
			optSneeqlNetworkTopologyFile = a
			continue
		if (o == "--network-topology-file"):
			optSneeqlNetworkTopologyFile = a
			continue
		#"network-topology-file"	#"site-resource-file"
		if (o == "--schema-file"):
		    optSchemaFile = a
		    continue
		if (o == "--operator-metadata-file"):
		    optOperatorMetadataFile = a
		    continue
		#"types-file"	
		if (o == "--haskell-use"):
			optHaskellUse = UtilLib.convertBool(a)
			continue
		#"haskell-decl-dir"
		#"haskell-main"	#"haskell-decl-file"	#"qos-aware-partitioning"	#"qos-aware-routing"
		#"qos-aware-where-scheduling"	#"qos-aware-when-scheduling	
		if (o == "--output-root-dir"):
			optOutputRootDir = a
			continue
		#"output-query-plan-dir"	#"output-nesc-dir"	
		if (o == "--debug-exit-on-error"):
			optDebugExitOnError = a
			continue
		if (o == "--measurements-active-agenda-loops"):
			optMeasurementsActiveAgendaLoops = int(a)
			continue
		if (o == "--measurements-ignore-in"):
			optMeasurementsIgnoreIn = a
			continue
		if (o == "--measurements-remove-operators"):
			optMeasurementsRemoveOperators = a
			continue
		if (o == "--measurements-thin-operators"):
			optMeasurementsThinOperators = a
			continue
		if (o == "--measurements-multi-acquire"):
			optMeasurementsMultiAcquire = a
			continue
		#"display-graphs"
		#"display-operator-properties"	#"display-sensornet-link-properties"
		#"display-site-properties"	#"display-config-graphs"	
		if (o == "--display-cost-expressions"):
			optDisplayCostExpressions = UtilLib.convertBool(a)
			continue
		if (o == "--remove-unrequired-operators"):
			optRemoveUnrequiredOperators = UtilLib.convertBool(a)
			continue
		if (o == "--push-projection-down"):
			optPushProjectionDown = UtilLib.convertBool(a)
			continue
		if (o == "--combine-acquire-and-select"):
			optCombineAcquireAndSelect = UtilLib.convertBool(a)
			continue
		#"routing-random-seed"	#"routing-trees-to-generate"	#"routing-trees-to-keep"
		if (o == "--where-scheduling-remove-redundant-exchanges"):
			optWhereSchedulingRemoveRedundantExchanges = UtilLib.convertBool(a)
			continue
		#"when-scheduling-decrease-bfactor-to-avoid-agenda-overlap"	
		if (o == "--targets"):
			optTargets = a
			continue
		#"nesc-control-radio-off"	#"nesc-adjust-radio-power"	#"nesc-synchronization-period"
		#"nesc-power-management"
		if (o == "nesc-deliver-last"):
			optNescDeliverLast = UtilLib.convertBool(a)
			continue
		
		if (o == "--nesc-led-debug"):
			optNescLedDebug = UtilLib.convertBool(a)
			if (not optNescLedDebug):
				if (optNescYellowExperiment != None):
					reportWarning("Overriding --nesc-led-debug to true")
					optNescLedDebug = True
				if (optNescGreenExperiment != None):
					reportWarning("Overriding --nesc-led-debug to true")
					optNescLedDebug = True
				if (optNescRedExperiment != None):
					reportWarning("Overriding --nesc-led-debug to true")
					optNescLedDebug = True
			continue			
		if (o == "--nesc-yellow-experiment"):
			optNescYellowExperiment = a
			optNescLedDebug = True
			continue			
		if (o == "--nesc-green-experiment"):
			optNescGreenExperiment = a
			optNescLedDebug = True
			continue			
		if (o == "--nesc-red-experiment"):
			optNescRedExperiment = a
			optNescLedDebug = True
			continue			
		if (o == "--qos-acquisition-interval"):
		 	optQosAcquisitionInterval = int(a)
		 	continue  
		#"qos-min-acquisition-interval"	#"qos-max-acquisition-interval"
		if (o == "--qos-max-delivery-time"):
			optQosMaxDeliveryTime = int(a)
		#"qos-max-total-energy"	#"qos-min-lifetime"
		if (o == "--qos-max-buffering-factor"):
			optQosMaxbufferingFactor = int(a)
			continue
		if (o == "--qos-buffering-factor"):
			optQosBufferingFactor = int(a)
			continue
예제 #34
0
def compileQuery(desc, 
	#"iniFile"	#"evaluate-all-queries"	
	deleteOldFiles = None,
	queryDir = None,
	query = None, 
	#"sinks" #"qos-file" #"network-topology-file"
	sneeqlNetworkTopologyFile = None,
	#"site-resource-file"	
	schemaFile = None,
	operatorMetadataFile = None,
	#"types-file"	
	haskellUse = None,
	#"haskell-decl-dir"	#"haskell-main"	#"haskell-decl-file"	#"qos-aware-partitioning"
	#"qos-aware-routing"	#"qos-aware-where-scheduling"	#"qos-aware-when-scheduling
	outputRootDir = None,
	#"output-query-plan-dir"	#"output-nesc-dir"	
	debugExitOnError = None,
	measurementsActiveAgendaLoops = None,
	measurementsIgnoreIn = None,
	measurementsRemoveOperators = None,
	measurementsThinOperators = None,
	measurementsMultiAcquire = None,
	#"display-graphs"
	#"display-operator-properties"	#"display-sensornet-link-properties"	#"display-site-properties"
	#"display-config-graphs"
	displayCostExpressions = None,
	removeUnrequiredOperators = None,
	pushProjectionDown = None, 
	combineAcquireAndSelect = None,
	#"routing-random-seed"
	#"routing-trees-to-generate"	#"routing-trees-to-keep"	
	whereSchedulingRemoveRedundantExchanges = None,
	#"when-scheduling-decrease-bfactor-to-avoid-agenda-overlap" 
	targets = None,
	#"nesc-control-radio-off"	#"nesc-adjust-radio-power"	#"nesc-synchronization-period"
	#"nesc-power-management"
	nescDeliverLast = None,
	nescLedDebug = None, nescYellowExperiment = None, nescGreenExperiment = None,
	nescRedExperiment = None, qosAcquisitionInterval = None,
	#"qos-min-acquisition-interval"	#"qos-max-acquisition-interval"
	qosMaxDeliveryTime = None,
	#"qos-max-total-energy"	#"qos-min-lifetime"	
	qosBufferingFactor = None, qosMaxBufferingFactor = None):
	#"qos-query-duration"
	
	params = []
	#"iniFile"	#"evaluate-all-queries"	#"query-dir"		

	if (deleteOldFiles != None):
		params += ["-delete-old-files="+str(deleteOldFiles)]
	elif (optDeleteOldFiles != None):
		params += ["-delete-old-files="+str(optDeleteOldFiles)]
	
	queryDirStr = ""
	if (queryDir != None):
		queryDirStr = queryDir + "/"
	elif (optQueryDir != None):
		queryDirStr = optQueryDir + "/"

	if (query != None):
		params += ["-query="+UtilLib.winpath(queryDirStr+query+".txt")]
	elif (optQuery != None):
		params += ["-query="+UtilLib.winpath(queryDirStr+optQuery+".txt")]	
	
	#"sinks" #"qos-file" #"network-topology-file"
	
	if (sneeqlNetworkTopologyFile != None): 
		params+= ["-network-topology-file="+UtilLib.winpath(sneeqlNetworkTopologyFile)]
	elif (optSneeqlNetworkTopologyFile != None): 
		params+= ["-network-topology-file="+UtilLib.winpath(optSneeqlNetworkTopologyFile)]
	
	#"site-resource-file"	
	
	if schemaFile:
		params+= ["-schema-file="+schemaFile]
	elif optSchemaFile:
		params+= ["-schema-file="+optSchemaFile]

	if operatorMetadataFile:
		params+= ["-operator-metadata-file="+operatorMetadataFile]
	elif optOperatorMetadataFile:
		params+= ["-operator-metadata-file="+optOperatorMetadataFile]
	
	#"types-file"	
	if haskellUse:
		params+= ["-haskell-use="+str(haskellUse)]
	elif optHaskellUse:
		params+= ["-haskell-use="+str(optHaskellUse)]

	#"haskell-decl-dir"	#"haskell-main"	#"haskell-decl-file"	#"qos-aware-partitioning"
	#"qos-aware-routing"	#"qos-aware-where-scheduling"	#"qos-aware-when-scheduling
	
	if (outputRootDir != None):
		params+= ["-output-root-dir="+UtilLib.winpath(outputRootDir)]	
	elif (optOutputRootDir != None):
		params+= ["-output-root-dir="+UtilLib.winpath(optOutputRootDir)]	
	
	#"output-query-plan-dir"	#"output-nesc-dir"	
	

	if (debugExitOnError != None):
		params+= ["-debug-exit-on-error="+str(debugExitOnError).lower()]	
	elif (optDebugExitOnError != None):
		params+= ["-debug-exit-on-error="+str(optDebugExitOnError).lower()]	

	if (measurementsActiveAgendaLoops != None):
		if (measurementsActiveAgendaLoops >= 0):
			params+= ["-measurements-active-agenda-loops="+str(measurementsActiveAgendaLoops).lower()]	
		else:
			params+= ["-measurements-active-agenda-loops="+str(-measurementsActiveAgendaLoops).lower()]	
	elif (optMeasurementsActiveAgendaLoops != None):
		if (optMeasurementsActiveAgendaLoops >= 0):
			params+= ["-measurements-active-agenda-loops="+str(optMeasurementsActiveAgendaLoops).lower()]	
		else:	
			params+= ["-measurements-active-agenda-loops="+str(-optMeasurementsActiveAgendaLoops).lower()]	

	if (measurementsIgnoreIn != None):
		if (measurementsIgnoreIn != ""):
			params+= ["-measurements-ignore-in="+str(measurementsIgnoreIn).lower()]	
	elif (optMeasurementsIgnoreIn != None):
		if (optMeasurementsIgnoreIn != ""):
			params+= ["-measurements-ignore-in="+str(optMeasurementsIgnoreIn).lower()]	

	if (measurementsRemoveOperators != None):
		if (measurementsRemoveOperators != ""):
			params+= ["-measurements-remove-operators="+str(measurementsRemoveOperators).lower()]	
	elif (optMeasurementsRemoveOperators != None):
		if (optMeasurementsRemoveOperators != ""):
			params+= ["-measurements-remove-operators="+str(optMeasurementsRemoveOperators).lower()]	

	if (measurementsThinOperators != None):
		if (measurementsThinOperators != ""):
			params+= ["-measurements-thin-operators="+str(measurementsThinOperators).lower()]	
	elif (optMeasurementsThinOperators != None):
		if (optMeasurementsThinOperators != ""):
			params+= ["-measurements-thin-operators="+str(optMeasurementsThinOperators).lower()]	

	if (measurementsMultiAcquire != None):
		if (measurementsMultiAcquire >= 0):
			params+= ["-measurements-multi-acquire="+str(measurementsMultiAcquire)]	
	elif (optMeasurementsMultiAcquire!= None):
		if (optMeasurementsMultiAcquire >= 0):
			params+= ["-measurements-multi-acquire="+str(optMeasurementsMultiAcquire)]	

#"display-graphs"
	#"display-operator-properties"	#"display-sensornet-link-properties"	#"display-site-properties"
	#"display-config-graphs"	

	if (displayCostExpressions != None):
		params+= ["-display-cost-expressions="+str(displayCostExpressions).lower()]	
	elif (optDisplayCostExpressions != None):
		params+= ["-display-cost-expressions="+str(optDisplayCostExpressions).lower()]	

	if (removeUnrequiredOperators != None):
		params+= ["-remove-unrequired-operators="+str(removeUnrequiredOperators).lower()]	
	elif (optRemoveUnrequiredOperators != None):
		params+= ["-remove-unrequired-operators="+str(optRemoveUnrequiredOperators).lower()]	
		
	if (pushProjectionDown != None):
		params+= ["-push-projection-down="+str(pushProjectionDown).lower()]	
	elif (optPushProjectionDown != None):
		params+= ["-push-projection-down="+str(optPushProjectionDown).lower()]	
		
	if (combineAcquireAndSelect != None):
		params+= ["-combine-acquire-and-select="+str(combineAcquireAndSelect).lower()]	
	elif (optCombineAcquireAndSelect):
		params+= ["-combine-acquire-and-select="+str(optCombineAcquireAndSelect).lower()]	
		
	#"routing-random-seed"	#"routing-trees-to-generate"	#"routing-trees-to-keep"	
	if (whereSchedulingRemoveRedundantExchanges != None):
		params+= ["-where-scheduling-remove-redundant-exchanges="+str(whereSchedulingRemoveRedundantExchanges).lower()]	
	elif (optWhereSchedulingRemoveRedundantExchanges):
		params+= ["-where-scheduling-remove-redundant-exchanges="+str(optWhereSchedulingRemoveRedundantExchanges).lower()]
	
	#"when-scheduling-decrease-bfactor-to-avoid-agenda-overlap" 
	
	if (targets != None):
		params+= ["-targets="+str(targets).lower()]	
	elif (optTargets):
		params+= ["-targets="+str(optTargets).lower()]	
	
	#"nesc-control-radio-off"	#"nesc-adjust-radio-power"	#"nesc-synchronization-period"
	#"nesc-power-management"
	
	if (nescDeliverLast != None):
		params+= ["nesc-deliver-last="+str(nescDeliverLast).lower()]
	elif (optNescDeliverLast != None):
		params+= ["nesc-deliver-last="+str(optNescDeliverLast).lower()]	

	if (nescLedDebug != None):
		params+= ["-nesc-led-debug="+str(nescLedDebug).lower()]
	elif (optNescLedDebug != None):
		params+= ["-nesc-led-debug="+str(optNescLedDebug).lower()]
		
	if (nescYellowExperiment != None):
		params+= ["-nesc-yellow-experiment="+str(nescYellowExperiment).lower()]
	elif (optNescYellowExperiment != None):
		params+= ["-nesc-yellow-experiment="+str(optNescYellowExperiment).lower()]

	if (nescGreenExperiment != None):
		params+= ["-nesc-green-experiment="+str(nescGreedExperiment).lower()]
	elif (optNescGreenExperiment != None):
		params+= ["-nesc-green-experiment="+str(optNescGreenExperiment).lower()]

	if (nescRedExperiment != None):
		params+= ["-nesc-red-experiment="+str(nescRedExperiment).lower()]
	elif (optNescRedExperiment != None):
		params+= ["-nesc-red-experiment="+str(optNescRedExperiment).lower()]

	if (qosAcquisitionInterval != None):
		params+= ["-qos-acquisition-interval="+str(qosAcquisitionInterval)]
	elif (optQosAcquisitionInterval != None):
		params+= ["-qos-acquisition-interval="+str(optQosAcquisitionInterval)]
	
	#"qos-min-acquisition-interval"	#"qos-max-acquisition-interval"
	#"qos-max-delivery-time"	
	if (qosMaxDeliveryTime != None):
		params+= ["-qos-max-delivery-time="+str(qosMaxDeliveryTime)]
	elif (optQosMaxDeliveryTime != None):
		params+= ["-qos-max-delivery-time="+str(optQosMaxDeliveryTime)]	
	#"qos-max-total-energy"	#"qos-min-lifetime"	
	if (qosMaxBufferingFactor != None):
		params+= ["-qos-max-buffering-factor="+str(qosMaxBufferingFactor)]
	elif (optQosMaxBufferingFactor != None):
		params+= ["-qos-max-buffering-factor="+str(optMaxQosBufferingFactor)]
	
	if (qosBufferingFactor != None):
		params+= ["-qos-buffering-factor="+str(qosBufferingFactor)]
	elif (optQosBufferingFactor != None):
		params+= ["-qos-buffering-factor="+str(optQosBufferingFactor)]
	else:
		print optQosBufferingFactor
	#"qos-query-duration"
	
	return compileQueryParamStr (params, desc)			
예제 #35
0
	def get(self,zip=None,format='json'):
		#set content-type
		self.response.headers['Content-Type'] = Formatter.contentType(format)
		
		#validate zip
		if (not zip or zip == ''):
			self.response.out.write(Formatter.error(format, 'invalid zipcode'))
			return
	
		#get lat/lon from zipcode
		urlStr = 'http://maps.google.com/maps/geo?q=%s&output=json&sensor=true&key=%s' % (zip,AppConfig.googleMapsAPIKey)
		jsonData = UtilLib.reverseGeo(urlStr)	
		#lets see if have jsonData from reverse geocoding call
		if (jsonData):
			lon = jsonData['Placemark'][0]['Point']['coordinates'][0]
			lat = jsonData['Placemark'][0]['Point']['coordinates'][1]
			logging.debug("GPS Coordinates: %s,%s" % (lat,lon))
			gb = geobox2.Geobox(lat, lon)
			#scope 100 miles
			box = gb.search_geobox(100)
			query = HospitalInfo.all().filter("geoboxes IN", [box])
			#get 100 records
			results = query.fetch(100)
			db_recs = {}
			for result in results:
				distance = UtilLib.getEarthDistance(lat, lon, result.location.lat, result.location.lon)
				if (distance and distance > 0):
					db_recs[distance] = result
			
			returnData = MutableString()
			returnData = ''
					
			#output this badboy
			if (db_recs and len(db_recs) > 0):
				for key in sorted(db_recs.iterkeys()):
					p = db_recs[key]
					if (format == 'json'):
						startTag = '{'
						endTag = '},'
						distance = Formatter.data(format, 'distance', '%s %s' % (str(math.ceil(key)), "mi"))[:-1]#'%.2g %s' % (key, "mi"))[:-1]
					else:
						startTag = '<record>'
						endTag = '</record>'
						distance = Formatter.data(format, 'distance', '%s %s' % (str(math.ceil(key)), "mi"))
					#build the string	
					returnData = "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" % (returnData,startTag,
																Formatter.data(format, 'hospital_id', p.hospital_id),
																Formatter.data(format, 'name', p.name.replace('&', '&amp;')),
																Formatter.data(format, 'address', p.address.replace('&', '&amp;')),
																Formatter.data(format, 'city', p.city),
																Formatter.data(format, 'state', p.state),
																Formatter.data(format, 'zip_code', p.zip_code),
																Formatter.data(format, 'county', p.county.replace('&', '&amp;')),
																Formatter.data(format, 'phone', p.phone),
																Formatter.data(format, 'hospital_type', p.hospital_type.replace('&', '&amp;')),
																Formatter.data(format, 'hospital_owner', p.hospital_owner.replace('&', '&amp;')),
																Formatter.data(format, 'emergency_service', p.emergency_service),
																Formatter.data(format, 'geo_location', p.location),
																distance,
																endTag
																)
																 
			
			#output to the browser
			self.response.out.write(Formatter.dataWrapper(format, returnData))
		else:
			self.response.out.write(Formatter.error(format, 'Unable to perform reverse geoencoding'))
			return
예제 #36
0
	def get(self,geopt=None,format='json'):
		#set content-type
		self.response.headers['Content-Type'] = Formatter.contentType(format)
		
		#validate lat/lon
		if (not geopt or geopt == ''):
			self.response.out.write(Formatter.error(format, 'invalid GeoPoint'))
			return
	
		geoData = urllib.unquote(geopt).split(',')
		if (geoData and len(geoData) == 2):
			lon = geoData[1]
			lat = geoData[0]
			logging.debug("GPS Coordinates: %s,%s" % (lat,lon))
			gb = geobox2.Geobox(lat, lon)
			#scope 100 miles
			box = gb.search_geobox(100)
			query = HospitalInfo.all().filter("geoboxes IN", [box])
			#get 100 records
			results = query.fetch(100)
			db_recs = {}
			for result in results:
				distance = UtilLib.getEarthDistance(lat, lon, result.location.lat, result.location.lon)
				if (distance and distance > 0):
					db_recs[distance] = result
			
			returnData = MutableString()
			returnData = ''
					
			#output this badboy
			if (db_recs and len(db_recs) > 0):
				for key in sorted(db_recs.iterkeys()):
					p = db_recs[key]
					if (format == 'json'):
						startTag = '{'
						endTag = '},'
						distance = Formatter.data(format, 'distance', '%s %s' % (str(math.ceil(key)), "mi"))[:-1]#'%.2g %s' % (key, "mi"))[:-1]
					else:
						startTag = '<record>'
						endTag = '</record>'
						distance = Formatter.data(format, 'distance', '%s %s' % (str(math.ceil(key)), "mi"))
					#build the string	
					returnData = "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" % (returnData,startTag,
																Formatter.data(format, 'hospital_id', p.hospital_id),
																Formatter.data(format, 'name', p.name.replace('&', '&amp;')),
																Formatter.data(format, 'address', p.address.replace('&', '&amp;')),
																Formatter.data(format, 'city', p.city),
																Formatter.data(format, 'state', p.state),
																Formatter.data(format, 'zip_code', p.zip_code),
																Formatter.data(format, 'county', p.county.replace('&', '&amp;')),
																Formatter.data(format, 'phone', p.phone),
																Formatter.data(format, 'hospital_type', p.hospital_type.replace('&', '&amp;')),
																Formatter.data(format, 'hospital_owner', p.hospital_owner.replace('&', '&amp;')),
																Formatter.data(format, 'emergency_service', p.emergency_service),
																Formatter.data(format, 'geo_location', p.location),
																distance,
																endTag
																)
																 
			
			#output to the browser
			self.response.out.write(Formatter.dataWrapper(format, returnData))
		else:
			self.response.out.write(Formatter.error(format, 'Unable to retrieve lat/lon from received GeoPoint'))
			return