little improvement
This commit is contained in:
parent
2f59bb1b99
commit
ef8923bcdd
|
|
@ -36,9 +36,10 @@ def extract_each(fp):
|
||||||
base = '_'.join(base.split('_')[:-1]) # remove time stamp
|
base = '_'.join(base.split('_')[:-1]) # remove time stamp
|
||||||
t = int(time.time())
|
t = int(time.time())
|
||||||
for mac in results:
|
for mac in results:
|
||||||
|
identifier = mac.replace(':', '-')
|
||||||
with open(
|
with open(
|
||||||
'{0}_{1}{2}'
|
'{0}_extract_{1}_{2}{3}'
|
||||||
.format(base, t, ext), 'w'
|
.format(base, identifier, t, ext), 'w'
|
||||||
) as f:
|
) as f:
|
||||||
f.write(nameLine)
|
f.write(nameLine)
|
||||||
if startLine:
|
if startLine:
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,17 @@ class Circle(object):
|
||||||
|
|
||||||
|
|
||||||
def get_distance(p1, p2):
|
def get_distance(p1, p2):
|
||||||
|
if isinstance(p1, Point):
|
||||||
return math.sqrt(
|
return math.sqrt(
|
||||||
(p1.x - p2.x) * (p1.x - p2.x) +
|
(p1.x - p2.x) * (p1.x - p2.x) +
|
||||||
(p1.y - p2.y) * (p1.y - p2.y)
|
(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):
|
def get_two_circles_intersecting_points(c1, c2):
|
||||||
|
|
@ -164,8 +171,8 @@ def deriveLocation(args, results):
|
||||||
bounds=args.get('loc_bounds', None),
|
bounds=args.get('loc_bounds', None),
|
||||||
verbose=args.get('verbose', False)
|
verbose=args.get('verbose', False)
|
||||||
)
|
)
|
||||||
if args.get('filepath', False):
|
if args.get('outfp', False):
|
||||||
with open("{0}_locs".format(args['filepath']), 'a') as f:
|
with open("{0}_locs".format(args['outfp']), 'a') as f:
|
||||||
f.write(
|
f.write(
|
||||||
"{0:.6f},{1:.4f},{2:.4f}\n"
|
"{0:.6f},{1:.4f},{2:.4f}\n"
|
||||||
.format(time.time(), loc[0], loc[1])
|
.format(time.time(), loc[0], loc[1])
|
||||||
|
|
@ -193,7 +200,7 @@ if __name__ == '__main__':
|
||||||
'34:f6:4b:5e:69:1a': {'location': '1,2'}
|
'34:f6:4b:5e:69:1a': {'location': '1,2'}
|
||||||
},
|
},
|
||||||
'verbose': True,
|
'verbose': True,
|
||||||
'filepath': '',
|
'outfp': '',
|
||||||
'loc_bounds': {
|
'loc_bounds': {
|
||||||
'y_min': 0
|
'y_min': 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ class Measurement(object):
|
||||||
raw_distance = int(match.group(6))
|
raw_distance = int(match.group(6))
|
||||||
raw_distance_var = int(match.group(7))
|
raw_distance_var = int(match.group(7))
|
||||||
rssi = int(match.group(8))
|
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
|
continue
|
||||||
distance = self.cali[0] * raw_distance + self.cali[1]
|
distance = self.cali[0] * raw_distance + self.cali[1]
|
||||||
result.append(
|
result.append(
|
||||||
|
|
@ -211,7 +211,7 @@ def wrapper(args):
|
||||||
print('Cannot plot because lacking matplotlib!')
|
print('Cannot plot because lacking matplotlib!')
|
||||||
with Measurement(
|
with Measurement(
|
||||||
args['interface'],
|
args['interface'],
|
||||||
ofp=args['filepath'], cali=args['cali']
|
ofp=args['outfp'], cali=args['cali']
|
||||||
) as m:
|
) as m:
|
||||||
while 1:
|
while 1:
|
||||||
print('Round {0}'.format(counter))
|
print('Round {0}'.format(counter))
|
||||||
|
|
@ -264,7 +264,7 @@ def main():
|
||||||
help="calibrate calibration params (pre-defined outdoor by default)"
|
help="calibrate calibration params (pre-defined outdoor by default)"
|
||||||
)
|
)
|
||||||
p.add_argument(
|
p.add_argument(
|
||||||
'--filepath', '-f',
|
'--outfp', '-f',
|
||||||
default=None,
|
default=None,
|
||||||
help="if set, will write raw fetched data to file"
|
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
|
# TODO: add option to change loc bounds, currently force y_min = 0
|
||||||
args['loc_bounds'] = {'y_min': 0}
|
args['loc_bounds'] = {'y_min': 0}
|
||||||
# rename file path by adding time of exec
|
# rename file path by adding time of exec
|
||||||
if args['filepath']:
|
if args['outfp']:
|
||||||
fp, ext = os.path.splitext(args['filepath'])
|
fp, ext = os.path.splitext(args['outfp'])
|
||||||
args['filepath'] = "{0}_{1}{2}".format(fp, args['time_of_exec'], ext)
|
args['outfp'] = "{0}_{1}{2}".format(fp, args['time_of_exec'], ext)
|
||||||
wrapper(args)
|
wrapper(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue