def _updateLogCB(self): """add current position at the end of the log""" pos = self.get('pos', None) if pos and not self.loggingPaused: timestamp = geo.timestamp_utc() lat, lon = pos elevation = self.get('elevation', None) self.log1.add_point_llet(lat, lon, elevation, timestamp) self.log2.add_point_llet(lat, lon, elevation, timestamp) # update statistics for the current log if self.loggingEnabled and not self.loggingPaused: # update the current log speed statistics currentSpeed = self.get('speed', None) if currentSpeed: # max speed if currentSpeed > self.maxSpeed: self.maxSpeed = currentSpeed # avg speed self.avg1 += currentSpeed self.avg2 += (time.time() - self.lastUpdateTimestamp) self.avgSpeed = self.avg1 / self.avg2 self.lastUpdateTimestamp = time.time() # update traveled distance if self.lastCoords: lLat, lLon = self.lastCoords self.distance += geo.distance(lLat, lLon, lat, lon) self.lastCoords = lat, lon # update the on-map trace if self.lastTracePoint: lat1, lon1 = self.lastTracePoint # check if the point is distant enough from the last added point # (which was either the first point or also passed the test) addToTrace = True try: addToTrace = geo.distance_approx( lat, lon, lat1, lon1) * 1000 >= DONT_ADD_TO_TRACE_THRESHOLD except Exception: self.log.exception( "measuring distance failed (yeah, really! :P), adding point anyway" ) if addToTrace: self._addLL2Trace(lat, lon) else: # this is the first known log point, just add it self._addLL2Trace(lat, lon) # done, trigger the tracklog updated signal self.tracklogUpdated()
def save_to_CSV(self, path, append=False): """Save all points to a CSV file NOTE: message points are not (yet) handled TODO: message point support """ timestamp = geo.timestamp_utc() try: f = open(path, "w") writer = csv.writer(f, dialect=csv.excel) points = self.points_lle for p in points: writer.writeRow(p[0], p[1], p[2], timestamp) f.close() log.info('%d points saved to %s as CSV', path, len(points)) return True except Exception: log.exception('saving to CSV failed') return False
def __init__(self, points=None): if not points: points = [] Way.__init__(self) self._points = [] # stored as (lat, lon, elevation, timestamp) tuples self.increment = [] # not yet saved increment, also LLET self.file = None self._file_path = None self.writer = None self._points_lock = threading.RLock() if points: with self._points_lock: # mark all points added on startup with a single timestamp timestamp = geo.timestamp_utc() # convert to LLET points = [(x[0], x[1], x[2], timestamp) for x in points] # mark points as not yet saved self.increment = points # and also add to main point list self._points = points
def add_point_lle(self, lat, lon, elevation=None): with self._points_lock: self._points.append((lat, lon, elevation, geo.timestamp_utc())) self.increment.append((lat, lon, elevation, geo.timestamp_utc()))
def add_point(self, point): with self._points_lock: lat, lon, elevation = point.getLLE() self._points.append((lat, lon, elevation, geo.timestamp_utc())) self.increment.append((lat, lon, elevation, geo.timestamp_utc()))