diff --git a/src/ambient.d.ts b/src/ambient.d.ts index b44af06..5eb821a 100644 --- a/src/ambient.d.ts +++ b/src/ambient.d.ts @@ -9,6 +9,17 @@ type WeatherDataCurrent = { windSpeed10m: number; } +type AirQualityCurrent = { + time: Date; + dust: number; + pm10: number; + pm25: number; +} + type WeatherData = { current: WeatherDataCurrent +} + +type AirQualityData = { + current: AirQualityCurrent } \ No newline at end of file diff --git a/src/lib/generators/weather/WeatherGen.svelte b/src/lib/generators/weather/WeatherGen.svelte index fb23aec..37adbf7 100644 --- a/src/lib/generators/weather/WeatherGen.svelte +++ b/src/lib/generators/weather/WeatherGen.svelte @@ -19,6 +19,7 @@ let gain: Tone.Gain | null = null; + //TODO - ADD DIFFERENT PROGRESSIONS const chordProgressions = [ [ { time: "0:0:0", notes: ['C4', 'E4', 'G4', 'B4'] }, @@ -48,9 +49,8 @@ let currentProgression = $state(chordProgressions[0]); - // Derived reactive values using runes - const bpm = $derived((temperature2m)); + const bpm = $derived((isDay? temperature2m * 2 : temperature2m)); const reverbWet = $derived(relativeHumidity2m/100); const delayWet = $derived(Math.round(windSpeed10m)/10); const phaserBase = $derived((1 / cloudCover) * 100); diff --git a/src/routes/on-out/+page.svelte b/src/routes/on-out/+page.svelte index 246063b..8eb92b7 100644 --- a/src/routes/on-out/+page.svelte +++ b/src/routes/on-out/+page.svelte @@ -4,9 +4,12 @@ import type { PageProps } from './$types'; const { data }: PageProps = $props(); - const currentWeather = data.current; + const currentWeather = data.weatherData.current; + const currentAirQuality = data.airQualityData.current; + $inspect(currentWeather) + $inspect(currentAirQuality) diff --git a/src/routes/on-out/+page.ts b/src/routes/on-out/+page.ts index 59a5a0c..bc5e7c3 100644 --- a/src/routes/on-out/+page.ts +++ b/src/routes/on-out/+page.ts @@ -6,6 +6,14 @@ export const load: PageLoad = async ({ url }) => { const lat = url.searchParams.get('lat'); const long = url.searchParams.get('long'); + const weatherData = await getWeather(lat!, long!); + const airQualityData = await getAirQuality(lat!, long!); + + return {weatherData, airQualityData} +}; + + +const getWeather = async (long: string, lat: string): Promise => { const apiParams = { "latitude": lat, "longitude": long, @@ -35,4 +43,34 @@ export const load: PageLoad = async ({ url }) => { }; return weatherData -}; \ No newline at end of file +} + +const getAirQuality = async (long: string, lat: string): Promise => { + const params = { + "latitude": lat, + "longitude": long, + "current": ["dust", "pm10", "pm2_5"] + }; + const url = "https://air-quality-api.open-meteo.com/v1/air-quality"; + const responses = await fetchWeatherApi(url, params); + + // Process first location. Add a for-loop for multiple locations or weather models + const response = responses[0]; + + // Attributes for timezone and location + const utcOffsetSeconds = response.utcOffsetSeconds(); + + const current = response.current()!; + + // Note: The order of weather variables in the URL query and the indices below need to match! + const airQualityData = { + current: { + time: new Date((Number(current.time()) + utcOffsetSeconds) * 1000), + dust: current.variables(0)!.value(), + pm10: current.variables(1)!.value(), + pm25: current.variables(2)!.value(), + }, + }; + + return airQualityData +} \ No newline at end of file