New and improved in sveltekit

This commit is contained in:
2023-05-22 22:29:43 +02:00
parent 4c5ede45a1
commit 23d4b727e6
78 changed files with 6148 additions and 648 deletions

View File

@@ -0,0 +1,38 @@
import { fetchTemperature, fetchHumidity, fetchPressure } from '$lib/graphQueryGenerator';
import type { PageServerLoad } from './$types';
import type IChartFrame from '$lib/interfaces/IChartFrame';
let DEFAULT_MINUTES = 10080;
export const load: PageServerLoad = async ({ fetch }) => {
const temperatureData: IChartFrame[] = await getTemp(DEFAULT_MINUTES, fetch);
const humidityData: IChartFrame[] = await getHumidity(DEFAULT_MINUTES, fetch);
const pressureData: IChartFrame[] = await getPressure(DEFAULT_MINUTES, fetch);
return {
temperatureData,
humidityData,
pressureData,
DEFAULT_MINUTES
};
};
function getSensor(func: Function, minutes: number, fetch: Function) {
const from: Date = new Date();
const to = new Date(from.getTime() - minutes * 60 * 1000);
const size = 40;
return func(from, to, size, fetch);
}
function getTemp(minutes: number, fetch: Function): IChartFrame[] {
return getSensor(fetchTemperature, minutes, fetch);
}
function getHumidity(minutes: number, fetch: Function): IChartFrame[] {
return getSensor(fetchHumidity, minutes, fetch);
}
function getPressure(minutes: number, fetch: Function): IChartFrame[] {
return getSensor(fetchPressure, minutes, fetch);
}