Exemplo n.º 1
0
def findSpots():
	''' find spots '''
	#print ("output!!")
	lat = request.args.get('lati')
	lon = request.args.get('longi')
	refresh = request.args.get('shouldRefresh', True, type=bool)
	userid = request.args.get('userid')
	parkingids = request.args.get('parkingids')
	spotsData = request.args.get('spotsData')
	parkingSpotRange = "500m"
	minimumNumOfSpots=2
	isNewSpotsFound = True
	
	#print lat
	#print lon
	#print refresh
	#print userid
	#print parkingids
	#print type(parkingids)
	parkingids=json.loads(parkingids)
	#print type(parkingids)
	#print parkingids
	##print len(parkingids)
	# if not userid:
	# 	return render_template("map.html",
 #        title = 'Home',
 #        mapbox=mapbox_token,
 #        error="Please enter a username"
 #        )
 	''' get spots for given location from search index'''
	if(parkingids is None or len(parkingids["ids"])<=minimumNumOfSpots):
		res= modelCont.getAvailableSpots(lat, lon, minimumNumOfSpots)
		#es_search_new_Spots(lat, lon, parkingSpotRange)
		##print res
		# if res[hits][total] == 0:
		# 	parkingSpotRange = "1000m"
		# 	res= es_search_new_Spots(lat, lon, parkingSpotRange)
		isNewSpotsFound=True
		global rdGenStart
		rdGenStart=True
	else:
		isNewSpotsFound=False
		#res = json.dumps(modelCont.updateSpots(parkingids["ids"]))
		'''for random traffic generator'''
		for id in parkingids["ids"]:
			rtgen.ids.append(id)
			if len(rtgen.ids) > 20:
				rtgen.ids.pop(0)
		global rdGenStart
		if rdGenStart:
			rtgen.main()
			rdGenStart=False
		res=modelCont.getUpdatedDocs(parkingids["ids"])

		##print type(res)
	#hits = res[hits][hits]
	#print "got es results"
	# if not refresh:

	# 	return render_template("output.html",lat=lat,lon=lon, res=json.dumps(res), uid=userid, mapbox= mapbox_token)
	# else:
	jsonResult = jsonify(lat=lat, lon=lon, res=res, uid=userid, mapbox=mapbox_token, newSpotsFound = isNewSpotsFound)
	return jsonResult
Exemplo n.º 2
0
def findSpots():

	#print ("output!!")
	lat = request.args.get('lati')
	lon = request.args.get('longi')
	refresh = request.args.get('shouldRefresh', True, type=bool)
	userid = request.args.get('userid')
	parkingids = request.args.get('parkingids')
	parkingSpotRange = "500m"
	isNewSpotsFound = True
	#print lat
	#print lon
	#print refresh
	#print userid
	#print parkingids
	#print type(parkingids)
	parkingids=json.loads(parkingids)
	#print type(parkingids)
	#print parkingids
	##print len(parkingids)
	# if not userid:
	# 	return render_template("map.html",
 #        title = 'Home',
 #        mapbox=mapbox_token,
 #        error="Please enter a username"
 #        )
	if(parkingids is None or len(parkingids["ids"])<=2):
		res= es_search_new_Spots(lat, lon, parkingSpotRange)
		##print res
		# if res[hits][total] == 0:
		# 	parkingSpotRange = "1000m"
		# 	res= es_search_new_Spots(lat, lon, parkingSpotRange)
		isNewSpotsFound=True
	else:
		idstosearch = []
		isNewSpotsFound=False
		
		#print ("len", len(parkingids["ids"]))
		for id in parkingids["ids"]:
			idstosearch.append(parkdoc_type+"#"+str(id))
			rtgen.ids.append(id)
			if len(rtgen.ids) > 20:
				rtgen.ids.pop(0)
		global rdGenStart
		if rdGenStart:
			rtgen.main()
			rdGenStart=False
		# sleepT = rtgen.sleeptime
		# rtgen.sleeptime=1
		# rtgen.ids=rtgen.ids.extend(parkingids["ids"])
		# rtgen.sleeptime= sleepT
		#print(idstosearch)
		res=es.search(index=parkindex, doc_type=parkdoc_type,
				body={
				  "query": {
				    "terms": {
				      "_uid": 
				        idstosearch
				      
				    }
				  }
				})

		##print type(res)
	#hits = res[hits][hits]
	#print "got es results"
	# if not refresh:

	# 	return render_template("output.html",lat=lat,lon=lon, res=json.dumps(res), uid=userid, mapbox= mapbox_token)
	# else:
	jsonResult = jsonify(lat=lat, lon=lon, res=res, uid=userid, mapbox=mapbox_token, newSpotsFound = isNewSpotsFound)
	return jsonResult