From ceed8a43b6f72c950fc4edc0cb43a775b877a60e Mon Sep 17 00:00:00 2001 From: anchao Date: Mon, 11 Dec 2023 17:46:50 +0800 Subject: [PATCH 1/2] fix: Codoon tcv output use start_time as ID instead of Codoon id --- run_page/codoon_sync.py | 15 +++++++-------- run_page/utils.py | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/run_page/codoon_sync.py b/run_page/codoon_sync.py index aa0d198975e..c04e58e7c25 100755 --- a/run_page/codoon_sync.py +++ b/run_page/codoon_sync.py @@ -129,6 +129,12 @@ def formated_input( def tcx_output(fit_array, run_data): # route ID fit_id = str(run_data["id"]) + # local time + fit_start_time_local = run_data["start_time"] + # zulu time + utc = adjust_time_to_utc(to_date(fit_start_time_local), str(get_localzone())) + fit_start_time = utc.strftime("%Y-%m-%dT%H:%M:%SZ") + # Root node training_center_database = ET.Element( "TrainingCenterDatabase", @@ -154,7 +160,7 @@ def tcx_output(fit_array, run_data): activities.append(activity) # Id activity_id = ET.Element("Id") - activity_id.text = fit_id + activity_id.text = fit_start_time # Codoon use start_time as ID activity.append(activity_id) # Creator activity_creator = ET.Element("Creator") @@ -164,13 +170,6 @@ def tcx_output(fit_array, run_data): activity_creator_name.text = "咕咚" activity_creator.append(activity_creator_name) # Lap - - # local time - fit_start_time_local = run_data["start_time"] - # zulu time - utc = adjust_time_to_utc(to_date(fit_start_time_local), str(get_localzone())) - fit_start_time = utc.strftime("%Y-%m-%dT%H:%M:%SZ") - activity_lap = ET.Element("Lap", {"StartTime": fit_start_time}) activity.append(activity_lap) # TotalTimeSeconds diff --git a/run_page/utils.py b/run_page/utils.py index b003707284a..92a4f1a6d72 100644 --- a/run_page/utils.py +++ b/run_page/utils.py @@ -40,7 +40,7 @@ def to_date(ts): # shouldn't be an issue since it's an offline cmdline tool return datetime.strptime(ts, ts_fmt) except ValueError: - print("Error: Can not execute strptime") + print(f"Warning: Can not execute strptime {ts} with ts_fmt {ts_fmt}, try next one...") pass raise ValueError(f"cannot parse timestamp {ts} into date with fmts: {ts_fmts}") From 4bb0d38218e9f157a80349ca5e924f4e72b7dd96 Mon Sep 17 00:00:00 2001 From: anchao Date: Mon, 11 Dec 2023 21:00:39 +0800 Subject: [PATCH 2/2] fix lint by black --- run_page/codoon_sync.py | 2 +- run_page/utils.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/run_page/codoon_sync.py b/run_page/codoon_sync.py index c04e58e7c25..84a19bf4650 100755 --- a/run_page/codoon_sync.py +++ b/run_page/codoon_sync.py @@ -160,7 +160,7 @@ def tcx_output(fit_array, run_data): activities.append(activity) # Id activity_id = ET.Element("Id") - activity_id.text = fit_start_time # Codoon use start_time as ID + activity_id.text = fit_start_time # Codoon use start_time as ID activity.append(activity_id) # Creator activity_creator = ET.Element("Creator") diff --git a/run_page/utils.py b/run_page/utils.py index 92a4f1a6d72..de6945ee48a 100644 --- a/run_page/utils.py +++ b/run_page/utils.py @@ -40,7 +40,9 @@ def to_date(ts): # shouldn't be an issue since it's an offline cmdline tool return datetime.strptime(ts, ts_fmt) except ValueError: - print(f"Warning: Can not execute strptime {ts} with ts_fmt {ts_fmt}, try next one...") + print( + f"Warning: Can not execute strptime {ts} with ts_fmt {ts_fmt}, try next one..." + ) pass raise ValueError(f"cannot parse timestamp {ts} into date with fmts: {ts_fmts}")