Skip to content

Commit

Permalink
Ptosiek/improve-tcx-loader-rebasedからのプルリクエスト#41をマージする
Browse files Browse the repository at this point in the history
fix loader_tcx to handle missing distance
  • Loading branch information
hishizuka authored Oct 10, 2023
2 parents b08fb3a + 80daa1e commit 4c150ce
Show file tree
Hide file tree
Showing 15 changed files with 9,538 additions and 466 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/log/
/screenshots/
/maptile/*
/courses/.current
/courses/ridewithgps/*
/courses/*html*
/fonts/*
Expand Down
42 changes: 41 additions & 1 deletion modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import traceback
import math
from glob import glob

import numpy as np
import oyaml as yaml
Expand Down Expand Up @@ -93,7 +94,7 @@ class Config:

# courses
G_COURSE_DIR = "courses"
G_COURSE_FILE_PATH = os.path.join(G_COURSE_DIR, "course.tcx")
G_COURSE_FILE_PATH = os.path.join(G_COURSE_DIR, ".current")
G_CUESHEET_DISPLAY_NUM = 3 # max: 5
G_CUESHEET_SCROLL = False
G_OBEXD_CMD = "/usr/libexec/bluetooth/obexd"
Expand Down Expand Up @@ -1327,3 +1328,42 @@ def get_lon_lat_from_tile_xy(z, x, y):
lat = math.degrees(math.atan(math.sinh(math.pi * (1 - 2 * y / n))))

return lon, lat

def get_courses(self):
dirs = sorted(
glob(os.path.join(self.G_COURSE_DIR, "*.tcx")),
key=lambda f: os.stat(f).st_mtime,
reverse=True,
)

# heavy: delayed updates required
# def get_course_info(c):
# pattern = {
# "name": re.compile(r"<Name>(?P<text>[\s\S]*?)</Name>"),
# "distance_meters": re.compile(
# r"<DistanceMeters>(?P<text>[\s\S]*?)</DistanceMeters>"
# ),
# # "track": re.compile(r'<Track>(?P<text>[\s\S]*?)</Track>'),
# # "altitude": re.compile(r'<AltitudeMeters>(?P<text>[^<]*)</AltitudeMeters>'),
# }
# info = {}
# with open(c, "r", encoding="utf-8_sig") as f:
# tcx = f.read()
# match_name = pattern["name"].search(tcx)
# if match_name:
# info["name"] = match_name.group("text").strip()
#
# match_distance_meter = pattern["distance_meters"].search(tcx)
# if match_distance_meter:
# info["distance"] = float(match_distance_meter.group("text").strip())
# return info

return [
{
"path": f,
"name": os.path.basename(f),
# **get_course_info(f)
}
for f in dirs
if os.path.isfile(f) and f != self.G_COURSE_FILE_PATH
]
Loading

0 comments on commit 4c150ce

Please sign in to comment.