database documentation update

This commit is contained in:
Bram Barbieri
2024-04-04 19:16:25 +02:00
parent fa7baccffd
commit d4b44e33b3

View File

@@ -68,18 +68,34 @@ The MAC address is then taken and turned into a tuple. This is done because the
#make a tuple of the MAC by placing a comma.
MACTuple = (processedMAC,)
```
Coming back to previous lines of code, the data which was first aked for is now gatherd and gets put in an array.
Coming back to the previous lines of code, the data which was first asked for is now gathered and put into an array.
This array is then examined, and all the data is compared to the newly obtained MAC address.
If it is not found, then the new MAC address is added to the database. This makes automation much easier and makes the process of adding a new node easy.
```py
#fetching data and adding to an array.
MACDataFetching = MACDataReading.fetchall()
MACArray = list(MACDataFetching)
#see if the given MAC is not in the array.
if MACTuple not in MACArray:
#a query to insert the new MAC in the DB
addingNode = "INSERT INTO `Node` (MAC) VALUES (%s)"
#combine the query and the data and push it.
cursor.execute(addingNode, MACTuple)
mydb.commit()
```
From here the data which was collected from the websocket gets placed in an array together with a few guidlines to propperly place it in the correct files on the database.
After going along all instances of the array, the data gets pushed together with the query to propperly enter the database.
Sadly this version of the code is only able to push the data from the one node because of some errors within the datase.
(This is later fixed in the updated version my teammate made.)
```py
#making an array with the data to sort it and be able to be pushed to the database.
pushingDataArray = [(1, "Temp", processedTemp), (1, "Humi", processedHumi), (1, "eCO2", processedeCO2), (1, "TVOC", processedTvoc)]
#go along all instances in the array, and combine this with the query.
for i in pushingDataArray:
print(query ,i)
cursor.execute(query, i)