Merge branch 'main' of gitlab.fdmci.hva.nl:propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
def get_query(node, dataType, MAC, questionID, replies, dateStart, dateEnd):
|
def get_query(node, dataType, MAC, questionID, replies, dateStart, dateEnd):
|
||||||
if node and dataType:
|
if dateStart and dateEnd and node:
|
||||||
|
query = f'''SELECT *
|
||||||
|
FROM Measurement
|
||||||
|
WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}' AND NodeID = {node};'''
|
||||||
|
elif dateStart and dateEnd:
|
||||||
|
query = f'''SELECT *
|
||||||
|
FROM Measurement
|
||||||
|
WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}';'''
|
||||||
|
elif node and dataType:
|
||||||
query = f"SELECT * FROM Measurement WHERE NodeID = {node} AND Type = '{dataType}'"
|
query = f"SELECT * FROM Measurement WHERE NodeID = {node} AND Type = '{dataType}'"
|
||||||
elif node:
|
elif node:
|
||||||
query = f"SELECT * FROM Measurement WHERE NodeID = {node}"
|
query = f"SELECT * FROM Measurement WHERE NodeID = {node}"
|
||||||
@@ -13,7 +21,7 @@ def get_query(node, dataType, MAC, questionID, replies, dateStart, dateEnd):
|
|||||||
query = f"SELECT * FROM Question"
|
query = f"SELECT * FROM Question"
|
||||||
elif replies:
|
elif replies:
|
||||||
query = f"SELECT * FROM Reply"
|
query = f"SELECT * FROM Reply"
|
||||||
elif dateStart and dateEnd:
|
elif dateStart and dateEnd and node:
|
||||||
query = f'''SELECT *
|
query = f'''SELECT *
|
||||||
FROM Measurement
|
FROM Measurement
|
||||||
WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}';'''
|
WHERE TimeStamp BETWEEN '{dateStart}' AND '{dateEnd}';'''
|
||||||
|
@@ -10,6 +10,9 @@ class Graph {
|
|||||||
|
|
||||||
// Function to create a graph
|
// Function to create a graph
|
||||||
makeGraph(line, lineColor, name) {
|
makeGraph(line, lineColor, name) {
|
||||||
|
let div = document.createElement("div");
|
||||||
|
div.setAttribute("id", this.id);
|
||||||
|
document.body.appendChild(div);
|
||||||
let lineArray;
|
let lineArray;
|
||||||
switch (line) {
|
switch (line) {
|
||||||
case "temp":
|
case "temp":
|
||||||
@@ -27,7 +30,6 @@ class Graph {
|
|||||||
default:
|
default:
|
||||||
console.error("Invalid line");
|
console.error("Invalid line");
|
||||||
}
|
}
|
||||||
this.timeArray.push(new Date());
|
|
||||||
Plotly.plot(this.id, [
|
Plotly.plot(this.id, [
|
||||||
{
|
{
|
||||||
x: this.timeArray,
|
x: this.timeArray,
|
||||||
@@ -39,7 +41,9 @@ class Graph {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateData(type, value) {
|
updateData(type, value, timestamp) {
|
||||||
|
this.timeArray.push(timestamp);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "Temp":
|
case "Temp":
|
||||||
this.tempArray.push(value);
|
this.tempArray.push(value);
|
||||||
@@ -59,8 +63,6 @@ class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateGraph() {
|
updateGraph() {
|
||||||
let time = new Date();
|
|
||||||
this.timeArray.push(time);
|
|
||||||
let update = {
|
let update = {
|
||||||
x: [[this.timeArray]],
|
x: [[this.timeArray]],
|
||||||
y: [
|
y: [
|
||||||
@@ -71,15 +73,7 @@ class Graph {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let olderTime = time.setMinutes(time.getMinutes() - 1);
|
Plotly.relayout(this.id, update);
|
||||||
let futureTime = time.setMinutes(time.getMinutes() + 1);
|
|
||||||
let minuteView = {
|
|
||||||
xaxis: {
|
|
||||||
type: "date",
|
|
||||||
range: [olderTime, futureTime],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Plotly.relayout(this.id, minuteView);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +136,6 @@ class DataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeGraph() {
|
makeGraph() {
|
||||||
let div = document.createElement("div");
|
|
||||||
div.setAttribute("id", "graph1");
|
|
||||||
document.body.appendChild(div);
|
|
||||||
this.graph = new Graph(1);
|
this.graph = new Graph(1);
|
||||||
this.graph.makeGraph("temp", "red", "Temperature");
|
this.graph.makeGraph("temp", "red", "Temperature");
|
||||||
this.graph.makeGraph("humi", "blue", "Humidity");
|
this.graph.makeGraph("humi", "blue", "Humidity");
|
||||||
@@ -153,15 +144,10 @@ class DataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateGraph() {
|
updateGraph() {
|
||||||
this.graph.updateData(this.data[0].Type, this.data[0].Value);
|
for (let i = 0; i < this.data.length; i++) {
|
||||||
console.log(this.data[0].Type, this.data[0].Value);
|
this.graph.updateData(this.data[i].Type, this.data[i].Value, this.data[i].TimeStamp);
|
||||||
this.graph.updateData(this.data[1].Type, this.data[1].Value);
|
console.log(this.data[i].Type, this.data[i].Value, this.data[i].TimeStamp);
|
||||||
console.log(this.data[1].Type, this.data[1].Value);
|
this.graph.updateGraph();
|
||||||
this.graph.updateData(this.data[2].Type, this.data[2].Value);
|
}
|
||||||
console.log(this.data[2].Type, this.data[2].Value);
|
|
||||||
this.graph.updateData(this.data[3].Type, this.data[3].Value);
|
|
||||||
console.log(this.data[3].Type, this.data[3].Value);
|
|
||||||
|
|
||||||
this.graph.updateGraph();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
// Sample data - you can replace this with your actual dataset
|
// Sample data - you can replace this with your actual dataset
|
||||||
const data = [];
|
const data = [];
|
||||||
processor = new DataProcessor();
|
processor = new DataProcessor();
|
||||||
|
|
||||||
// Function to create checkbox with label
|
// Function to create checkbox with label
|
||||||
function createCheckBox(id, label) {
|
function createCheckBox(id, label) {
|
||||||
const checkbox = document.createElement("input");
|
const checkbox = document.createElement("input");
|
||||||
@@ -107,9 +108,15 @@ function createFilterContainer() {
|
|||||||
document.body.appendChild(container);
|
document.body.appendChild(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to get the link for the get request
|
||||||
|
function getLink(startDate, endDate, node) {
|
||||||
|
return link = "http://getMeasurements?dateStart=" + startDate.toISOString() +
|
||||||
|
"&dateEnd=" + endDate.toISOString() +
|
||||||
|
"&node=" + node;
|
||||||
|
}
|
||||||
// Get request to fetch data from the server
|
// Get request to fetch data from the server
|
||||||
function fetchData() {
|
function fetchData(link) {
|
||||||
fetch("http://145.92.8.114/getMeasurements?dateStart=2024-03-27%2011:47:11&dateEnd=2024-03-27%2011:47:11")
|
fetch(link)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Network response was not ok");
|
throw new Error("Network response was not ok");
|
||||||
@@ -120,7 +127,7 @@ function fetchData() {
|
|||||||
createFilterContainer();
|
createFilterContainer();
|
||||||
processor.update(data);
|
processor.update(data);
|
||||||
processor.makeGraph();
|
processor.makeGraph();
|
||||||
processor.updateGraph();
|
processor.updateGraph(dateStart, dateEnd);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error fetching data:", error);
|
console.error("Error fetching data:", error);
|
||||||
|
Reference in New Issue
Block a user