From 99b882905f67e78f5630f299930f08ebe89c87c0 Mon Sep 17 00:00:00 2001 From: Anthex Date: Fri, 26 Apr 2019 23:31:47 +0200 Subject: [PATCH] fix styling according to spec --- README.md | 10 +++------- main.py | 6 +++--- structure.py | 20 ++++++++++---------- test_structure.py | 6 +++--- test_visuals.py | 2 +- visuals.py | 5 ++--- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b85c049..b203766 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ - - - [![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) -# [UTBM - LO53] - Python fingerprinting -**Documentation** : https://dantz.fr/LO53/structure.html +# UTBM - LO53 : Python fingerprinting +**Documentation** : [dantz.fr/LO53/structure.html](https://dantz.fr/LO53/structure.html) or _Documentation.md_ **Author** : Achille Dantz ## Description @@ -16,6 +13,5 @@ This program aims to compute the approximate location of a mobile terminal for a ## Annex : N-Lateration 3D visualisation visuals.py provides a cool function to graphically represent the N-Lateration distances in a 3D space by creating an animated gif (RMI style) -### Example : +### Example [Click here to view output gif example](https://dantz.fr/LO53/out.gif?) (too big to be displayed) - diff --git a/main.py b/main.py index f9fa9eb..693e09a 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration +from structure import RSSVector, Location, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration from random import random from math import floor @@ -35,7 +35,7 @@ def main(): print(a.toString()) #### Markov #### - MM = MarkovModel(Tf) + MM = MarkovModel(Tf) # small set fixed definition 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(): MM.printPercentages() 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") - + while(1): print("Input next location ID (between 1 and 9)\r\n>>", end='') in_char = int(input()) diff --git a/structure.py b/structure.py index 3f06356..75a97b5 100644 --- a/structure.py +++ b/structure.py @@ -1,5 +1,5 @@ from operator import itemgetter as ig -from math import floor, sqrt, ceil, log, exp +from math import floor, sqrt, ceil, exp from numpy import arange class RSSVector(): distances = [] @@ -30,7 +30,7 @@ class Location(): def __mul__(self, multiplier): returnValue = Location(self.x, self.y, self.z) - returnValue.x *= multiplier + returnValue.x *= multiplier returnValue.y *= multiplier returnValue.z *= multiplier return returnValue @@ -117,14 +117,14 @@ class MarkovModel(): self.MarkovValues.append([]) for _ in range (0, 10): self.MarkovValues[i].append(MarkovValue()) - self.MarkovValues[10][0].nb = 1 #initial position sigma increment + self.MarkovValues[10][0].nb = 1 #initial position sigma increment def moveToCellID(self, nextCell): ''' Registers a movement from the current cell to a specified location by its ID :param nextCell: The ID of the new location ''' - self.MarkovValues[nextCell][self.previousCell].nb += 1 + self.MarkovValues[nextCell][self.previousCell].nb += 1 self.MarkovValues[10][nextCell].nb += 1 self.refreshPercentage(self.previousCell) self.previousCell = nextCell @@ -201,7 +201,7 @@ class MarkovModel(): Returns the ID of the most likely next location with a given previous cell ID Typically called by getMostLikely() function Convert to coordinates using the Location.fromID() function - :param currentCell: ID of the last cell + :param currentCell: ID of the last cell :return: ID of the most likely next location ''' max_value=0 @@ -210,7 +210,7 @@ class MarkovModel(): if self.MarkovValues[k][currentCell].nb > max_value: max_value = self.MarkovValues[k][currentCell].nb max_id = k - return max_id + return max_id def path(self, locationIDs): ''' @@ -233,8 +233,8 @@ def newCell(n1, n2, n3, n4, l1, l2): :return: Cell with given characteristics ''' return Cell(RSSVector(n1,n2,n3,n4), Location(l1,l2)) - -def KNeighbors(fingerprints, sample): + +def KNeighbors(fingerprints, sample): ''' Returns the 4 closest cells to the given sample and fills sample distance data :param fingerprints: 2D array of all the cells @@ -247,7 +247,7 @@ def KNeighbors(fingerprints, sample): dist = abs(currentItem.v.n1 - sample.n1) \ + abs(currentItem.v.n2 - sample.n2) \ + abs(currentItem.v.n3 - sample.n3) \ - + abs(currentItem.v.n4 - sample.n4) + + abs(currentItem.v.n4 - sample.n4) distances.append((dist, currentItem)) distances = sorted(distances, key=ig(0)) sample.distances = [x[0] for x in distances][:4] @@ -266,7 +266,7 @@ def resolve_barycenter(nC, d): 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3])*nC[0].location \ + 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3])*nC[1].location \ + 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3])*nC[2].location \ - + 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0])*nC[3].location + + 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0])*nC[3].location def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): diff --git a/test_structure.py b/test_structure.py index a5fb770..9581a4e 100644 --- a/test_structure.py +++ b/test_structure.py @@ -68,9 +68,9 @@ def test_getPositionInArray(): def test_fromID(): test_loc = Location.fromID(3) - assert test_loc == Location(2,10) + assert test_loc == Location(2,10) test_loc = Location.fromID(9) - assert test_loc == Location(10,10) + assert test_loc == Location(10,10) def test_getModeLikely(): test_MM = MarkovModel(Tf) @@ -84,7 +84,7 @@ def test_getModeLikely(): def test_printValues(): test_MM = MarkovModel(Tf) test_MM.path([1,2,3,2,3,4,3,4]) - + with OutputBuffer() as output: test_MM.printValues() assert len(output.out) > 2500 diff --git a/test_visuals.py b/test_visuals.py index 1c2e1c4..bd369ab 100644 --- a/test_visuals.py +++ b/test_visuals.py @@ -4,7 +4,7 @@ from PIL import Image def test_createFrame(): result = createFrame(100,100,1) - assert type(result) is Image.Image + assert isinstance(result, Image.Image) def test_exportGif(): exportGif() diff --git a/visuals.py b/visuals.py index 10a1073..e8f7b85 100644 --- a/visuals.py +++ b/visuals.py @@ -1,6 +1,5 @@ -from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration -from random import random -from math import floor, sqrt, ceil +from structure import NLateration, Location +from math import floor, sqrt from PIL import Image, ImageDraw 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)] -- libgit2 0.21.4