Skip to content

Commit 4d477e0

Browse files
committed
more null elevation support
see russellporter/openskidata-processor@11d89ea
1 parent 48106fd commit 4d477e0

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

openskistats/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ class RunModel(Model): # type: ignore [misc]
361361
description="List of sources for the run from OpenSkiMap.",
362362
),
363363
]
364+
run_coordinates_filter_count: Annotated[
365+
int,
366+
Field(
367+
description="Number of coordinates removed from the run during filtering. "
368+
"Coordinates with missing or bad elevation data are filtered out.",
369+
),
370+
]
364371
run_coordinates_clean: Annotated[
365372
list[RunCoordinateSegmentModel] | None,
366373
Field(

openskistats/openskimap_utils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,29 @@ def load_downhill_runs_from_download_pl() -> pl.DataFrame:
189189
openskimap_source_to_url(**source) for source in run_properties["sources"]
190190
)
191191
coordinates = run["geometry"]["coordinates"]
192-
row["run_coordinates_raw"] = [
193-
x.model_dump() for x in _structure_coordinates(coordinates)
194-
]
192+
row["run_coordinates_raw_count"] = len(coordinates)
195193
row["run_coordinates_clean"] = [
196194
x.model_dump()
197195
for x in _structure_coordinates(_clean_coordinates(coordinates))
198196
]
197+
row["run_coordinates_filter_count"] = len(coordinates) - len(
198+
row["run_coordinates_clean"]
199+
)
199200
# do we ever need to reverse the elevation profile (e.g. if run coordinates are reversed)?
200201
if elev_profile := run_properties["elevationProfile"]:
201202
assert elev_profile["resolution"] == 25
203+
# It is not a great solution to just filter the missing elevation values,
204+
# especially without changing the resolution.
202205
row["run_elevation_profile"] = [
203-
round(x, 2) for x in elev_profile["heights"]
206+
round(x, 2) for x in elev_profile["heights"] if x is not None
204207
]
205208
else:
206209
row["run_elevation_profile"] = None
207210
rows.append(row)
208211
set_variables(
209212
openskimap__runs__counts__02_linestring=len(rows),
210213
openskimap__runs__coordinates__counts__01_raw=sum(
211-
len(row["run_coordinates_raw"]) for row in rows
214+
row["run_coordinates_raw_count"] for row in rows
212215
),
213216
openskimap__runs__coordinates__counts__02_clean=sum(
214217
len(row["run_coordinates_clean"]) for row in rows
@@ -218,13 +221,13 @@ def load_downhill_runs_from_download_pl() -> pl.DataFrame:
218221
set_variables(
219222
openskimap__runs__counts__03_downhill=len(rows),
220223
openskimap__runs__coordinates__counts__03_downhill_raw=sum(
221-
len(row["run_coordinates_raw"]) for row in rows
224+
row["run_coordinates_raw_count"] for row in rows
222225
),
223226
openskimap__runs__coordinates__counts__04_downhill_clean=sum(
224227
len(row["run_coordinates_clean"]) for row in rows
225228
),
226229
)
227-
return pl.DataFrame(rows, strict=False).drop("run_coordinates_raw")
230+
return pl.DataFrame(rows, strict=False).drop("run_coordinates_raw_count")
228231

229232

230233
def load_lifts_from_download_pl() -> pl.DataFrame:

0 commit comments

Comments
 (0)