Commit 99b882905f67e78f5630f299930f08ebe89c87c0
1 parent
1d9d7a9c
fix styling according to spec
Showing
6 changed files
with
22 additions
and
27 deletions
Show diff stats
README.md
1 | - | |
2 | - | |
3 | - | |
4 | 1 | [](https://travis-ci.com/Anthex/LO53FP) [](https://codecov.io/gh/Anthex/LO53FP) [](https://www.codefactor.io/repository/github/anthex/lo53fp) [](https://www.codacy.com/app/Anthex/LO53FP?utm_source=github.com&utm_medium=referral&utm_content=Anthex/LO53FP&utm_campaign=Badge_Grade) [](https://opensource.org/licenses/MIT) |
5 | 2 | |
6 | -# [UTBM - LO53] - Python fingerprinting | |
7 | -**Documentation** : https://dantz.fr/LO53/structure.html | |
3 | +# UTBM - LO53 : Python fingerprinting | |
4 | +**Documentation** : [dantz.fr/LO53/structure.html](https://dantz.fr/LO53/structure.html) or _Documentation.md_ | |
8 | 5 | **Author** : Achille Dantz <achille@dantz.fr> |
9 | 6 | |
10 | 7 | ## Description |
... | ... | @@ -16,6 +13,5 @@ This program aims to compute the approximate location of a mobile terminal for a |
16 | 13 | |
17 | 14 | ## Annex : N-Lateration 3D visualisation |
18 | 15 | visuals.py provides a cool function to graphically represent the N-Lateration distances in a 3D space by creating an animated gif (RMI style) |
19 | -### Example : | |
16 | +### Example | |
20 | 17 | [Click here to view output gif example](https://dantz.fr/LO53/out.gif?) (too big to be displayed) |
21 | - | ... | ... |
main.py
1 | -from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration | |
1 | +from structure import RSSVector, Location, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration | |
2 | 2 | from random import random |
3 | 3 | from math import floor |
4 | 4 | |
... | ... | @@ -35,7 +35,7 @@ def main(): |
35 | 35 | print(a.toString()) |
36 | 36 | |
37 | 37 | #### Markov #### |
38 | - MM = MarkovModel(Tf) | |
38 | + MM = MarkovModel(Tf) | |
39 | 39 | |
40 | 40 | # small set fixed definition |
41 | 41 | MM.path([8,7,8,7,8,7,8,5,8,2,9,8,1,9,8,9,5,4,3,2,3,2,4,5,4,5,6,6,7,6,9,5,9,3,2,4,3,5,3,4,3,3,5,6,7,6,7,6,5,4,3,4,3,4]) |
... | ... | @@ -50,7 +50,7 @@ def main(): |
50 | 50 | MM.printPercentages() |
51 | 51 | |
52 | 52 | print("\r\ncurrent cell is \033[1;32;40m#" + str(MM.previousCell) + "\033[1;37;40m , most likely next cell is \033[1;32;40m#" + str(MM.getMostLikely()) + "\033[1;37;40m which is located at \033[1;32;40m" + str(Location.fromID(MM.getMostLikely()).toString()) + "\033[1;37;40m") |
53 | - | |
53 | + | |
54 | 54 | while(1): |
55 | 55 | print("Input next location ID (between 1 and 9)\r\n>>", end='') |
56 | 56 | in_char = int(input()) | ... | ... |
structure.py
1 | 1 | from operator import itemgetter as ig |
2 | -from math import floor, sqrt, ceil, log, exp | |
2 | +from math import floor, sqrt, ceil, exp | |
3 | 3 | from numpy import arange |
4 | 4 | class RSSVector(): |
5 | 5 | distances = [] |
... | ... | @@ -30,7 +30,7 @@ class Location(): |
30 | 30 | |
31 | 31 | def __mul__(self, multiplier): |
32 | 32 | returnValue = Location(self.x, self.y, self.z) |
33 | - returnValue.x *= multiplier | |
33 | + returnValue.x *= multiplier | |
34 | 34 | returnValue.y *= multiplier |
35 | 35 | returnValue.z *= multiplier |
36 | 36 | return returnValue |
... | ... | @@ -117,14 +117,14 @@ class MarkovModel(): |
117 | 117 | self.MarkovValues.append([]) |
118 | 118 | for _ in range (0, 10): |
119 | 119 | self.MarkovValues[i].append(MarkovValue()) |
120 | - self.MarkovValues[10][0].nb = 1 #initial position sigma increment | |
120 | + self.MarkovValues[10][0].nb = 1 #initial position sigma increment | |
121 | 121 | |
122 | 122 | def moveToCellID(self, nextCell): |
123 | 123 | ''' |
124 | 124 | Registers a movement from the current cell to a specified location by its ID |
125 | 125 | :param nextCell: The ID of the new location |
126 | 126 | ''' |
127 | - self.MarkovValues[nextCell][self.previousCell].nb += 1 | |
127 | + self.MarkovValues[nextCell][self.previousCell].nb += 1 | |
128 | 128 | self.MarkovValues[10][nextCell].nb += 1 |
129 | 129 | self.refreshPercentage(self.previousCell) |
130 | 130 | self.previousCell = nextCell |
... | ... | @@ -201,7 +201,7 @@ class MarkovModel(): |
201 | 201 | Returns the ID of the most likely next location with a given previous cell ID |
202 | 202 | Typically called by getMostLikely() function |
203 | 203 | Convert to coordinates using the Location.fromID() function |
204 | - :param currentCell: ID of the last cell | |
204 | + :param currentCell: ID of the last cell | |
205 | 205 | :return: ID of the most likely next location |
206 | 206 | ''' |
207 | 207 | max_value=0 |
... | ... | @@ -210,7 +210,7 @@ class MarkovModel(): |
210 | 210 | if self.MarkovValues[k][currentCell].nb > max_value: |
211 | 211 | max_value = self.MarkovValues[k][currentCell].nb |
212 | 212 | max_id = k |
213 | - return max_id | |
213 | + return max_id | |
214 | 214 | |
215 | 215 | def path(self, locationIDs): |
216 | 216 | ''' |
... | ... | @@ -233,8 +233,8 @@ def newCell(n1, n2, n3, n4, l1, l2): |
233 | 233 | :return: Cell with given characteristics |
234 | 234 | ''' |
235 | 235 | return Cell(RSSVector(n1,n2,n3,n4), Location(l1,l2)) |
236 | - | |
237 | -def KNeighbors(fingerprints, sample): | |
236 | + | |
237 | +def KNeighbors(fingerprints, sample): | |
238 | 238 | ''' |
239 | 239 | Returns the 4 closest cells to the given sample and fills sample distance data |
240 | 240 | :param fingerprints: 2D array of all the cells |
... | ... | @@ -247,7 +247,7 @@ def KNeighbors(fingerprints, sample): |
247 | 247 | dist = abs(currentItem.v.n1 - sample.n1) \ |
248 | 248 | + abs(currentItem.v.n2 - sample.n2) \ |
249 | 249 | + abs(currentItem.v.n3 - sample.n3) \ |
250 | - + abs(currentItem.v.n4 - sample.n4) | |
250 | + + abs(currentItem.v.n4 - sample.n4) | |
251 | 251 | distances.append((dist, currentItem)) |
252 | 252 | distances = sorted(distances, key=ig(0)) |
253 | 253 | sample.distances = [x[0] for x in distances][:4] |
... | ... | @@ -266,7 +266,7 @@ def resolve_barycenter(nC, d): |
266 | 266 | 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3])*nC[0].location \ |
267 | 267 | + 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3])*nC[1].location \ |
268 | 268 | + 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3])*nC[2].location \ |
269 | - + 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0])*nC[3].location | |
269 | + + 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0])*nC[3].location | |
270 | 270 | |
271 | 271 | |
272 | 272 | def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): | ... | ... |
test_structure.py
... | ... | @@ -68,9 +68,9 @@ def test_getPositionInArray(): |
68 | 68 | |
69 | 69 | def test_fromID(): |
70 | 70 | test_loc = Location.fromID(3) |
71 | - assert test_loc == Location(2,10) | |
71 | + assert test_loc == Location(2,10) | |
72 | 72 | test_loc = Location.fromID(9) |
73 | - assert test_loc == Location(10,10) | |
73 | + assert test_loc == Location(10,10) | |
74 | 74 | |
75 | 75 | def test_getModeLikely(): |
76 | 76 | test_MM = MarkovModel(Tf) |
... | ... | @@ -84,7 +84,7 @@ def test_getModeLikely(): |
84 | 84 | def test_printValues(): |
85 | 85 | test_MM = MarkovModel(Tf) |
86 | 86 | test_MM.path([1,2,3,2,3,4,3,4]) |
87 | - | |
87 | + | |
88 | 88 | with OutputBuffer() as output: |
89 | 89 | test_MM.printValues() |
90 | 90 | assert len(output.out) > 2500 | ... | ... |
test_visuals.py
visuals.py
1 | -from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration | |
2 | -from random import random | |
3 | -from math import floor, sqrt, ceil | |
1 | +from structure import NLateration, Location | |
2 | +from math import floor, sqrt | |
4 | 3 | from PIL import Image, ImageDraw |
5 | 4 | |
6 | 5 | dataset = [(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)] | ... | ... |