From ef8923bcdd3ecd65c04b76e367cfcadbb47b81a7 Mon Sep 17 00:00:00 2001 From: HappyZ Date: Mon, 12 Feb 2018 13:53:29 -0500 Subject: [PATCH] little improvement --- libExtraction.py | 5 +++-- libLocalization.py | 21 ++++++++++++++------- libMeasurement.py | 12 ++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/libExtraction.py b/libExtraction.py index 2d52ab1..73624e1 100755 --- a/libExtraction.py +++ b/libExtraction.py @@ -36,9 +36,10 @@ def extract_each(fp): base = '_'.join(base.split('_')[:-1]) # remove time stamp t = int(time.time()) for mac in results: + identifier = mac.replace(':', '-') with open( - '{0}_{1}{2}' - .format(base, t, ext), 'w' + '{0}_extract_{1}_{2}{3}' + .format(base, identifier, t, ext), 'w' ) as f: f.write(nameLine) if startLine: diff --git a/libLocalization.py b/libLocalization.py index b9101c2..15b8c06 100755 --- a/libLocalization.py +++ b/libLocalization.py @@ -29,10 +29,17 @@ class Circle(object): def get_distance(p1, p2): - return math.sqrt( - (p1.x - p2.x) * (p1.x - p2.x) + - (p1.y - p2.y) * (p1.y - p2.y) - ) + if isinstance(p1, Point): + return math.sqrt( + (p1.x - p2.x) * (p1.x - p2.x) + + (p1.y - p2.y) * (p1.y - p2.y) + ) + elif isinstance(p1, list) or isinstance(p1, tuple): + return math.sqrt( + (p1[0] - p2[0]) * (p1[0] - p2[0]) + + (p1[1] - p2[1]) * (p1[1] - p2[1]) + ) + return -1 def get_two_circles_intersecting_points(c1, c2): @@ -164,8 +171,8 @@ def deriveLocation(args, results): bounds=args.get('loc_bounds', None), verbose=args.get('verbose', False) ) - if args.get('filepath', False): - with open("{0}_locs".format(args['filepath']), 'a') as f: + if args.get('outfp', False): + with open("{0}_locs".format(args['outfp']), 'a') as f: f.write( "{0:.6f},{1:.4f},{2:.4f}\n" .format(time.time(), loc[0], loc[1]) @@ -193,7 +200,7 @@ if __name__ == '__main__': '34:f6:4b:5e:69:1a': {'location': '1,2'} }, 'verbose': True, - 'filepath': '', + 'outfp': '', 'loc_bounds': { 'y_min': 0 } diff --git a/libMeasurement.py b/libMeasurement.py index 7734399..8bbacec 100755 --- a/libMeasurement.py +++ b/libMeasurement.py @@ -124,7 +124,7 @@ class Measurement(object): raw_distance = int(match.group(6)) raw_distance_var = int(match.group(7)) rssi = int(match.group(8)) - if status is not 0 or raw_distance < -1000: + if status is not 0 or raw_distance < -1000 or raw_distance > 10000: continue distance = self.cali[0] * raw_distance + self.cali[1] result.append( @@ -211,7 +211,7 @@ def wrapper(args): print('Cannot plot because lacking matplotlib!') with Measurement( args['interface'], - ofp=args['filepath'], cali=args['cali'] + ofp=args['outfp'], cali=args['cali'] ) as m: while 1: print('Round {0}'.format(counter)) @@ -264,7 +264,7 @@ def main(): help="calibrate calibration params (pre-defined outdoor by default)" ) p.add_argument( - '--filepath', '-f', + '--outfp', '-f', default=None, help="if set, will write raw fetched data to file" ) @@ -322,9 +322,9 @@ def main(): # TODO: add option to change loc bounds, currently force y_min = 0 args['loc_bounds'] = {'y_min': 0} # rename file path by adding time of exec - if args['filepath']: - fp, ext = os.path.splitext(args['filepath']) - args['filepath'] = "{0}_{1}{2}".format(fp, args['time_of_exec'], ext) + if args['outfp']: + fp, ext = os.path.splitext(args['outfp']) + args['outfp'] = "{0}_{1}{2}".format(fp, args['time_of_exec'], ext) wrapper(args)