diff --git a/client/src/components/CurrentWeather.vue b/client/src/components/CurrentWeather.vue index f7b7b52..fab2a33 100644 --- a/client/src/components/CurrentWeather.vue +++ b/client/src/components/CurrentWeather.vue @@ -142,10 +142,10 @@ onMounted(async () => {
-
Precipitation{{ !data.precipitation && data.raining == 'True' ? 'Spitting' : data.precipitation?.toFixed(1) + 'mm'}}
-
Humidity{{ data.humidity?.toFixed(0) }}%
-
Wind{{ data.wind_gusts }} Kph ({{ dir(data.wind_direction) }})
-
Clouds{{ data.clouds?.toFixed(0) }}%
+
Precipitation{{ !data.precipitation && data.raining == 'True' ? 'Spitting' : (data.precipitation || 0).toFixed(1) + 'mm'}}
+
Humidity{{ (data.humidity || 0).toFixed(0) }}%
+
Wind{{ data.wind_gusts || 0 }} Kph ({{ dir(data.wind_direction || 0) }})
+
Clouds{{ (data.clouds || 0).toFixed(0) }}%
Air Quality{{ data.air_quality }} ({{data.air_quality_label}})
UV index{{ data.uv_index }}
diff --git a/server/icons.mjs b/server/openweather.mjs similarity index 67% rename from server/icons.mjs rename to server/openweather.mjs index 0554499..8caf5c8 100644 --- a/server/icons.mjs +++ b/server/openweather.mjs @@ -50,3 +50,35 @@ export async function downloadIcons() { })) console.log('✅ Weather icons ready') } + +export function getWeatherCondition(data) { + // Determine primary condition + if (data.lightning_rate > 0 && data.raining === "True") { + return { label: "Thunderstorm", code: 211, icon: "11d" }; + } + + if (data.raining === "True") { + if (data.precipitation > 7.6) return { label: "Heavy Rain", code: 502, icon: "10d" }; + if (data.precipitation > 2.5) return { label: "Moderate Rain", code: 501, icon: "10d" }; + return { label: "Light Rain", code: 500, icon: "09d" }; + } + + if (data.lightning_rate > 500) { + return { label: "Thunderstorm", code: 211, icon: "11d" }; + } + + if (data.visibility < 10) { + return { label: "Mist", code: 701, icon: "50d" }; + } + + // Cloud-based conditions + const isDay = data.daytime; + const dayNight = isDay ? "d" : "n"; + + if (data.clouds > 85) return { label: "Overcast Clouds", code: 804, icon: `04${dayNight}` }; + if (data.clouds > 50) return { label: "Broken Clouds", code: 803, icon: `04${dayNight}` }; + if (data.clouds > 25) return { label: "Scattered Clouds",code: 802, icon: `03${dayNight}` }; + if (data.clouds > 10) return { label: "Few Clouds", code: 801, icon: `02${dayNight}` }; + + return { label: "Clear Sky", code: 800, icon: `01${dayNight}` }; +} diff --git a/server/server.mjs b/server/server.mjs index c26a994..6edab4e 100644 --- a/server/server.mjs +++ b/server/server.mjs @@ -10,6 +10,7 @@ import {apiReference} from '@scalar/express-api-reference'; import {spec} from './spec.mjs'; import {existsSync} from 'fs'; import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs'; +import {getWeatherCondition} from './openweather.mjs'; const app = express(); const DIR = dirname(fileURLToPath(import.meta.url)); @@ -39,8 +40,9 @@ function filterArr(arr, fields) { app.get('/api/current', async (req, res) => { const {fields} = req.query; const [sensors, coords] = await Promise.all([queryCurrent(), getCoords()]); + const condition = getWeatherCondition(sensors); const space = getCelestialCurrent(coords.latitude, coords.longitude); - res.json(filterFields({...sensors, ...space}, fields)); + res.json(filterFields({...condition, ...sensors, ...space}, fields)); }); // ── Position ──────────────────────────────────────────────────────────────────