Пример #1
0
	def parse_file(self):
		self.laps = []
		self.position_start = None
		self.date = None
		self.time_start = None
		self.time_end = None
		self.position_start = None

		if len(self.gpxfile.tracks) == 0:
			raise RuntimeError("No track found in gpx file")

		# this is start of activity, get timestamp and all other activity related data
		for track in self.gpxfile.tracks:
			for segment in track.segments:
				# start of a lap
				lap = Lap()
				time_bounds = segment.get_time_bounds()
				moving_data = segment.get_moving_data(stopped_speed_threshold=0.5)
				up_down = segment.get_uphill_downhill()
				elev_min_max = segment.get_elevation_extremes()

				lap.date = time_bounds.start_time.replace(tzinfo=utc)
				lap.time = int(moving_data.moving_time)
				lap.distance = round(moving_data.moving_distance / 1000, 3)
				lap.elevation_gain = int(up_down.uphill)
				lap.elevation_loss = int(up_down.downhill)
				lap.elevation_min = int(elev_min_max.minimum)
				lap.elevation_max = int(elev_min_max.maximum)
				if moving_data.max_speed:
					lap.speed_max = round(moving_data.max_speed * 3.6, 1)
				else:
					lap.speed_max = 0.0
				if lap.time > 0:
					lap.speed_avg = round((lap.distance / lap.time) * 3.6, 1)
				else:
					lap.speed_avg = 0.0
				self.laps.append(lap)

		self.time_start = track.segments[0].points[0].time
		self.time_end = track.segments[-1].points[-1].time
		start_point = track.segments[0].points[0]
		self.position_start = (start_point.latitude, start_point.longitude)
Пример #2
0
	def parse_file(self):
		self.laps = []
		self.position_start = None
		self.date = None
		self.time_start = None
		self.time_end = None
		self.position_start = None

		for message in self.fitfile.get_messages(name="session"):
			if message.get_value("start_position_lat") is not None and message.get_value("start_position_long") is not None:
				self.position_start = (message.get_value("start_position_lat"), message.get_value("start_position_long"))
			self.time_start = message.get_value("start_time")
			self.time_end = message.get_value("timestamp")

		lap_altitude = []
		for message in self.fitfile.get_messages():
			if message.name == "record":
				lap_altitude.append(message.get_value('altitude'))
			elif message.name == "lap":
				lap = Lap()
				lap.date = message.get_value("start_time").replace(tzinfo=utc)
				lap.time = message.get_value("total_timer_time")
				lap.distance = message.get_value("total_distance")
				if lap.distance is None:
					lap.distance = 0
				else:
					lap.distance /= 1000
				lap.elevation_gain = message.get_value("total_ascent")
				lap.elevation_loss = message.get_value("total_descent")
				if lap.elevation_gain is None:
					lap.elevation_gain = 0
				if lap.elevation_loss is None:
					lap.elevation_loss = 0

				lap.cadence_avg = message.get_value("avg_cadence")
				lap.cadence_max = message.get_value("max_cadence")
				if message.get_value("sport") == 'running':
					if lap.cadence_avg is not None:
						lap.cadence_avg *= 2
					if lap.cadence_max is not None:
						lap.cadence_max *= 2

				lap.calories = message.get_value("total_calories")
				lap.hf_avg = message.get_value("avg_heart_rate")
				lap.hf_max = message.get_value("max_heart_rate")

				if len(lap_altitude) > 0:
					lap.elevation_max = max(lap_altitude)
					lap.elevation_min = min(lap_altitude)
				lap_altitude = []

				max_speed = message.get("max_speed")
				if max_speed and max_speed.value:
					if max_speed.units == "m/s":
						lap.speed_max = (max_speed.value * 3600.0) / 1000
					elif max_speed.units == "km/h":
						lap.speed_max = max_speed.value
					else:
						raise RuntimeError("Unknown speed unit: %s" % max_speed.units)
				else:
					lap.speed_max = 0

				avg_speed = message.get("avg_speed")
				if avg_speed and avg_speed.value:
					if avg_speed:
						if avg_speed.units == "m/s":
							lap.speed_avg = (avg_speed.value * 3600.0) / 1000
						elif max_speed.units == "km/h":
							lap.speed_avg = avg_speed.value
						else:
							raise RuntimeError("Unknown speed unit: %s" % max_speed.units)
				else:
					lap.speed_avg = 0

				self.laps.append(lap)