init
This commit is contained in:
commit
6250d23297
53 changed files with 6381 additions and 0 deletions
32
lib/weather/providers/openweather/shared.ts
Normal file
32
lib/weather/providers/openweather/shared.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import type { Condition } from "../../types";
|
||||
|
||||
/** Shared by both OpenWeather plans. */
|
||||
|
||||
export const OWM_LABEL = "OpenWeather";
|
||||
|
||||
export interface OwmWeatherTag {
|
||||
id: number;
|
||||
description: string;
|
||||
icon: string; // ends in "d" (day) or "n" (night)
|
||||
}
|
||||
|
||||
/** Condition codes: https://openweathermap.org/weather-conditions */
|
||||
export function toCondition(code: number): Condition {
|
||||
if (code >= 200 && code < 300) return "storm";
|
||||
if (code >= 300 && code < 600) return "rain"; // drizzle + rain
|
||||
if (code >= 600 && code < 700) return "snow";
|
||||
if (code >= 700 && code < 800) return "fog"; // mist, haze, smoke, dust…
|
||||
if (code === 800) return "clear";
|
||||
return "clouds";
|
||||
}
|
||||
|
||||
/** OpenWeather gives probability of precipitation as 0–1; we use 0–100. */
|
||||
export function popToPercent(pop: number | undefined): number | null {
|
||||
return pop === undefined ? null : Math.round(pop * 100);
|
||||
}
|
||||
|
||||
/** Rain + snow volume, either of which may be missing. */
|
||||
export function precipitation(rain?: number, snow?: number): number | null {
|
||||
if (rain === undefined && snow === undefined) return null;
|
||||
return Math.round(((rain ?? 0) + (snow ?? 0)) * 10) / 10;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue