Commit 8e9d77cf9dd7f3c4ef6ec165ea5e03e10857fda1

Authored by Anthex
0 parents

Initial commit

Showing 4 changed files with 132 additions and 0 deletions   Show diff stats
.gitignore 0 → 100644
  1 +++ a/.gitignore
  1 +__pycache__/
  2 +*.pyc
... ...
README.mk 0 → 100644
  1 +++ a/README.mk
  1 +[UTBM - LO53] - Python fingerprinting
  2 +Achille Dantz <achille@dantz.fr>
  3 +
  4 +This program aims to compute the approximate location of a mobile terminal for a known set of Wi-Fi accesspoints in an ideal 12x12m space for which we have 9 fingerprinting values (known RSSI for each accesspoint at a given location)
... ...
main.py 0 → 100644
  1 +++ a/main.py
  1 +
  2 +from structure import *
  3 +import sys
  4 +
  5 +Tf = [] #cells table
  6 +testSample = RSSVector(-26, -42, -13, -46)
  7 +
  8 +
  9 +#cells Table initialization
  10 +for i in range (0, 3):
  11 + Tf.append([])
  12 + for k in range (0,3):
  13 + Tf[i].append([])
  14 +
  15 +Tf[0][0] = Cell(RSSVector(-38,-27,-54,-13), Location(2,2))
  16 +Tf[0][1] = Cell(RSSVector(-74,-62,-48,-33), Location(2,6))
  17 +Tf[0][2] = Cell(RSSVector(-13,-28,-12,-40), Location(2,10))
  18 +Tf[1][0] = Cell(RSSVector(-34,-27,-38,-41), Location(6,2))
  19 +Tf[1][1] = Cell(RSSVector(-64,-48,-72,-35), Location(6,6))
  20 +Tf[1][2] = Cell(RSSVector(-45,-37,-20,-15), Location(6,10))
  21 +Tf[2][0] = Cell(RSSVector(-17,-50,-44,-33), Location(10,2))
  22 +Tf[2][1] = Cell(RSSVector(-27,-28,-32,-45), Location(10,6))
  23 +Tf[2][2] = Cell(RSSVector(-30,-20,-60,-40), Location(10,10))
  24 +
  25 +def main(args):
  26 +
  27 + print(Tf[1][1].v.n2)
  28 +
  29 +
  30 + print("\nk neighbors of test sample : ")
  31 + neighborsCells = KNeighbors(Tf, testSample)
  32 + for k in neighborsCells:
  33 + print("(", k.location.x, ";", k.location.y, ")")
  34 +
  35 + print ("\ndistances : " + str(testSample.distances))
  36 +
  37 + testLoc = Location(3,4,5)
  38 + loc2 = Location(1,2,3)
  39 + print((testLoc+loc2).toString())
  40 +
  41 + a = resolve_barycenter(neighborsCells, testSample)
  42 + print(a.toString)
  43 + return 0;
  44 +
  45 +
  46 +main(sys.argv)
0 47 \ No newline at end of file
... ...
structure.py 0 → 100644
  1 +++ a/structure.py
  1 +from operator import itemgetter
  2 +
  3 +class RSSVector():
  4 + distances = []
  5 + def __init__(self, n1, n2, n3, n4):
  6 + self.n1 = n1
  7 + self.n2 = n2
  8 + self.n3 = n3
  9 + self.n4 = n4
  10 +
  11 +class Location():
  12 + def __init(self):
  13 + self.x = self.y = self.z = 0
  14 +
  15 + def __init__(self, x, y, z=0):
  16 + self.x = x
  17 + self.y = y
  18 + self.z = z
  19 +
  20 + def __mul__(self, multiplier):
  21 + returnValue = Location(self.x, self.y, self.z)
  22 + returnValue.x *= multiplier
  23 + returnValue.y *= multiplier
  24 + returnValue.z *= multiplier
  25 + return returnValue
  26 + def __rmul__(self, multiplier):
  27 + return self * multiplier
  28 +
  29 + def __add__(self, added):
  30 + returnValue = Location(self.x, self.y, self.z)
  31 + returnValue.x += added.x
  32 + returnValue.y += added.y
  33 + returnValue.z += added.z
  34 + return returnValue
  35 +
  36 + def toString(self):
  37 + return "(" + str(self.x) + " ; " + str(self.y) + " ; " + str(self.z) + ")"
  38 +
  39 +
  40 +class Cell():
  41 + def __init__(self, v_, loc):
  42 + self.v = v_
  43 + self.location = loc
  44 +
  45 +
  46 +def KNeighbors(fingerprints, sample):
  47 + '''
  48 + Returns the 4 closest cells to the given sample and fills sample distance data
  49 + :param Cell[3][3] fingerprints: 2D array of all the cells
  50 + :param RSSIVector sample: Mobile terminal sample
  51 + :return Cell[4]: the 4 nearest cells
  52 + '''
  53 + distances = []
  54 + for row in fingerprints:
  55 + for currentItem in row:
  56 + dist = abs(currentItem.v.n1 - sample.n1) \
  57 + + abs(currentItem.v.n2 - sample.n2) \
  58 + + abs(currentItem.v.n3 - sample.n3) \
  59 + + abs(currentItem.v.n4 - sample.n4)
  60 + distances.append((dist, currentItem))
  61 + distances = sorted(distances, key=itemgetter(0))
  62 + neighbours = []
  63 + for k in range (0,4):
  64 + neighbours.append(distances[k][1])
  65 + sample.distances.append(distances[k][0])
  66 + return neighbours
  67 +
  68 +
  69 +
  70 +def resolve_barycenter(neighbourCells, sample):
  71 + '''
  72 + Returns the weighted barycenter of the 4 neighbouring cells
  73 + :param Cell[4] neighbourCells: Array containing the 4 closest cells
  74 + :param RSSIVector sample: Sample of the mobile terminal
  75 + :return Location: Estimated location of the mobile terminal
  76 + '''
  77 + d = sample.distances #shorter notation
  78 + a1,a2,a3,a4 = 1 / (1+d[0]/d[1]+d[0]/d[2]+d[0]/d[3]), 1 / (1+d[1]/d[0]+d[1]/d[2]+d[1]/d[3]), 1 / (1+d[2]/d[1]+d[2]/d[0]+d[2]/d[3]), 1 / (1+d[3]/d[1]+d[3]/d[2]+d[3]/d[0])
  79 + return a1*neighbourCells[0].location + a2*neighbourCells[1].location + a3*neighbourCells[1].location + a4*neighbourCells[1].location
  80 +
0 81 \ No newline at end of file
... ...