Commit 99b882905f67e78f5630f299930f08ebe89c87c0

Authored by Anthex
1 parent 1d9d7a9c

fix styling according to spec

1 -  
2 -  
3 -  
4 [![Build Status](https://travis-ci.com/Anthex/LO53FP.svg?branch=master)](https://travis-ci.com/Anthex/LO53FP) [![codecov](https://codecov.io/gh/Anthex/LO53FP/branch/master/graph/badge.svg)](https://codecov.io/gh/Anthex/LO53FP) [![CodeFactor](https://www.codefactor.io/repository/github/anthex/lo53fp/badge)](https://www.codefactor.io/repository/github/anthex/lo53fp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b621fc832a894b1b81a9c240293f352d)](https://www.codacy.com/app/Anthex/LO53FP?utm_source=github.com&utm_medium=referral&utm_content=Anthex/LO53FP&utm_campaign=Badge_Grade) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 1 [![Build Status](https://travis-ci.com/Anthex/LO53FP.svg?branch=master)](https://travis-ci.com/Anthex/LO53FP) [![codecov](https://codecov.io/gh/Anthex/LO53FP/branch/master/graph/badge.svg)](https://codecov.io/gh/Anthex/LO53FP) [![CodeFactor](https://www.codefactor.io/repository/github/anthex/lo53fp/badge)](https://www.codefactor.io/repository/github/anthex/lo53fp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b621fc832a894b1b81a9c240293f352d)](https://www.codacy.com/app/Anthex/LO53FP?utm_source=github.com&utm_medium=referral&utm_content=Anthex/LO53FP&utm_campaign=Badge_Grade) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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 **Author** : Achille Dantz <achille@dantz.fr> 5 **Author** : Achille Dantz <achille@dantz.fr>
9 6
10 ## Description 7 ## Description
@@ -16,6 +13,5 @@ This program aims to compute the approximate location of a mobile terminal for a @@ -16,6 +13,5 @@ This program aims to compute the approximate location of a mobile terminal for a
16 13
17 ## Annex : N-Lateration 3D visualisation 14 ## Annex : N-Lateration 3D visualisation
18 visuals.py provides a cool function to graphically represent the N-Lateration distances in a 3D space by creating an animated gif (RMI style) 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 [Click here to view output gif example](https://dantz.fr/LO53/out.gif?) (too big to be displayed) 17 [Click here to view output gif example](https://dantz.fr/LO53/out.gif?) (too big to be displayed)
21 -  
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 from random import random 2 from random import random
3 from math import floor 3 from math import floor
4 4
@@ -35,7 +35,7 @@ def main(): @@ -35,7 +35,7 @@ def main():
35 print(a.toString()) 35 print(a.toString())
36 36
37 #### Markov #### 37 #### Markov ####
38 - MM = MarkovModel(Tf) 38 + MM = MarkovModel(Tf)
39 39
40 # small set fixed definition 40 # small set fixed definition
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]) 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,7 +50,7 @@ def main():
50 MM.printPercentages() 50 MM.printPercentages()
51 51
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") 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 while(1): 54 while(1):
55 print("Input next location ID (between 1 and 9)\r\n>>", end='') 55 print("Input next location ID (between 1 and 9)\r\n>>", end='')
56 in_char = int(input()) 56 in_char = int(input())
1 from operator import itemgetter as ig 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 from numpy import arange 3 from numpy import arange
4 class RSSVector(): 4 class RSSVector():
5 distances = [] 5 distances = []
@@ -30,7 +30,7 @@ class Location(): @@ -30,7 +30,7 @@ class Location():
30 30
31 def __mul__(self, multiplier): 31 def __mul__(self, multiplier):
32 returnValue = Location(self.x, self.y, self.z) 32 returnValue = Location(self.x, self.y, self.z)
33 - returnValue.x *= multiplier 33 + returnValue.x *= multiplier
34 returnValue.y *= multiplier 34 returnValue.y *= multiplier
35 returnValue.z *= multiplier 35 returnValue.z *= multiplier
36 return returnValue 36 return returnValue
@@ -117,14 +117,14 @@ class MarkovModel(): @@ -117,14 +117,14 @@ class MarkovModel():
117 self.MarkovValues.append([]) 117 self.MarkovValues.append([])
118 for _ in range (0, 10): 118 for _ in range (0, 10):
119 self.MarkovValues[i].append(MarkovValue()) 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 def moveToCellID(self, nextCell): 122 def moveToCellID(self, nextCell):
123 ''' 123 '''
124 Registers a movement from the current cell to a specified location by its ID 124 Registers a movement from the current cell to a specified location by its ID
125 :param nextCell: The ID of the new location 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 self.MarkovValues[10][nextCell].nb += 1 128 self.MarkovValues[10][nextCell].nb += 1
129 self.refreshPercentage(self.previousCell) 129 self.refreshPercentage(self.previousCell)
130 self.previousCell = nextCell 130 self.previousCell = nextCell
@@ -201,7 +201,7 @@ class MarkovModel(): @@ -201,7 +201,7 @@ class MarkovModel():
201 Returns the ID of the most likely next location with a given previous cell ID 201 Returns the ID of the most likely next location with a given previous cell ID
202 Typically called by getMostLikely() function 202 Typically called by getMostLikely() function
203 Convert to coordinates using the Location.fromID() function 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 :return: ID of the most likely next location 205 :return: ID of the most likely next location
206 ''' 206 '''
207 max_value=0 207 max_value=0
@@ -210,7 +210,7 @@ class MarkovModel(): @@ -210,7 +210,7 @@ class MarkovModel():
210 if self.MarkovValues[k][currentCell].nb > max_value: 210 if self.MarkovValues[k][currentCell].nb > max_value:
211 max_value = self.MarkovValues[k][currentCell].nb 211 max_value = self.MarkovValues[k][currentCell].nb
212 max_id = k 212 max_id = k
213 - return max_id 213 + return max_id
214 214
215 def path(self, locationIDs): 215 def path(self, locationIDs):
216 ''' 216 '''
@@ -233,8 +233,8 @@ def newCell(n1, n2, n3, n4, l1, l2): @@ -233,8 +233,8 @@ def newCell(n1, n2, n3, n4, l1, l2):
233 :return: Cell with given characteristics 233 :return: Cell with given characteristics
234 ''' 234 '''
235 return Cell(RSSVector(n1,n2,n3,n4), Location(l1,l2)) 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 Returns the 4 closest cells to the given sample and fills sample distance data 239 Returns the 4 closest cells to the given sample and fills sample distance data
240 :param fingerprints: 2D array of all the cells 240 :param fingerprints: 2D array of all the cells
@@ -247,7 +247,7 @@ def KNeighbors(fingerprints, sample): @@ -247,7 +247,7 @@ def KNeighbors(fingerprints, sample):
247 dist = abs(currentItem.v.n1 - sample.n1) \ 247 dist = abs(currentItem.v.n1 - sample.n1) \
248 + abs(currentItem.v.n2 - sample.n2) \ 248 + abs(currentItem.v.n2 - sample.n2) \
249 + abs(currentItem.v.n3 - sample.n3) \ 249 + abs(currentItem.v.n3 - sample.n3) \
250 - + abs(currentItem.v.n4 - sample.n4) 250 + + abs(currentItem.v.n4 - sample.n4)
251 distances.append((dist, currentItem)) 251 distances.append((dist, currentItem))
252 distances = sorted(distances, key=ig(0)) 252 distances = sorted(distances, key=ig(0))
253 sample.distances = [x[0] for x in distances][:4] 253 sample.distances = [x[0] for x in distances][:4]
@@ -266,7 +266,7 @@ def resolve_barycenter(nC, d): @@ -266,7 +266,7 @@ def resolve_barycenter(nC, d):
266 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3])*nC[0].location \ 266 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3])*nC[0].location \
267 + 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3])*nC[1].location \ 267 + 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3])*nC[1].location \
268 + 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3])*nC[2].location \ 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 def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): 272 def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0):
@@ -68,9 +68,9 @@ def test_getPositionInArray(): @@ -68,9 +68,9 @@ def test_getPositionInArray():
68 68
69 def test_fromID(): 69 def test_fromID():
70 test_loc = Location.fromID(3) 70 test_loc = Location.fromID(3)
71 - assert test_loc == Location(2,10) 71 + assert test_loc == Location(2,10)
72 test_loc = Location.fromID(9) 72 test_loc = Location.fromID(9)
73 - assert test_loc == Location(10,10) 73 + assert test_loc == Location(10,10)
74 74
75 def test_getModeLikely(): 75 def test_getModeLikely():
76 test_MM = MarkovModel(Tf) 76 test_MM = MarkovModel(Tf)
@@ -84,7 +84,7 @@ def test_getModeLikely(): @@ -84,7 +84,7 @@ def test_getModeLikely():
84 def test_printValues(): 84 def test_printValues():
85 test_MM = MarkovModel(Tf) 85 test_MM = MarkovModel(Tf)
86 test_MM.path([1,2,3,2,3,4,3,4]) 86 test_MM.path([1,2,3,2,3,4,3,4])
87 - 87 +
88 with OutputBuffer() as output: 88 with OutputBuffer() as output:
89 test_MM.printValues() 89 test_MM.printValues()
90 assert len(output.out) > 2500 90 assert len(output.out) > 2500
@@ -4,7 +4,7 @@ from PIL import Image @@ -4,7 +4,7 @@ from PIL import Image
4 4
5 def test_createFrame(): 5 def test_createFrame():
6 result = createFrame(100,100,1) 6 result = createFrame(100,100,1)
7 - assert type(result) is Image.Image 7 + assert isinstance(result, Image.Image)
8 8
9 def test_exportGif(): 9 def test_exportGif():
10 exportGif() 10 exportGif()
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 from PIL import Image, ImageDraw 3 from PIL import Image, ImageDraw
5 4
6 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)] 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)]