chore: add prettier formatting
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s

This commit is contained in:
zv
2026-06-14 20:26:56 +02:00
parent 8bbd9397a1
commit ee55521803
79 changed files with 2451 additions and 969 deletions

View File

@@ -30,10 +30,11 @@ function normalizeName(value: string) {
function distanceKm(latitudeA: number, longitudeA: number, latitudeB: number, longitudeB: number) {
const earthRadiusKm = 6371;
const toRadians = (value: number) => value * Math.PI / 180;
const toRadians = (value: number) => (value * Math.PI) / 180;
const latitudeDistance = toRadians(latitudeB - latitudeA);
const longitudeDistance = toRadians(longitudeB - longitudeA);
const a = Math.sin(latitudeDistance / 2) ** 2 +
const a =
Math.sin(latitudeDistance / 2) ** 2 +
Math.cos(toRadians(latitudeA)) * Math.cos(toRadians(latitudeB)) * Math.sin(longitudeDistance / 2) ** 2;
return earthRadiusKm * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
@@ -81,17 +82,31 @@ export function findNearestSynopStation(
}
export function createSelectedLocation(
location: Pick<LocationSearchResult, "name" | "province" | "district" | "country" | "countryCode" | "admin1" | "admin2" | "timezone" | "region" | "latitude" | "longitude">,
location: Pick<
LocationSearchResult,
| "name"
| "province"
| "district"
| "country"
| "countryCode"
| "admin1"
| "admin2"
| "timezone"
| "region"
| "latitude"
| "longitude"
>,
stations: LocatedSynopStation[],
): SelectedLocation {
const countryCode = location.countryCode?.toUpperCase() ?? null;
const region = location.region ?? getWeatherRegionForCountryCode(countryCode);
const nearest = region === "PL"
? stations.reduce<{ station: LocatedSynopStation; distanceKm: number } | null>((best, station) => {
const distance = distanceKm(location.latitude, location.longitude, station.latitude, station.longitude);
return !best || distance < best.distanceKm ? { station, distanceKm: distance } : best;
}, null)
: null;
const nearest =
region === "PL"
? stations.reduce<{ station: LocatedSynopStation; distanceKm: number } | null>((best, station) => {
const distance = distanceKm(location.latitude, location.longitude, station.latitude, station.longitude);
return !best || distance < best.distanceKm ? { station, distanceKm: distance } : best;
}, null)
: null;
return {
name: location.name,
@@ -103,7 +118,8 @@ export function createSelectedLocation(
admin2: location.admin2,
timezone: location.timezone,
region,
countyTeryt: region === "PL" ? getCountyTerytForLocation(location.province, location.district, location.name) : null,
countyTeryt:
region === "PL" ? getCountyTerytForLocation(location.province, location.district, location.name) : null,
latitude: location.latitude,
longitude: location.longitude,
stationId: nearest?.station.id ?? null,