diff --git a/server/Flask/main.py b/server/Flask/main.py index 349cf99..9fb35a1 100644 --- a/server/Flask/main.py +++ b/server/Flask/main.py @@ -49,9 +49,9 @@ def loginDB(): ) return mydb -def getData(node, dataType, MAC, dateStart, dateEnd): +def getData(node, dataTypes, MAC, dateStart, dateEnd): mydb = loginDB() - query = get_query(node, dataType, MAC, False, False, dateStart, dateEnd) + query = get_query(node, dataTypes, MAC, False, False, dateStart, dateEnd) cursor = mydb.cursor(dictionary=True) # Enable dictionary output cursor.execute(query) result = cursor.fetchall() # Fetch the results @@ -62,7 +62,7 @@ def getData(node, dataType, MAC, dateStart, dateEnd): def getNodeInfo(macAdress): mydb = loginDB() - query = get_query(False, False, macAdress, False, False) + query = get_query(False, False, macAdress, False, False, False, False) cursor = mydb.cursor(dictionary=True) # Enable dictionary output cursor.execute(query) result = cursor.fetchall() # Fetch the results diff --git a/server/Flask/queries.py b/server/Flask/queries.py index 2257b79..0211c8d 100644 --- a/server/Flask/queries.py +++ b/server/Flask/queries.py @@ -1,5 +1,9 @@ def get_query(node, dataType, MAC, questionID, replies, dateStart, dateEnd): - if dateStart and dateEnd and node: + if dateStart and dateEnd and node and dataType: + query = f'''SELECT * + FROM Measurement + WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}' AND NodeID = {node} AND Type IN ('{dataType}');''' + elif dateStart and dateEnd and node: query = f'''SELECT * FROM Measurement WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}' AND NodeID = {node};''' @@ -21,10 +25,7 @@ def get_query(node, dataType, MAC, questionID, replies, dateStart, dateEnd): query = f"SELECT * FROM Question" elif replies: query = f"SELECT * FROM Reply" - elif dateStart and dateEnd and node: - query = f'''SELECT * - FROM Measurement - WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}';''' + else: query = "SELECT * FROM `Measurement`" return query diff --git a/web/newWebsite/graph-classes.js b/web/newWebsite/graph-classes.js index 3e6e359..9700ab0 100644 --- a/web/newWebsite/graph-classes.js +++ b/web/newWebsite/graph-classes.js @@ -42,8 +42,7 @@ class Graph { } updateData(type, value, timestamp) { - this.timeArray.push(timestamp); - + // this.timeArray.push(timestamp); switch (type) { case "Temp": this.tempArray.push(value); @@ -67,7 +66,7 @@ class Graph { x: [this.timeArray], y: [this.tempArray, this.humiArray, this.eco2Array, this.tvocArray], }; - + console.log(update); Plotly.update(this.id, update); } } @@ -140,10 +139,19 @@ class DataProcessor { } updateGraph() { + this.graph.timeArray = []; + this.graph.tempArray = []; + this.graph.humiArray = []; + this.graph.eco2Array = []; + this.graph.tvocArray = []; + for (let i = 0; i < this.data.length; i++) { + if (i % 4 == 0){ + this.graph.timeArray.push(this.data[i].TimeStamp); + } this.graph.updateData(this.data[i].Type, this.data[i].Value, this.data[i].TimeStamp); console.log(this.data[i].Type, this.data[i].Value, this.data[i].TimeStamp); - this.graph.updateGraph(); } - } + this.graph.updateGraph(); + } } diff --git a/web/newWebsite/graph-main.js b/web/newWebsite/graph-main.js index e07f628..cd9760a 100644 --- a/web/newWebsite/graph-main.js +++ b/web/newWebsite/graph-main.js @@ -24,10 +24,10 @@ container.setAttribute("class", "container"); const dataTypesContainer = document.createElement("div"); dataTypesContainer.setAttribute("class", "data-types"); -const temperatureCheckbox = createCheckBox("temperature", "Temperature"); -const humidityCheckbox = createCheckBox("humidity", "Humidity"); -const eco2Checkbox = createCheckBox("eco2", "eCO2"); -const tvocCheckbox = createCheckBox("tvoc", "TVOC"); +const temperatureCheckbox = createCheckBox("Temp", "Temperature"); +const humidityCheckbox = createCheckBox("Humi", "Humidity"); +const eco2Checkbox = createCheckBox("eCO2", "eCO2"); +const tvocCheckbox = createCheckBox("TVOC", "TVOC"); dataTypesContainer.appendChild(temperatureCheckbox.checkbox); dataTypesContainer.appendChild(temperatureCheckbox.checkboxLabel); @@ -55,24 +55,30 @@ filterButton.addEventListener("click", () => { temperatureCheckbox, humidityCheckbox, eco2Checkbox, - tvocCheckbox, + tvocCheckbox ]; + checkboxes.forEach((checkbox) => { if (checkbox.checkbox.checked) { - selectedFields.push(checkbox.checkbox.id); + selectedFields.push(String(checkbox.checkbox.id)); } }); + let selectedFieldsString = selectedFields.map(String); + + let formattedString = '(' + selectedFieldsString.map(item => `'${item}'`).join(', ') + ')'; + const filteredData = [ startDate, endDate, selectedNodes, - selectedFields + formattedString ]; + console.log(filteredData); console.log(startDate, endDate, selectedNodes); - generateLink(startDate, endDate, selectedNodes); + generateLink(startDate, endDate, selectedNodes, formattedString); fetchData(); }); @@ -98,7 +104,7 @@ nodeFilter.setAttribute("class", "node-filter"); const nodeInput = document.createElement("input"); nodeInput.setAttribute("type", "text"); -nodeInput.setAttribute("placeholder", "Enter node (A, B, etc.)"); +nodeInput.setAttribute("placeholder", "Enter Node Name (* for all)"); nodeInput.setAttribute("id", "node-input"); nodeInput.setAttribute("class", "input-field"); @@ -110,12 +116,12 @@ container.appendChild(filterButton); document.body.appendChild(container); // Function to get the link for the get request -function generateLink(dateStart, dateEnd, node) { +function generateLink(dateStart, dateEnd, node, dataTypes) { const baseUrl = 'http://145.92.8.114/getMeasurements'; const formattedDateStart = new Date(dateStart).toISOString().replace('T', '%20'); const formattedDateEnd = new Date(dateEnd).toISOString().replace('T', '%20'); - link = `${baseUrl}?dateStart=${formattedDateStart}&dateEnd=${formattedDateEnd}&node=${node}`; + link = `${baseUrl}?dateStart=${formattedDateStart}&dateEnd=${formattedDateEnd}&node=${node}&dataType=${dataTypes}`; console.log(link); } diff --git a/web/newWebsite/questions-chart-class.js b/web/newWebsite/questions-chart-class.js new file mode 100644 index 0000000..42467d9 --- /dev/null +++ b/web/newWebsite/questions-chart-class.js @@ -0,0 +1,27 @@ +class ChartConfigClass{ + constructor(data, text){ + this.data = data + this.text = text + } + + get chartConfig() { + return{ + type: 'pie', + data: this.data, + options: { + responsive: true, + legend: { + position: 'top', + }, + title: { + display: true, + text: this.text + }, + animation: { + animateScale: true, + animateRotate: true + } + } + } + } +} \ No newline at end of file diff --git a/web/newWebsite/questions-main-class.js b/web/newWebsite/questions-creation-class.js similarity index 100% rename from web/newWebsite/questions-main-class.js rename to web/newWebsite/questions-creation-class.js diff --git a/web/newWebsite/questions-dashboard.html b/web/newWebsite/questions-dashboard.html index 46dad55..5ce5f66 100644 --- a/web/newWebsite/questions-dashboard.html +++ b/web/newWebsite/questions-dashboard.html @@ -30,24 +30,30 @@