Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an optional run_from parameter in to_namedtuple method #702

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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