Refactor getData function and fix query bug

This commit is contained in:
sietse jonker
2024-04-01 14:41:02 +02:00
parent 650032fced
commit 4ab7709c82
2 changed files with 7 additions and 7 deletions

View File

@@ -49,9 +49,9 @@ def loginDB():
)
return mydb
def getData(node, dataType, MAC, dateStart, dateEnd):
def getData(node, dataType, MAC, dateStart, dateEnd, type):
mydb = loginDB()
query = get_query(node, dataType, MAC, False, False, dateStart, dateEnd)
query = get_query(node, dataType, MAC, dateStart, dateEnd, type)
cursor = mydb.cursor(dictionary=True) # Enable dictionary output
cursor.execute(query)
result = cursor.fetchall() # Fetch the results

View File

@@ -1,12 +1,12 @@
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} OR;'''
elif 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}'"
elif node: