Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 6d2b44d7 authored by Freezed's avatar Freezed
Browse files

:zap: Update useful info from GPX file #3

Fit the use case (posting to strava):
- remove pointless informations
- compute values in standard units

relate to #2 & !3
parent be0bca62
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,7 @@ A python CLI to share data related to physical activities over an API (geo-local ...@@ -18,7 +18,7 @@ A python CLI to share data related to physical activities over an API (geo-local
These are imagined with _[Strava](https://developers.strava.com/docs/reference/) in mind_, but any other service will be nice too : These are imagined with _[Strava](https://developers.strava.com/docs/reference/) in mind_, but any other service will be nice too :
* [x] [Create activity](https://lab.frogg.it/fcode/geostrapy/-/issues/1) * [x] [Create activity](https://lab.frogg.it/fcode/geostrapy/-/issues/1)
* [ ] From a GPX track: [get characteristics](https://lab.frogg.it/fcode/geostrapy/-/issues/2) * [x] From a GPX track: [get characteristics](https://lab.frogg.it/fcode/geostrapy/-/issues/2)
* [ ] and [create an activity](https://lab.frogg.it/fcode/geostrapy/-/issues/3) * [ ] and [create an activity](https://lab.frogg.it/fcode/geostrapy/-/issues/3)
* Sanitize a GPX track: * Sanitize a GPX track:
* [ ] [crop start, end & stop points](https://lab.frogg.it/fcode/geostrapy/-/issues/4) * [ ] [crop start, end & stop points](https://lab.frogg.it/fcode/geostrapy/-/issues/4)
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
Process a GPX file to get informations. Process a GPX file to get informations.
""" """
import sys as mod_sys
import logging as mod_logging import logging as mod_logging
from os.path import basename as os_basename
import sys as mod_sys
from typing import Union, List from typing import Union, List
import gpxpy as mod_gpxpy import gpxpy as mod_gpxpy
...@@ -19,25 +20,27 @@ def get_gpx_part_info( ...@@ -19,25 +20,27 @@ def get_gpx_part_info(
"""gpx_part may be a track or segment.""" """gpx_part may be a track or segment."""
gpx_part_summary = {} gpx_part_summary = {}
gpx_part_summary.update({"length_2d": gpx_part.length_2d() or 0}) gpx_part_summary.update({"length_2d": round(gpx_part.length_2d()) or 0})
gpx_part_summary.update({"": gpx_part.length_3d()}) gpx_part_summary.update({"length_3d": round(gpx_part.length_3d())})
moving_data = gpx_part.get_moving_data() moving_data = gpx_part.get_moving_data()
if moving_data: if moving_data:
gpx_part_summary.update({"moving_time": moving_data.moving_time}) gpx_part_summary.update({"moving_time": round(moving_data.moving_time)})
gpx_part_summary.update({"stopped_time": moving_data.stopped_time}) gpx_part_summary.update({"stopped_time": round(moving_data.stopped_time)})
gpx_part_summary.update({"max_speed": moving_data.max_speed}) gpx_part_summary.update({"max_speed": round(moving_data.max_speed * 3.6, 1)})
gpx_part_summary.update( gpx_part_summary.update(
{ {
"avg_speed": moving_data.moving_distance / moving_data.moving_time "avg_speed": round(
moving_data.moving_distance / moving_data.moving_time * 3.6, 1
)
if moving_data.moving_time > 0 if moving_data.moving_time > 0
else "?" else "?"
} }
) )
uphill, downhill = gpx_part.get_uphill_downhill() uphill, downhill = gpx_part.get_uphill_downhill()
gpx_part_summary.update({"uphill": uphill}) gpx_part_summary.update({"uphill": round(uphill)})
gpx_part_summary.update({"downhill": downhill}) gpx_part_summary.update({"downhill": round(downhill)})
start_time, end_time = gpx_part.get_time_bounds() start_time, end_time = gpx_part.get_time_bounds()
gpx_part_summary.update({"start_time": start_time}) gpx_part_summary.update({"start_time": start_time})
...@@ -54,9 +57,6 @@ def get_gpx_part_info( ...@@ -54,9 +57,6 @@ def get_gpx_part_info(
distance = point.distance_2d(previous_point) distance = point.distance_2d(previous_point)
distances.append(distance) distances.append(distance)
previous_point = point previous_point = point
gpx_part_summary.update(
{"avg_dist_points": sum(distances) / len(list(gpx_part.walk()))}
)
return gpx_part_summary return gpx_part_summary
...@@ -69,21 +69,17 @@ def get_gpx_info(gpx: mod_gpx.GPX, gpx_file: str) -> None: ...@@ -69,21 +69,17 @@ def get_gpx_info(gpx: mod_gpx.GPX, gpx_file: str) -> None:
calculated over all. calculated over all.
""" """
gpx_summary = {} gpx_summary = {}
if gpx.name: if gpx.name:
gpx_summary.update({"name": gpx.name}) gpx_summary.update({"name": gpx.name})
if gpx.description: if gpx.description:
gpx_summary.update({"description": gpx.description}) gpx_summary.update({"description": gpx.description})
if gpx.author_name: if gpx.creator:
gpx_summary.update({"author_name": gpx.author_name}) gpx_summary.update({"creator": gpx.creator})
if gpx.author_email:
gpx_summary.update({"author_email": gpx.author_email}) gpx_summary.update({"file_name": os_basename(gpx_file)[:-4]})
gpx_summary.update({"has_elevations": gpx.has_elevations()})
gpx_summary.update({"file_name": gpx_file}) gpx_summary.update({"has_times": gpx.has_times()})
gpx_summary.update({"waypoints": len(gpx.waypoints)})
gpx_summary.update({"routes": len(gpx.routes)})
gpx_summary.update({"tracks": len(gpx.tracks)}) gpx_summary.update({"tracks": len(gpx.tracks)})
# gpx_summary.update({"segments": len(track.segments)})
gpx_summary.update(get_gpx_part_info(gpx)) gpx_summary.update(get_gpx_part_info(gpx))
return gpx_summary return gpx_summary
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment