Commit 6435c2b758e7a967c37b89dade31f7963115217b

Authored by Anthex
1 parent a9f70deb

fix cuboid dimensions calculation, add NLat unit test

Showing 3 changed files with 19 additions and 8 deletions   Show diff stats
1 ignore: 1 ignore:
2 - - "main.py"  
3 \ No newline at end of file 2 \ No newline at end of file
  3 + - "main.py"
  4 +
  5 +status:
  6 +project:
  7 + default:
  8 + target:90%
4 \ No newline at end of file 9 \ No newline at end of file
@@ -279,12 +279,12 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): @@ -279,12 +279,12 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0):
279 :param zSize: The Z dimension of the cuboid containing all the emitters (automatically computed if not specified) 279 :param zSize: The Z dimension of the cuboid containing all the emitters (automatically computed if not specified)
280 ''' 280 '''
281 minLoc = Location() 281 minLoc = Location()
282 - minDist = xMax = yMax = zMax = 0.0 282 + minDist = 0.0
283 for k in data: 283 for k in data:
284 minDist += abs(k[0].distanceTo(Location()) - k[1]) 284 minDist += abs(k[0].distanceTo(Location()) - k[1])
285 - xMax = k[0].x if k[0].x > xMax and not xSize else k[0].x  
286 - yMax = k[0].y if k[0].y > yMax and not ySize else k[0].y  
287 - zMax = k[0].z if k[0].z > zMax and not zSize else k[0].z 285 + xSize = k[0].x if k[0].x > xSize else xSize
  286 + ySize = k[0].y if k[0].y > ySize else ySize
  287 + zSize = k[0].z if k[0].z > zSize else zSize
288 for k in arange(0.1,xSize,step): 288 for k in arange(0.1,xSize,step):
289 for l in arange(0.1,ySize,step): 289 for l in arange(0.1,ySize,step):
290 for m in arange(0.1,zSize,step): 290 for m in arange(0.1,zSize,step):
@@ -294,4 +294,5 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): @@ -294,4 +294,5 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0):
294 if d < minDist: 294 if d < minDist:
295 minDist = d 295 minDist = d
296 minLoc = Location(round(k,2),round(l,2),round(m,2)) 296 minLoc = Location(round(k,2),round(l,2),round(m,2))
297 - return (minLoc, minDist)  
298 \ No newline at end of file 297 \ No newline at end of file
  298 + return (minLoc, minDist)
  299 +
299 \ No newline at end of file 300 \ No newline at end of file
1 -from structure import KNeighbors, resolve_barycenter, Location, newCell, MarkovModel, RSSVector 1 +from structure import KNeighbors, resolve_barycenter, Location, newCell, MarkovModel, RSSVector, NLateration
2 from io import StringIO 2 from io import StringIO
3 import sys 3 import sys
4 4
  5 +testEmitters = [(Location(.5,.5,.5), 3.0), (Location(4.0,.0,.0), 2.0), (Location(4.0,5.0,5.0), 4.2), (Location(3.0,3.0,3.0), 2.5)]
  6 +
5 Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ 7 Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\
6 [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ 8 [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \
7 [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]] 9 [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]]
@@ -97,7 +99,10 @@ def test_printPercentage(): @@ -97,7 +99,10 @@ def test_printPercentage():
97 assert len(output.out) > 2000 99 assert len(output.out) > 2000
98 print(len(output.out)) 100 print(len(output.out))
99 101
100 - 102 +def test_NLateration():
  103 + test_result = NLateration(testEmitters)
  104 + assert test_result[0] == Location(3.3, 1.5, 1.1)
  105 + assert round(test_result[1],2) == 1.19
101 class OutputBuffer(object): 106 class OutputBuffer(object):
102 107
103 def __init__(self): 108 def __init__(self):