diff --git a/web-app/src/App.vue b/web-app/src/App.vue index a5e4cd4..017b71a 100644 --- a/web-app/src/App.vue +++ b/web-app/src/App.vue @@ -1,53 +1,146 @@ diff --git a/web-app/src/Measures/Serie.ts b/web-app/src/Measures/Serie.ts index 2f9e3e3..9fa8c99 100644 --- a/web-app/src/Measures/Serie.ts +++ b/web-app/src/Measures/Serie.ts @@ -23,14 +23,16 @@ export class Serie { } public getLabel(): string { - return `${this._user} - ${this._room} - ${this._device}`; + return `${this._type} - ${this._user} - ${this._room} - ${this._device}`; } public getSerie(): any { if (this._type === TEMPERATURE) { return { label: this.getLabel(), - data: this._data, + data: this._data.map((v: any) => { + return { x: v.time, y: v.value }; + }), borderColor: "rgba(255, 99, 132, 1)", backgroundColor: "rgba(255, 99, 132, 0.2)", borderWidth: 1, @@ -38,7 +40,9 @@ export class Serie { } else if (this._type === HUMIDITY) { return { label: this.getLabel(), - data: this._data, + data: this._data.map((v: any) => { + return { x: v.time, y: v.value }; + }), borderColor: "rgba(54, 162, 235, 1)", backgroundColor: "rgba(54, 162, 235, 0.2)", borderWidth: 1, diff --git a/web-app/src/TimeSeriesManager.ts b/web-app/src/TimeSeriesManager.ts index 82ba4fc..9183073 100644 --- a/web-app/src/TimeSeriesManager.ts +++ b/web-app/src/TimeSeriesManager.ts @@ -14,31 +14,63 @@ export class TimeSeriesManager { user: string, room: string, device: string - ): Promise<{ temperature: Serie; humidity: Serie }> { + ): Promise { return this.client .getValues(user, room, device) .then((response) => { - console.log(response); - const serie_temperature = new Serie( + // Filter temperature records + let temperatureRecords = response.data.filter( + (x: any) => x[TYPE] === TEMPERATURE + ); + + // Create a new array with type field removed and time converted to timestamp + let temperatureRecordsProcessed = temperatureRecords.map((x: any) => { + // Create a new object without the TYPE field + const { [TYPE]: removed, ...rest } = x; + + // Convert the ISO time string to a timestamp (if it's a string) + if (typeof rest.time === "string") { + rest.time = new Date(rest.time).getTime(); + } + + return rest; + }); + //filter humidity records + let humidityRecord = response.data.filter( + (x: any) => x[TYPE] === HUMIDITY + ); + + // Create a new array with type field removed and time converted to timestamp + let humidityRecordProcessed = humidityRecord.map((x: any) => { + // Create a new object without the TYPE field + const { [TYPE]: removed, ...rest } = x; + + // Convert the ISO time string to a timestamp (if it's a string) + if (typeof rest.time === "string") { + rest.time = new Date(rest.time).getTime(); + } + + return rest; + }); + + // Create actual Serie instances + const temperatureSerie = new Serie( TEMPERATURE, - response.data.filter((x: any) => x[TYPE] === TEMPERATURE), + temperatureRecordsProcessed, user, room, device ); - const serie_humidity = new Serie( + const humiditySerie = new Serie( HUMIDITY, - response.data.filter((x: any) => x[TYPE] === HUMIDITY), + humidityRecordProcessed, user, room, device ); - return { - temperature: serie_temperature, - humidity: serie_humidity, - }; + return [temperatureSerie, humiditySerie]; }) .catch((error) => { console.error("Error fetching time series data:", error); diff --git a/web-app/src/components/ButtonInterace.vue b/web-app/src/components/ButtonInterace.vue deleted file mode 100644 index 1e02b78..0000000 --- a/web-app/src/components/ButtonInterace.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - diff --git a/web-app/src/components/ChartComponent.vue b/web-app/src/components/ChartComponent.vue new file mode 100644 index 0000000..a2475ee --- /dev/null +++ b/web-app/src/components/ChartComponent.vue @@ -0,0 +1,111 @@ + + + + + + diff --git a/web-app/src/components/ControlPanel.vue b/web-app/src/components/ControlPanel.vue new file mode 100644 index 0000000..5194001 --- /dev/null +++ b/web-app/src/components/ControlPanel.vue @@ -0,0 +1,130 @@ + + + + +