add air quality data
This commit is contained in:
11
src/ambient.d.ts
vendored
11
src/ambient.d.ts
vendored
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -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<WeatherData> => {
|
||||
const apiParams = {
|
||||
"latitude": lat,
|
||||
"longitude": long,
|
||||
@@ -35,4 +43,34 @@ export const load: PageLoad = async ({ url }) => {
|
||||
};
|
||||
|
||||
return weatherData
|
||||
};
|
||||
}
|
||||
|
||||
const getAirQuality = async (long: string, lat: string): Promise<AirQualityData> => {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user