def parse_input(fileid=util.get_last_fileid()): filename = util.OUTPUT_FILENAME_TEMPLATE.format(fileid) results = [] with open(filename, 'r') as f: for line in f.readlines(): if line[0] == '#': # this is a comment, skip continue results.append(json.loads(line)) coords = [(res['latitude'], res['longitude']) for res in results] print "found {0} unique records out of {1} total records".format( len(set(coords)), len(coords)) return coords
def parse_input(fileid = util.get_last_fileid()): filename = util.OUTPUT_FILENAME_TEMPLATE.format(fileid) results = [] with open(filename, 'r') as f: for line in f.readlines(): if line[0] == '#': # this is a comment, skip continue results.append(json.loads(line)) coords = [(res['latitude'], res['longitude']) for res in results] print "found {0} unique records out of {1} total records".format( len(set(coords)), len(coords)) return coords
def record(): # Start location messages droid = android.Android() droid.startLocating(0, 0) droid.makeToast("Starting location drill") # Show a dialog box droid.dialogCreateInput("GPS Recorder running", "Add message to log") droid.dialogSetPositiveButtonText("Log message") droid.dialogSetNegativeButtonText("Exit") droid.dialogShow() # Loop until the user exits out_filename = OUTPUT_FILENAME_TEMPLATE.format(get_last_fileid() + 1) with open(out_filename, 'w') as out_file: running = True while running: # Wait until we get an event res = droid.eventWait(1000).result if res == None: print "LocationListener timeout" elif res['name'] == "dialog": # User used the dialog if (res[u'data'][u'which'] == u'positive'): droid.makeToast("Saving log message") message = '# {0}'.format(res[u'data'][u'value']) print message out_file.write('{0}\n'.format(message)) droid.dialogShow() else: print "User requested exit" running = False elif res['name'] == "location": # It's a GPS message! try: loc = res['data']['gps'] except (KeyError, TypeError): print("Location message, but no GPS data") continue print(loc) out_file.write(json.dumps(loc) + '\n') # Shutdown droid.stopLocating() droid.makeToast("All done - saved to {0}".format(out_filename))
def record(): # Start location messages droid = android.Android() droid.startSensingTimed(1, 50) droid.makeToast("Starting sensing") # Show a dialog box droid.dialogCreateInput("Sensor Recorder running", "Add message to log") droid.dialogSetPositiveButtonText("Log message") droid.dialogSetNegativeButtonText("Exit") droid.dialogShow() # Loop until the user exits out_filename = OUTPUT_FILENAME_TEMPLATE.format(get_last_fileid() + 1) with open(out_filename, 'w') as out_file: running = True time.sleep(10) while running: res = droid.eventWait(1000).result print res if res == None: print "SensorListener timeout" elif res['name'] == "dialog": # User saving a comment if (res[u'data'][u'which'] == u'positive'): droid.makeToast("Saving log message") message = '# {0}'.format(res[u'data'][u'value']) print message out_file.write('{0}\n'.format(message)) droid.dialogShow() else: print "User requested exit" running = False elif res['name'] == "sensors": # We've got what we're looking for! print(res) out_file.write(json.dumps(res) + '\n') # Shutdown droid.stopLocating() droid.makeToast("All done - saved to {0}".format(out_filename))
def record(): # Start location messages droid = android.Android() droid.startSensingTimed(1, 1000) droid.makeToast("Starting Bearing drill") # Show a dialog box droid.dialogCreateInput("Bearing Recorder running", "Add message to log") droid.dialogSetPositiveButtonText("Log message") droid.dialogSetNegativeButtonText("Exit") droid.dialogShow() out_filename = OUTPUT_FILENAME_TEMPLATE.format(get_last_fileid() + 1) with open(out_filename, 'w') as out_file: running = True while running: # Wait until we get an event res = droid.eventWait(1000).result if res == None: print "SensorListener timeout" elif res['name'] == "dialog": # User used the dialog if (res[u'data'][u'which'] == u'positive'): droid.makeToast("Saving log message") message = '# {0}'.format(res[u'data'][u'value']) print message out_file.write('{0}\n'.format(message)) droid.dialogShow() else: print "User requested exit" running = False elif res['name'] == 'sensors': data = {} data['time'] = res['data']['time'] xforce = float(res['data']['xforce']) yforce = float(res['data']['yforce']) zforce = float(res['data']['zforce']) xmag = float(res['data']['xMag']) ymag = float(res['data']['yMag']) zmag = float(res['data']['zMag']) if abs(xforce) > abs(yforce) and abs(xforce) > abs(zforce): if xforce > VERTICAL_THRESHOLD: angle = math.atan2(-(ymag),zmag) if angle < 0: angle = angle + (2 * math.pi) bearing = int(math.degrees(angle)) data['bearing'] = bearing elif xforce < -(VERTICAL_THRESHOLD): angle = math.atan2(ymag,zmag) if angle < 0: angle = angle + (2 * math.pi) bearing = int(math.degrees(angle)) data['bearing'] = bearing elif xforce > 0: data['bearing'] = None else: data['bearing'] = None elif abs(yforce) > abs(xforce) and abs(yforce) > abs(zforce): if yforce > VERTICAL_THRESHOLD: angle = math.atan2(-(zmag),xmag) if angle < 0: angle = angle + (2 * math.pi) bearing = int(math.degrees(angle)) data['bearing'] = bearing elif yforce < -(VERTICAL_THRESHOLD): angle = math.atan2(zmag,xmag) if angle < 0: angle = angle + (2 * math.pi) data['bearing'] = int(math.degrees(angle)) elif yforce > 0: data['bearing'] = None else: data['bearing'] = None elif abs(zforce) > abs(yforce) and abs(zforce) > abs(xforce): if zforce > VERTICAL_THRESHOLD: angle = math.atan2(ymag,xmag) if angle < 0: angle = angle + (2 * math.pi) data['bearing'] = int(math.degrees(angle)) elif zforce < -(VERTICAL_THRESHOLD): angle = math.atan2(-(ymag),xmag) if angle < 0: angle = angle + (2 * math.pi) data['bearing'] = int(math.degrees(angle)) elif zforce > 0: data['bearing'] = None else: data['bearing'] = None else: data['bearing'] = None print(data) out_file.write(json.dumps(data) + '\n') # Shutdown droid.stopSensing()