From 417e1bef96f8f60201e0fd84b645d8aac00579d6 Mon Sep 17 00:00:00 2001 From: Anthex Date: Thu, 25 Apr 2019 16:25:00 +0200 Subject: [PATCH] small improvements --- main.py | 2 +- structure.py | 8 +++----- test_structure.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 3a32c7a..abb1a01 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel, MarkovValue +from structure import RSSVector, Location, Cell, newCell, KNeighbors, resolve_barycenter, MarkovModel from random import random from math import floor diff --git a/structure.py b/structure.py index 2a08e7d..e70bdc6 100644 --- a/structure.py +++ b/structure.py @@ -239,7 +239,7 @@ def KNeighbors(fingerprints, sample): :param sample: Mobile terminal sample :return: the 4 nearest cells ''' - distances, neighbours = [], [] + distances = [] for row in fingerprints: for currentItem in row: dist = abs(currentItem.v.n1 - sample.n1) \ @@ -248,10 +248,8 @@ def KNeighbors(fingerprints, sample): + abs(currentItem.v.n4 - sample.n4) distances.append((dist, currentItem)) distances = sorted(distances, key=ig(0)) - for k in range (0,4): - neighbours.append(distances[k][1]) - sample.distances.append(distances[k][0]) - return neighbours + sample.distances = [x[0] for x in distances][:4] + return [x[1] for x in distances][:4] diff --git a/test_structure.py b/test_structure.py index 36c2596..344a437 100644 --- a/test_structure.py +++ b/test_structure.py @@ -1,4 +1,4 @@ -from structure import * +from structure import KNeighbors, resolve_barycenter, Location, newCell, MarkovModel, RSSVector from io import StringIO import sys -- libgit2 0.21.4