Skip to content

Commit

Permalink
fix: use named imports
Browse files Browse the repository at this point in the history
  • Loading branch information
andipaetzold committed Jan 11, 2025
1 parent 827684a commit 9039cd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
6 changes: 3 additions & 3 deletions frontend/scripts/create-world-roads-buffered.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import buffer from "@turf/buffer";
import { Feature, lineString, MultiPolygon, Polygon } from "@turf/helpers";
import union from "@turf/union";
import _ from "lodash-es";
import { round } from "lodash-es";
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -31,13 +31,13 @@ for (const world of worlds) {

const linePolygon = linePolygons.reduce(
(prev, cur) => union(prev, cur)!,
linePolygons[0] as Feature<Polygon | MultiPolygon>,
linePolygons[0] as Feature<Polygon | MultiPolygon>
) as Feature<Polygon>;

const data = linePolygon.geometry.coordinates.map((polygon) =>
polygon
.map(positionToLatLng)
.map(([lat, lng]) => [_.round(lat, 6), _.round(lng, 6)]),
.map(([lat, lng]) => [round(lat, 6), round(lng, 6)])
);

const dir = `${BASE_DIR}/${world.slug}`;
Expand Down
31 changes: 14 additions & 17 deletions frontend/scripts/fetch-segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync, mkdirSync, writeFileSync } from "fs";
import path, { dirname } from "path";
import { Route, routes, Segment, segments } from "zwift-data";
import { fileURLToPath } from "url";
import _ from "lodash-es";
import { zip, unzip, round } from "lodash-es";
import progress from "cli-progress";
import { LatLng } from "strava";

Expand All @@ -22,7 +22,7 @@ if (!existsSync(BASE_DIR)) {

const bar = new progress.Bar({});
const segmentsToFetch = [...routes, ...segments].filter(
(route) => route.stravaSegmentId !== undefined,
(route) => route.stravaSegmentId !== undefined
);
bar.start(segmentsToFetch.length, 0);

Expand All @@ -32,16 +32,16 @@ await Promise.all([
.map((segment) =>
fetchSegment(
segment as (Segment | Route) & { stravaSegmentId: number },
bar,
),
bar
)
),
]);

bar.stop();

async function fetchSegment(
{ name, stravaSegmentId }: (Segment | Route) & { stravaSegmentId: number },
bar: progress.Bar,
bar: progress.Bar
) {
const segmentDir = `${BASE_DIR}/strava-segments/${stravaSegmentId}`;

Expand All @@ -51,7 +51,7 @@ async function fetchSegment(
}

const response = await fetch(
`https://www.strava.com/stream/segments/${stravaSegmentId}?streams%5B%5D=latlng&streams%5B%5D=distance&streams%5B%5D=altitude`,
`https://www.strava.com/stream/segments/${stravaSegmentId}?streams%5B%5D=latlng&streams%5B%5D=distance&streams%5B%5D=altitude`
);

if (response.status !== 200) {
Expand All @@ -65,25 +65,25 @@ async function fetchSegment(
mkdirSync(segmentDir, { recursive: true });
}

const zipped = _.zip(
const zipped = zip(
getRoundedLatLng(stravaData),
getRoundedAltitude(stravaData),
getRoundedDistances(stravaData),
getRoundedDistances(stravaData)
) as [LatLng, number, number][];
const dedupedZip = zipped.filter(([[lat, lng]], index) => {
return (
zipped[index - 1]?.[0][0] !== lat || zipped[index - 1]?.[0][1] !== lng
);
});
const [latlng, altitude, distance] = _.unzip(dedupedZip) as [
const [latlng, altitude, distance] = unzip(dedupedZip) as [
LatLng[],
number[],
number[],
];

writeFileSync(
`${segmentDir}/altitude.json`,
JSON.stringify(fixMakuriIslandsAltitude(stravaSegmentId, altitude)),
JSON.stringify(fixMakuriIslandsAltitude(stravaSegmentId, altitude))
);
writeFileSync(`${segmentDir}/distance.json`, JSON.stringify(distance));
writeFileSync(`${segmentDir}/latlng.json`, JSON.stringify(latlng));
Expand All @@ -92,26 +92,23 @@ async function fetchSegment(
}

function getRoundedLatLng(stravaData: StravaData) {
return stravaData.latlng.map(([lat, lng]) => [
_.round(lat, 6),
_.round(lng, 6),
]);
return stravaData.latlng.map(([lat, lng]) => [round(lat, 6), round(lng, 6)]);
}

function getRoundedAltitude(stravaData: StravaData) {
return stravaData.altitude.map((d) => _.round(d, 1));
return stravaData.altitude.map((d) => round(d, 1));
}

function getRoundedDistances(stravaData: StravaData) {
return stravaData.distance.map((d) => _.round(d, 2));
return stravaData.distance.map((d) => round(d, 2));
}

/**
* With the Urukazi update, Zwift lowered the altitude of all existing roads by 60m
*/
function fixMakuriIslandsAltitude(
segmentId: number,
altitudeStream: number[],
altitudeStream: number[]
): number[] {
const segments = [
30407802, 28431416, 30987848, 30480835, 30407658, 29009500, 30629791,
Expand Down

0 comments on commit 9039cd7

Please sign in to comment.