little improvement

This commit is contained in:
HappyZ 2018-02-12 13:53:29 -05:00
parent 2f59bb1b99
commit ef8923bcdd
3 changed files with 23 additions and 15 deletions

View File

@ -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:

View File

@ -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
}

View File

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