Skip to content

Commit

Permalink
Autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
russellporter committed Feb 12, 2025
1 parent 79447ba commit 42a1872
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ To enable, set `GEOCODING_SERVER_URL` to an endpoint that reverse geocodes in th

## Issue reporting

Feature requests and bug reports are tracked in the [main project repo](https://github.com/russellporter/openskimap.org/issues/).
Feature requests and bug reports are tracked in the [main project repo](https://github.com/russellporter/openskimap.org/issues/).
6 changes: 3 additions & 3 deletions src/clustering/ArangoHelpers.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("isArangoInvalidGeometryError", () => {
errorMessage: "AQL: Polygon is not valid (while executing)",
},
},
})
}),
).toBe(true);
});
it("is false for other error", () => {
Expand All @@ -18,14 +18,14 @@ describe("isArangoInvalidGeometryError", () => {
response: {
parsedBody: { errorMessage: "AQL: Connection error" },
},
})
}),
).toBe(false);
});
it("is false for error with null response", () => {
expect(
isArangoInvalidGeometryError({
response: null,
})
}),
).toBe(false);
});
});
22 changes: 11 additions & 11 deletions src/io/GeoJSONDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import convertOSMFileToGeoJSON from "./OSMToGeoJSONConverter";

export default async function downloadAndConvertToGeoJSON(
folder: string,
bbox: GeoJSON.BBox | null
bbox: GeoJSON.BBox | null,
): Promise<InputDataPaths> {
const paths = new InputDataPaths(folder);

Expand All @@ -26,26 +26,26 @@ export default async function downloadAndConvertToGeoJSON(
OSMEndpoint.Z,
runsDownloadConfig,
paths.osmJSON.runs,
bbox
bbox,
),
(async () => {
await downloadOSMJSON(
OSMEndpoint.LZ4,
liftsDownloadConfig,
paths.osmJSON.lifts,
bbox
bbox,
);
await downloadOSMJSON(
OSMEndpoint.LZ4,
skiAreasDownloadConfig,
paths.osmJSON.skiAreas,
bbox
bbox,
);
await downloadOSMJSON(
OSMEndpoint.LZ4,
skiAreaSitesDownloadConfig,
paths.osmJSON.skiAreaSites,
bbox
bbox,
);
})(),
downloadSkiMapOrgSkiAreas(paths.geoJSON.skiMapSkiAreas, bbox),
Expand All @@ -68,7 +68,7 @@ async function downloadOSMJSON(
endpoint: OSMEndpoint,
config: OSMDownloadConfig,
targetPath: string,
bbox: GeoJSON.BBox | null
bbox: GeoJSON.BBox | null,
) {
const query = config.query(bbox);
console.log("Performing overpass query...");
Expand All @@ -79,7 +79,7 @@ async function downloadOSMJSON(

async function downloadSkiMapOrgSkiAreas(
targetPath: string,
bbox: GeoJSON.BBox | null
bbox: GeoJSON.BBox | null,
) {
await downloadToFile(skiMapSkiAreasURL, targetPath);

Expand All @@ -92,7 +92,7 @@ async function downloadSkiMapOrgSkiAreas(
const contents = await readFile(targetPath);
const json: GeoJSON.FeatureCollection = JSON.parse(contents.toString());
json.features = (json.features as InputSkiMapOrgSkiAreaFeature[]).filter(
(feature) => booleanContains(bboxGeometry, feature)
(feature) => booleanContains(bboxGeometry, feature),
);

await writeFile(targetPath, JSON.stringify(json));
Expand All @@ -101,7 +101,7 @@ async function downloadSkiMapOrgSkiAreas(
async function downloadToFile(
sourceURL: string,
targetPath: string,
retries: number = 10
retries: number = 10,
): Promise<void> {
try {
await _downloadToFile(sourceURL, targetPath);
Expand All @@ -111,7 +111,7 @@ async function downloadToFile(
}

console.log(
"Download failed due to " + e + ". Will wait a minute and try again."
"Download failed due to " + e + ". Will wait a minute and try again.",
);

// Wait a bit in case we are rate limited by the server.
Expand All @@ -123,7 +123,7 @@ async function downloadToFile(

async function _downloadToFile(
sourceURL: string,
targetPath: string
targetPath: string,
): Promise<void> {
const response = await fetch(sourceURL, {
headers: { Referer: "https://openskimap.org" },
Expand Down
14 changes: 7 additions & 7 deletions src/transforms/Elevation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FeatureType, LiftFeature, RunFeature } from "openskidata-format";
const elevationProfileResolution = 25;

export default function addElevation(
elevationServerURL: string
elevationServerURL: string,
): (feature: RunFeature | LiftFeature) => Promise<RunFeature | LiftFeature> {
return async (feature: RunFeature | LiftFeature) => {
const coordinates: number[][] = getCoordinates(feature);
Expand All @@ -18,7 +18,7 @@ export default function addElevation(
Array.from(coordinates)
.concat(elevationProfileCoordinates)
.map(([lng, lat]) => [lat, lng]),
elevationServerURL
elevationServerURL,
);
} catch (error) {
console.log("Failed to load elevations", error);
Expand All @@ -28,7 +28,7 @@ export default function addElevation(
const coordinateElevations = elevations.slice(0, coordinates.length);
const profileElevations = elevations.slice(
coordinates.length,
elevations.length
elevations.length,
);

if (feature.properties.type === FeatureType.Run) {
Expand All @@ -48,7 +48,7 @@ export default function addElevation(

async function loadElevations(
coordinates: number[][],
elevationServerURL: string
elevationServerURL: string,
): Promise<number[]> {
const response = await fetch(elevationServerURL, {
method: "POST",
Expand All @@ -70,7 +70,7 @@ async function loadElevations(
coordinates.length +
") is different than number of elevations (" +
elevations.length +
")"
")",
);
}

Expand Down Expand Up @@ -113,7 +113,7 @@ function getCoordinatesForElevationProfile(feature: RunFeature | LiftFeature) {
const subfeatures = turfLineChunk(
feature.geometry,
elevationProfileResolution,
{ units: "meters" }
{ units: "meters" },
).features;
const points: [number, number][] = [];
for (let subline of subfeatures) {
Expand All @@ -139,7 +139,7 @@ function getCoordinatesForElevationProfile(feature: RunFeature | LiftFeature) {

function addElevations(
feature: RunFeature | LiftFeature,
elevations: number[]
elevations: number[],
) {
let i = 0;
switch (feature.geometry.type) {
Expand Down
18 changes: 9 additions & 9 deletions src/transforms/Geocoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class Geocoder {
{
batch: false,
cacheMap: new LRUMap(config.inMemoryCacheSize),
}
},
);
}

Expand All @@ -63,12 +63,12 @@ export default class Geocoder {
};

private geocodeInternal = async (
geohash: string
geohash: string,
): Promise<Geocode | null> => {
try {
const cacheObject = await cacache.get(
this.config.cacheDir,
cacheKey(geohash)
cacheKey(geohash),
);
const content = JSON.parse(cacheObject.data.toString());
if (content.timestamp + this.config.diskTTL < currentTimestamp()) {
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class Geocoder {
error !== null || (response !== null && response.status >= 400)
);
},
}
},
).then((res) => res.json());

await cacache.put(
Expand All @@ -117,7 +117,7 @@ export default class Geocoder {
JSON.stringify({
data: response,
timestamp: currentTimestamp(),
})
}),
);
return this.enhance(response);
});
Expand All @@ -126,7 +126,7 @@ export default class Geocoder {
private enhance = (rawGeocode: PhotonGeocode): Geocode | null => {
console.assert(
rawGeocode.features.length <= 1,
"Expected Photon geocode to only have at most a single feature."
"Expected Photon geocode to only have at most a single feature.",
);
if (rawGeocode.features.length === 0) {
return null;
Expand All @@ -140,7 +140,7 @@ export default class Geocoder {
const country = iso3166_2.getDataSet()[properties.countrycode];
if (!country) {
console.log(
`Could not find country info for code ${properties.countrycode}`
`Could not find country info for code ${properties.countrycode}`,
);
return null;
}
Expand All @@ -150,14 +150,14 @@ export default class Geocoder {
if (properties.state !== undefined) {
region =
country.regions.find(
(region: Region) => region.name === properties.state
(region: Region) => region.name === properties.state,
) || null;
}

if (region === null && properties.county !== undefined) {
region =
country.regions.find(
(region: Region) => region.name === properties.county
(region: Region) => region.name === properties.county,
) || null;
}

Expand Down
20 changes: 10 additions & 10 deletions src/transforms/Geocoder.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe("Geocoder", () => {
"DE",
"Bavaria",
"Landkreis Garmisch-Partenkirchen",
undefined
)
undefined,
),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand All @@ -121,8 +121,8 @@ describe("Geocoder", () => {
"DE",
"Bavaria",
"Landkreis Garmisch-Partenkirchen",
"Mittenwald"
)
"Mittenwald",
),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand All @@ -145,7 +145,7 @@ describe("Geocoder", () => {
it("can enhance a US geocode", async () => {
// https://photon.komoot.io/reverse?lon=-120.238408&lat=39.154157&lang=en
mockHTTPResponse(
mockPhotonGeocode("US", "California", "Placer County", "Alpine Meadows")
mockPhotonGeocode("US", "California", "Placer County", "Alpine Meadows"),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand All @@ -168,7 +168,7 @@ describe("Geocoder", () => {
it("can enhance a Czechia geocode", async () => {
// https://photon.komoot.io/reverse?lon=15.51456&lat=50.68039&lang=en
mockHTTPResponse(
mockPhotonGeocode("CZ", "Northeast", "Liberec Region", "Vítkovice")
mockPhotonGeocode("CZ", "Northeast", "Liberec Region", "Vítkovice"),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand All @@ -191,7 +191,7 @@ describe("Geocoder", () => {
it("can enhance a Japan geocode", async () => {
// https://photon.komoot.io/reverse?lon=132.3609&lat=34.8246&lang=en
mockHTTPResponse(
mockPhotonGeocode("JP", "Shimane Prefecture", undefined, "Hamada")
mockPhotonGeocode("JP", "Shimane Prefecture", undefined, "Hamada"),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand All @@ -213,7 +213,7 @@ describe("Geocoder", () => {

it("does not geocode invalid country", async () => {
mockHTTPResponse(
mockPhotonGeocode("DEUS", undefined, undefined, undefined)
mockPhotonGeocode("DEUS", undefined, undefined, undefined),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand All @@ -223,7 +223,7 @@ describe("Geocoder", () => {

it("does not geocode invalid region", async () => {
mockHTTPResponse(
mockPhotonGeocode("DE", "British Columbia", undefined, undefined)
mockPhotonGeocode("DE", "British Columbia", undefined, undefined),
);

const result = await defaultGeocoder().geocode([0, 0]);
Expand Down Expand Up @@ -272,7 +272,7 @@ function mockPhotonGeocode(
countryCode: string | undefined,
state: string | undefined,
county: string | undefined,
city: string | undefined
city: string | undefined,
): PhotonGeocode {
return {
type: "FeatureCollection",
Expand Down

0 comments on commit 42a1872

Please sign in to comment.