Skip to content

Commit

Permalink
Modified Track class to accept an optional run_from parameter in …
Browse files Browse the repository at this point in the history
…`to_namedtuple` method, (#702)

allowing dynamic naming of activities based on their source.
  • Loading branch information
Fariacool authored Aug 6, 2024
1 parent fa7790b commit e652647
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion run_page/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def sync_from_data_dir(self, data_dir, file_suffix="gpx"):
synced_files = []

for t in tracks:
created = update_or_create_activity(self.session, t.to_namedtuple())
created = update_or_create_activity(
self.session, t.to_namedtuple(run_from=file_suffix)
)
if created:
sys.stdout.write("+")
else:
Expand Down
17 changes: 15 additions & 2 deletions run_page/gpxtrackposter/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self):
self.run_id = 0
self.start_latlng = []
self.type = "Run"
self.device = ""

def load_gpx(self, file_name):
"""
Expand Down Expand Up @@ -280,6 +281,14 @@ def _load_fit_data(self, fit: dict):
self.start_time, self.end_time, None
)

# The FIT file created by Garmin
if "file_id_mesgs" in fit:
device_message = fit["file_id_mesgs"][0]
if "manufacturer" in device_message:
self.device = device_message["manufacturer"]
if "garmin_product" in device_message:
self.device += " " + device_message["garmin_product"]

def append(self, other):
"""Append other track to self."""
self.end_time = other.end_time
Expand Down Expand Up @@ -319,10 +328,14 @@ def _get_moving_data(gpx):
),
}

def to_namedtuple(self):
def to_namedtuple(self, run_from="gpx"):
d = {
"id": self.run_id,
"name": "run from gpx", # maybe change later
"name": (
f"run from {run_from} by {self.device}"
if self.device
else f"run from {run_from}"
), # maybe change later
"type": "Run", # Run for now only support run for now maybe change later
"start_date": self.start_time.strftime("%Y-%m-%d %H:%M:%S"),
"end": self.end_time.strftime("%Y-%m-%d %H:%M:%S"),
Expand Down

0 comments on commit e652647

Please sign in to comment.