コード例 #1
0
ファイル: test_structure.py プロジェクト: Anthex/LO53FP
def test_getPositionInArray():
    test_loc = Location(2, 2)
    assert test_loc.getPositionInArray() == 0
    test_loc = Location(2, 6)
    assert test_loc.getPositionInArray() == 1
    test_loc = Location(10, 10)
    assert test_loc.getPositionInArray() == 8
コード例 #2
0
ファイル: test_structure.py プロジェクト: Anthex/LO53FP
def test_Location():
    loc1 = Location(1, 2)
    loc2 = Location(3, 4)
    assert loc1 + loc2 == Location(4, 6)
    assert loc1 * 2 == Location(2, 4)
    loc2 -= Location(1, 1)
    assert loc2 == Location(2, 3)
    loc1 *= 3
    assert loc1 == Location(3, 6)
コード例 #3
0
def main():
    #### N-Lateration ####
    NLat_result = NLateration(dataset, step=1)
    printf("\r\nN-Lateration :\nComputed location : " +
           NLat_result[0].toString())
    printf("With distance = " + str(round(NLat_result[1], 2)) + " m")

    #### K neighbours ####
    printf("\nK-neighbors of test sample : ")
    neighborsCells = KNeighbors(Tf, testSample)
    for k in neighborsCells:
        printf("(", k.location.x, ";", k.location.y, ")")

    #### Distances ####
    print("\nDistances : " + str(testSample.distances))

    #### Barycenter ####
    printf("\r\nWeighted barycenter :")
    a = resolve_barycenter(neighborsCells, testSample.distances)
    printf(a.toString())

    #### Markov ####
    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
    ])

    # larger set random generation
    for k in range(0, 100):
        MM.moveToCellID(floor(random() * 9 + 1))

    printf("\r\n")
    MM.printValues()
    printf("\r\nPERCENTAGES : \r\n")
    MM.printPercentages()

    printf("\r\ncurrent cell is {output.GREEN}" + str(MM.previousCell) +
           "{output.NORMAL} , most likely next cell is {output.GREEN}" +
           str(MM.getMostLikely()) +
           "{output.NORMAL} which is located at {output.GREEN}" +
           str(Location.fromID(MM.getMostLikely()).toString()) +
           "{output.NORMAL}")

    while (1):
        printf("Input next location ID (between 1 and 9)\r\n>>", end='')
        in_char = int(input())
        printf(output.CLEAR)
        if in_char > 0 and in_char < 10:
            MM.moveToCellID(in_char)
            MM.printValues()
            printf("\r\nPERCENTAGES : \r\n")
            MM.printPercentages()
            printf(
                "\r\ncurrent cell is {output.GREEN}#" + str(MM.previousCell) +
                "{output.NORMAL} , most likely next cell is {output.GREEN}" +
                str(MM.getMostLikely()) +
                "{output.NORMAL} which is located at {output.GREEN}" +
                str(Location.fromID(MM.getMostLikely()).toString()) +
                "{output.NORMAL}")
        else:
            printf("invalid ID")
            break
コード例 #4
0
from structure import output, printf, RSSVector, Location, newCell, KNeighbors, resolve_barycenter, MarkovModel, NLateration
from random import random
from math import floor

Tf = []  #cells table

#dataset : list of tuples representing emitters (Location, distance)
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)]

testSample = RSSVector(-26, -42, -13, -46)

#known fingerprints
Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\
      [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \
      [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]]


def main():
    #### N-Lateration ####
    NLat_result = NLateration(dataset, step=1)
    printf("\r\nN-Lateration :\nComputed location : " +
           NLat_result[0].toString())
    printf("With distance = " + str(round(NLat_result[1], 2)) + " m")

    #### K neighbours ####
    printf("\nK-neighbors of test sample : ")
    neighborsCells = KNeighbors(Tf, testSample)
    for k in neighborsCells:
        printf("(", k.location.x, ";", k.location.y, ")")
コード例 #5
0
ファイル: test_structure.py プロジェクト: Anthex/LO53FP
def test_fromID():
    test_loc = Location.fromID(3)
    assert test_loc == Location(2, 10)
    test_loc = Location.fromID(9)
    assert test_loc == Location(10, 10)
コード例 #6
0
ファイル: test_structure.py プロジェクト: Anthex/LO53FP
def test_newCell():
    testCell = newCell(-38, -27, -54, -13, 2, 2)
    assert testCell.location == Location(2, 2)
    assert testCell.v == RSSVector(-38, -27, -54, -13)
コード例 #7
0
ファイル: test_structure.py プロジェクト: Anthex/LO53FP
def test_NLateration():
    test_result = NLateration(testEmitters)
    assert test_result[0] == Location(3.3, 1.5, 1.1)
    assert round(test_result[1], 2) == 1.19
コード例 #8
0
ファイル: test_structure.py プロジェクト: Anthex/LO53FP
from structure import KNeighbors, resolve_barycenter, Location, newCell, MarkovModel, RSSVector, NLateration
from io import StringIO
import sys

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)]

Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\
      [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \
      [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]]

testSample = RSSVector(-26, -42, -13, -46)
testCells = [Tf[0][2], Tf[2][1], Tf[1][0], Tf[2][0]]
testDistances = [34, 35, 53, 61]


def test_KNeighbors():
    assert KNeighbors(Tf, testSample)[0].location.toString() == "(2 ; 10 ; 0)"
    assert KNeighbors(Tf, testSample)[1].location.toString() == "(10 ; 6 ; 0)"
    assert KNeighbors(Tf, testSample)[2].location.toString() == "(6 ; 2 ; 0)"
    assert KNeighbors(Tf, testSample)[3].location.toString() == "(10 ; 2 ; 0)"


def test_resolve_barycenter():

    result = resolve_barycenter(testCells, testDistances)
    print(testSample.distances)
    assert round(result.x, 2) == 6.67
    assert round(result.y, 2) == 5.75

コード例 #9
0
print("Importing Libs")
from structure import NLateration, Location
from math import floor
from PIL import Image, ImageDraw
import sys
import time

global_step = .05
upscale_factor = 1
upscale_method = Image.NEAREST
dataset = [(Location(.5, .5, 0), 3.0), (Location(5.0, 7.0, .0), 4.0),
           (Location(3.0, .0, 5.0), 4)]
colorRange = 1.0  # [0.0, 1.0]
#NLat_result = NLateration(dataset, step=global_step)

frames = []
max = NLateration(dataset, step=global_step)


def createFrame(x, y, arr, nbr):
    img = Image.new("HSV", (y, x))
    img.putdata(arr[nbr])
    return img


def exportGif(includeReverse=False):
    print(
        str(round(1000 * (time.time() - start), 2)) + "ms",
        " - Calculating Array")
    NLat_result = NLateration(dataset,
                              step=global_step,