Commit 6435c2b758e7a967c37b89dade31f7963115217b
1 parent
a9f70deb
fix cuboid dimensions calculation, add NLat unit test
Showing
3 changed files
with
19 additions
and
8 deletions
Show diff stats
.codecov.yml
structure.py
... | ... | @@ -279,12 +279,12 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): |
279 | 279 | :param zSize: The Z dimension of the cuboid containing all the emitters (automatically computed if not specified) |
280 | 280 | ''' |
281 | 281 | minLoc = Location() |
282 | - minDist = xMax = yMax = zMax = 0.0 | |
282 | + minDist = 0.0 | |
283 | 283 | for k in data: |
284 | 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 | 288 | for k in arange(0.1,xSize,step): |
289 | 289 | for l in arange(0.1,ySize,step): |
290 | 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 | 294 | if d < minDist: |
295 | 295 | minDist = d |
296 | 296 | minLoc = Location(round(k,2),round(l,2),round(m,2)) |
297 | - return (minLoc, minDist) | |
298 | 297 | \ No newline at end of file |
298 | + return (minLoc, minDist) | |
299 | + | |
299 | 300 | \ No newline at end of file | ... | ... |
test_structure.py
1 | -from structure import KNeighbors, resolve_barycenter, Location, newCell, MarkovModel, RSSVector | |
1 | +from structure import KNeighbors, resolve_barycenter, Location, newCell, MarkovModel, RSSVector, NLateration | |
2 | 2 | from io import StringIO |
3 | 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 | 7 | Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ |
6 | 8 | [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ |
7 | 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 | 99 | assert len(output.out) > 2000 |
98 | 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 | 106 | class OutputBuffer(object): |
102 | 107 | |
103 | 108 | def __init__(self): | ... | ... |