Files
MSE-SoftwEng/web-app/src/TimeSeriesManager.ts

49 lines
1.2 KiB
TypeScript

import { Prop } from "vue";
import { Serie } from "./Measures/Serie";
import { HttpClient } from "./Services/HttpClient";
import { TEMPERATURE, HUMIDITY, TYPE, VALUE } from "./const";
export class TimeSeriesManager {
private client: HttpClient;
constructor(client: HttpClient) {
this.client = client;
}
async getTimeSeriesData(
user: string,
room: string,
device: string
): Promise<{ temperature: Serie; humidity: Serie }> {
return this.client
.getValues(user, room, device)
.then((response) => {
console.log(response);
const serie_temperature = new Serie(
TEMPERATURE,
response.data.filter((x: any) => x[TYPE] === TEMPERATURE),
user,
room,
device
);
const serie_humidity = new Serie(
HUMIDITY,
response.data.filter((x: any) => x[TYPE] === HUMIDITY),
user,
room,
device
);
return {
temperature: serie_temperature,
humidity: serie_humidity,
};
})
.catch((error) => {
console.error("Error fetching time series data:", error);
throw error; // Re-throw to allow calling code to handle it
});
}
}