diff --git a/run_page/garmin_sync_cn_global.py b/run_page/garmin_sync_cn_global.py index cf5f3831f0e..98a3ebe42d3 100644 --- a/run_page/garmin_sync_cn_global.py +++ b/run_page/garmin_sync_cn_global.py @@ -5,32 +5,13 @@ import argparse import asyncio -import logging import os import sys -import time -import traceback -import zipfile -from io import BytesIO -import aiofiles -import cloudscraper -import garth -import httpx + from config import FIT_FOLDER, GPX_FOLDER, JSON_FILE, SQL_FILE, config -from garmin_device_adaptor import wrap_device_info from garmin_sync import Garmin, get_downloaded_ids -from garmin_sync import ( - download_new_activities, - gather_with_concurrency, - get_activities_name, -) -from synced_data_file_logger import ( - load_synced_activity_list, - save_synced_activity_list, - load_fit_name_mapping, - save_fit_name_mapping, -) +from garmin_sync import download_new_activities, gather_with_concurrency from utils import make_activities_file if __name__ == "__main__": @@ -62,7 +43,9 @@ # If the activity is manually imported with a GPX, the GPX file will be synced # load synced activity list - synced_activity = load_synced_activity_list() + downloaded_fit = get_downloaded_ids(FIT_FOLDER) + downloaded_gpx = get_downloaded_ids(GPX_FOLDER) + downloaded_activity = list(set(downloaded_fit + downloaded_gpx)) folder = FIT_FOLDER # make gpx or tcx dir @@ -74,7 +57,7 @@ download_new_activities( secret_string_cn, auth_domain, - synced_activity, + downloaded_activity, is_only_running, folder, "fit", @@ -83,21 +66,6 @@ loop.run_until_complete(future) new_ids = future.result() - # Step 2: - # activity name not included in fit file - # manually fetch activity name, save to file for later use - old_name_mapping = load_fit_name_mapping() - new_ids = new_ids - old_name_mapping.keys() - if new_ids: - loop = asyncio.get_event_loop() - future = asyncio.ensure_future( - get_activities_name(secret_string_cn, auth_domain, new_ids) - ) - loop.run_until_complete(future) - names_mapping = future.result() - names_mapping.update(old_name_mapping) - save_fit_name_mapping(names_mapping) - to_upload_files = [] for i in new_ids: if os.path.exists(os.path.join(FIT_FOLDER, f"{i}.fit")): @@ -119,11 +87,7 @@ ) loop.run_until_complete(future) - # Save synced activity list for speeding up - synced_activity.extend(new_ids) - save_synced_activity_list(synced_activity) - - # Step 3: + # Step 2: # Generate track from fit/gpx file make_activities_file(SQL_FILE, GPX_FOLDER, JSON_FILE, file_suffix="gpx") make_activities_file(SQL_FILE, FIT_FOLDER, JSON_FILE, file_suffix="fit") diff --git a/run_page/generator/__init__.py b/run_page/generator/__init__.py index 7039cac1a0f..5ea57e64d08 100644 --- a/run_page/generator/__init__.py +++ b/run_page/generator/__init__.py @@ -91,9 +91,7 @@ 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(run_from=file_suffix) - ) + created = update_or_create_activity(self.session, t.to_namedtuple()) if created: sys.stdout.write("+") else: diff --git a/run_page/gpxtrackposter/tracks_drawer.py b/run_page/gpxtrackposter/tracks_drawer.py index 912de8ce952..216b4e8da5b 100644 --- a/run_page/gpxtrackposter/tracks_drawer.py +++ b/run_page/gpxtrackposter/tracks_drawer.py @@ -47,5 +47,10 @@ def color( diff = length_range.diameter() if diff == 0: return color1 + if ( + self.poster.length_range.upper() / 1000 + < self.poster.special_distance["special_distance2"] + ): + return color1 return interpolate_color(color1, color2, (length - length_range.lower()) / diff) diff --git a/run_page/synced_data_file_logger.py b/run_page/synced_data_file_logger.py index 1b0c6edbe45..6247263072e 100644 --- a/run_page/synced_data_file_logger.py +++ b/run_page/synced_data_file_logger.py @@ -1,5 +1,5 @@ import os -from config import SYNCED_FILE, SYNCED_ACTIVITY_FILE, NAME_MAPPING_FILE +from config import SYNCED_FILE, SYNCED_ACTIVITY_FILE import json @@ -27,32 +27,3 @@ def load_synced_file_list(): pass return [] - - -def load_synced_activity_list(): - if os.path.exists(SYNCED_ACTIVITY_FILE): - with open(SYNCED_ACTIVITY_FILE, "r") as f: - try: - return json.load(f) - except Exception as e: - print(f"json load {SYNCED_ACTIVITY_FILE} \nerror {e}") - pass - - return [] - - -def load_fit_name_mapping(): - if os.path.exists(NAME_MAPPING_FILE): - with open(NAME_MAPPING_FILE, "r") as f: - try: - return json.load(f) - except Exception as e: - print(f"json load {NAME_MAPPING_FILE} \nerror {e}") - pass - - return {} - - -def save_fit_name_mapping(name_mapping: dict): - with open(NAME_MAPPING_FILE, "w") as f: - json.dump(name_mapping, f)