Skip to content
Snippets Groups Projects
Commit 9c7c4686 authored by Server (Shared Users)'s avatar Server (Shared Users)
Browse files

aa

parent 3ef67ca3
Branches
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ class CoAPServer(CoAP): ...@@ -36,6 +36,7 @@ class CoAPServer(CoAP):
while True: while True:
cursor = self.usersCollection.find() cursor = self.usersCollection.find()
for c in cursor: for c in cursor:
print(c['uuid'])
positionCalculationThread = threading.Thread(target = self.positionCalculation, args=([c['uuid']])) positionCalculationThread = threading.Thread(target = self.positionCalculation, args=([c['uuid']]))
positionCalculationThread.start() positionCalculationThread.start()
time.sleep(3.1) time.sleep(3.1)
...@@ -45,8 +46,9 @@ class CoAPServer(CoAP): ...@@ -45,8 +46,9 @@ class CoAPServer(CoAP):
print("existing updateUserLocation") print("existing updateUserLocation")
def positionCalculation(self, useruuid): def positionCalculation(self, useruuid):
print(useruuid)
currentTime = time.time() currentTime = time.time()
trackingCursor = self.trackingCollection.find({'$and':[{'useruuid':{'$eq' : useruuid}}, trackingCursor = self.trackingCollection.find({'$and':[{'useruuid': useruuid},
{'updateTime':{'$gt' : currentTime - 3}}]}) {'updateTime':{'$gt' : currentTime - 3}}]})
#trackingCursor = self.trackingCollection.find({'$and':[{'useruuid':{'$eq' : useruuid}}]}) #trackingCursor = self.trackingCollection.find({'$and':[{'useruuid':{'$eq' : useruuid}}]})
userLocationData =[] userLocationData =[]
...@@ -70,8 +72,11 @@ class CoAPServer(CoAP): ...@@ -70,8 +72,11 @@ class CoAPServer(CoAP):
flag = 0 flag = 0
userLocationData = sorted(userLocationData, key=lambda k: k['distance'], reverse = False) userLocationData = sorted(userLocationData, key=lambda k: k['distance'], reverse = False)
for u in userLocationData:
print(userLocationData)
if len(userLocationData) < 3: if len(userLocationData) < 3:
print("userLoicationData < 3")
return return
nodeList = [] nodeList = []
...@@ -86,6 +91,7 @@ class CoAPServer(CoAP): ...@@ -86,6 +91,7 @@ class CoAPServer(CoAP):
x, y = triangulationInst.doTriangulation() x, y = triangulationInst.doTriangulation()
if x == None: if x == None:
print("no solution")
return return
dd = datetime.datetime.now() dd = datetime.datetime.now()
......
...@@ -9,7 +9,7 @@ from coapthon.transaction import Transaction ...@@ -9,7 +9,7 @@ from coapthon.transaction import Transaction
__author__ = 'Giacomo Tanganelli' __author__ = 'Giacomo Tanganelli'
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.propagate = False
def str_append_hash(*args): def str_append_hash(*args):
""" Convert each argument to a lower case string, appended, then hash """ """ Convert each argument to a lower case string, appended, then hash """
......
...@@ -28,7 +28,7 @@ if not os.path.isfile("logging.conf"): ...@@ -28,7 +28,7 @@ if not os.path.isfile("logging.conf"):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.config.fileConfig("logging.conf", disable_existing_loggers=False) logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
logger.propagate = False
class CoAP(object): class CoAP(object):
""" """
......
...@@ -42,7 +42,7 @@ class RpNodeInfoResource(Resource): ...@@ -42,7 +42,7 @@ class RpNodeInfoResource(Resource):
return self, response return self, response
def postRpNodeInfoInDB(self, info): def postRpNodeInfoInDB(self, info):
info = info['myMAC'] info = info['rpMAC']
self.collection.delete_many({ 'rpMAC' : info }) self.collection.delete_many({ 'rpMAC' : info })
rpuuid = "52528282"+str(uuid.uuid4())[8:] rpuuid = "52528282"+str(uuid.uuid4())[8:]
rpuuid = rpuuid.replace("-","") rpuuid = rpuuid.replace("-","")
...@@ -89,15 +89,16 @@ class RpNodeInfoResource(Resource): ...@@ -89,15 +89,16 @@ class RpNodeInfoResource(Resource):
if tempdoc[0]['x'] == 0 and tempdoc[0]['y'] == 0: if tempdoc[0]['x'] == 0 and tempdoc[0]['y'] == 0:
vertexA = tempdoc[0] vertexA = tempdoc[0]
vertexB = tempdoc[0] vertexB = tempdoc[0]
#print("kkkkkkkkkkkkkkk", graphColletion.find({'v1': vertexB['rpuuid'], 'v2': info}) )
dis = { dis = {
'a': graphColletion.find({'v1': vertexB[0][rpuuid], 'v2': info})[0]['distance'], 'a': graphColletion.find({'v1': vertexB['rpuuid'], 'v2': info})[0]['distance'],
'b': graphColletion.find({'v1': vertexA[0][rpuuid], 'v2': info})[0]['distance'], 'b': graphColletion.find({'v1': vertexA['rpuuid'], 'v2': info})[0]['distance'],
'c': vertexB[0]['x'] 'c': vertexB['x']
} }
cosA = (math.pow(dis['b'], 2) + math.pow(dis['c'], 2) - math.pow(dis['a'], 2)) / (2 * dis['b'] * dis['c']) cosA = (math.pow(dis['b'], 2) + math.pow(dis['c'], 2) - math.pow(dis['a'], 2)) / (2 * dis['b'] * dis['c'])
sinA = math.sqrt((1 - math.pow(cosA,2))) sinA = math.sqrt((1 - math.pow(cosA,2)))
x = b * cosA x = dis['b'] * cosA
y = b * sinA y = dis['b'] * sinA
self.collection.update({'rpuuid' : info}, {'$set':{'x': x, 'y': y}}, False) self.collection.update({'rpuuid' : info}, {'$set':{'x': x, 'y': y}}, False)
else: else:
graphD = graphColletion.find({'v2' : info}) graphD = graphColletion.find({'v2' : info})
......
...@@ -24,11 +24,11 @@ console.log("aaaa") ...@@ -24,11 +24,11 @@ console.log("aaaa")
/* POST CreateNewUser page. */ /* POST CreateNewUser page. */
router.post('/CreateNewUser', function(req, res, next) { router.post('/CreateNewUser', function(req, res, next) {
var uuid = uuidv1() var uuid = uuidv1()
console.log(uuid.toString().replace(/-/gi, ""))
var user = new User({ var user = new User({
name: req.body.name, name: req.body.name,
aID: req.body.aID, aID: req.body.aID,
uuid:uuid uuid: uuid.toString().replace(/-/gi, "")
}); });
user.save(function(err, user){ user.save(function(err, user){
if(err) return console.error(err); if(err) return console.error(err);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment