From 07cc13d573c35096359abae7220ecbab02c2812a Mon Sep 17 00:00:00 2001 From: Sietse Jonker Date: Fri, 22 Mar 2024 12:31:53 +0100 Subject: [PATCH] Refactor classes.js to update connection status and add feedbackNode and graph classes --- web/classes.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/web/classes.js b/web/classes.js index 49fae13..1837cef 100644 --- a/web/classes.js +++ b/web/classes.js @@ -16,12 +16,30 @@ class node { this.TVOC = TVOC; } // Function to update the connection status - updateConnection(status) { - this.connected = status; + updateConnection() { + if (connectedNodes[this.nodeId]) { + this.connected = true; + } + else { + this.connected = false; + } } } -class liveGraph { +class feedbackNode extends node { + // Constructor to initialize the feedback node + constructor(nodeId) { + super(nodeId); + this.feedback = {}; + this.answers = 0; + } + // Function to update the feedback + updateFeedback(feedback) { + this.feedback = feedback; + } +} + +class liveGraph extends node{ // Constructor to initialize the graph constructor(id) { this.timeArray = []; @@ -105,4 +123,52 @@ class liveGraph { this.eco2Array.push(eCO2 / 10); this.tvocArray.push(TVOC / 10); } +} + +class graph { + // Constructor to initialize the graph + constructor(id) { + this.timeArray = []; + this.tempArray = []; + this.humiArray = []; + this.eco2Array = []; + this.tvocArray = []; + this.nodeId = "graph" + id; + } + // Function to create a graph + makeGraph(amountOfGraphs) { + for (let i = 0; i < amountOfGraphs; i++) { + + // Create a new line for temperature + Plotly.plot(this.nodeId, [ + { + x: this.timeArray, // Use timeArray as x values + y: this.array[i], + mode: "lines", + line: { color: "#FF0000" }, + name: "Temperature", + }, + ]); + } + } + // Function to update the graph with new values got from updateData function + updateGraph() { + let time = new Date(); + this.timeArray.push(new Date()); + + let update = { + x: [[this.timeArray]], + y: [[this.tempArray], [this.humiArray], [this.eco2Array], [this.tvocArray]] + }; + + let olderTime = time.setMinutes(time.getMinutes() - 1); + let futureTime = time.setMinutes(time.getMinutes() + 1); + let minuteView = { + xaxis: { + type: "date", + range: + }, + }; + +} } \ No newline at end of file