From dfed0582056651004b7e84f877da850baf6640da Mon Sep 17 00:00:00 2001 From: uday Date: Thu, 5 Dec 2024 00:16:19 +0900 Subject: [PATCH] # bug changes --- .../FindNeighboursUsingEuclidean.py | 71 ++++++++++++------- .../neighbours/FindNeighboursUsingGeodesic.py | 22 +++--- 2 files changed, 57 insertions(+), 36 deletions(-) diff --git a/PAMI/extras/neighbours/FindNeighboursUsingEuclidean.py b/PAMI/extras/neighbours/FindNeighboursUsingEuclidean.py index 4a7f69fd..ba7ed15f 100644 --- a/PAMI/extras/neighbours/FindNeighboursUsingEuclidean.py +++ b/PAMI/extras/neighbours/FindNeighboursUsingEuclidean.py @@ -11,8 +11,6 @@ # - - __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -30,9 +28,11 @@ along with this program. If not, see . """ -import sys import re from math import sqrt +import time +import sys, psutil, os + class FindNeighboursUsingEuclidean: """ @@ -42,8 +42,6 @@ class FindNeighboursUsingEuclidean: :param iFile : file Input file name or path of the input file - :param oFile : file - Output file name or path pf the output file :param maxDist : int The user can specify maxEuclideanDistance. This program find pairs of values whose Euclidean distance is less than or equal to maxEucledianDistace @@ -69,22 +67,20 @@ class FindNeighboursUsingEuclidean: obj.save() """ - def __init__(self,iFile: str,oFile: str,maxDist: int, sep='\t') -> None: + def __init__(self, iFile: str, maxDist: int, sep='\t') -> None: self.iFile = iFile - self.oFile = oFile self.maxEucledianDistance = maxDist self.seperator = sep + self.result = {} - + def create(self): + self._startTime = time.time() coordinates = [] - result = {} - with open(self.iFile,"r") as f: + with open(self.iFile, "r") as f: for line in f: l = line.rstrip().split(self.seperator) - #print(l) l[0] = re.sub(r'[^0-9. ]', '', l[0]) coordinates.append(l[0].rstrip().split(' ')) - #print(l[0]) for i in range(len(coordinates)): for j in range(len(coordinates)): if i != j: @@ -94,26 +90,51 @@ def __init__(self,iFile: str,oFile: str,maxDist: int, sep='\t') -> None: y1 = float(firstCoordinate[1]) x2 = float(secondCoordinate[0]) y2 = float(secondCoordinate[1]) - ansX = x2-x1 - ansY = y2-y1 - dist = abs(pow(ansX,2) - pow(ansY,2)) + ansX = x2 - x1 + ansY = y2 - y1 + dist = abs(pow(ansX, 2) - pow(ansY, 2)) norm = sqrt(dist) if norm <= float(self.maxEucledianDistance): - result[tuple(firstCoordinate)] = result.get(tuple(firstCoordinate),[]) - result[tuple(firstCoordinate)].append(secondCoordinate) - - with open(self.oFile,"w+") as f: - for i in result: - string = "Point(" +i[0]+" "+i[1] + ")"+ self.seperator + self.result[tuple(firstCoordinate)] = self.result.get(tuple(firstCoordinate), []) + self.result[tuple(firstCoordinate)].append(secondCoordinate) + self._endTime = time.time() + + def save(oFile: str) -> None: + with open(oFile, "w+") as f: + for i in self.result: + string = "Point(" + i[0] + " " + i[1] + ")" + self.seperator f.write(string) - for j in result[i]: - string = "Point(" + j[0] + " " + j[1] + ")"+ self.seperator + for j in self.result[i]: + string = "Point(" + j[0] + " " + j[1] + ")" + self.seperator f.write(string) f.write("\n") + def getNeighbors(): + return self.result + + def getRuntime(self) -> float: + """ + Get the runtime of the transactional database + + :return: the runtime of the transactional database + + + :rtype: float + """ + return self._endTime - self._startTime + + def getMemoryUSS(self) -> float: + + process = psutil.Process(os.getpid()) + self._memoryUSS = process.memory_full_info().uss + return self._memoryUSS + + def getMemoryRSS(self) -> float: + + process = psutil.Process(os.getpid()) + self._memoryRSS = process.memory_info().rss + return self._memoryRSS - def getFileName(self) -> str: - return self.oFile if __name__ == "__main__": obj = FindNeighboursUsingEuclidean(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) diff --git a/PAMI/extras/neighbours/FindNeighboursUsingGeodesic.py b/PAMI/extras/neighbours/FindNeighboursUsingGeodesic.py index 4040961b..f5b56d29 100644 --- a/PAMI/extras/neighbours/FindNeighboursUsingGeodesic.py +++ b/PAMI/extras/neighbours/FindNeighboursUsingGeodesic.py @@ -32,7 +32,8 @@ import sys import re from geopy.distance import geodesic - +import time +import sys, psutil, os class FindNeighboursUsingGeodesic: """ @@ -70,14 +71,14 @@ class FindNeighboursUsingGeodesic: obj.save() """ - def __init__(self, iFile: str, oFile: str, maxDist: float, sep='\t'): + def __init__(self, iFile: str, maxDist: float, sep='\t'): self.iFile = iFile - self.oFile = oFile self.maxGeodesicDistance = maxDist self.seperator = sep + def create(self)->None: coordinates = [] - result = {} + self.result = {} with open(self.iFile, "r") as f: for line in f: l = line.rstrip().split(self.seperator) @@ -98,20 +99,19 @@ def __init__(self, iFile: str, oFile: str, maxDist: float, sep='\t'): dist = geodesic((lat1, long1), (lat2, long2)).kilometers if dist <= float(self.maxGeodesicDistance): - result[tuple(firstCoordinate)] = result.get(tuple(firstCoordinate), []) - result[tuple(firstCoordinate)].append(secondCoordinate) + self.result[tuple(firstCoordinate)] = self.result.get(tuple(firstCoordinate), []) + self.result[tuple(firstCoordinate)].append(secondCoordinate) - with open(self.oFile, "w+") as f: - for i in result: + def save(self,oFile:str)->None: + with open(oFile, "w+") as f: + for i in self.result: string = "Point(" + i[0] + " " + i[1] + ")" + self.seperator f.write(string) - for j in result[i]: + for j in self.result[i]: string = "Point(" + j[0] + " " + j[1] + ")" + self.seperator f.write(string) f.write("\n") - def getFileName(self): - return self.oFile if __name__ == "__main__":