diff --git a/server/web-data-connection/enqueteClassFile.md b/server/web-data-connection/enqueteClassFile.md index a89eb58..21821d3 100644 --- a/server/web-data-connection/enqueteClassFile.md +++ b/server/web-data-connection/enqueteClassFile.md @@ -1,6 +1,14 @@ ## Questionaire class -This file prmairly is dedicated to the class which gets its data form the questionare and pushes it to the database. -This is done this way to make the code more visable and more clear. +This File and class are dedicated to storing/using data that is related to the questionaire. This class is primairly used as a gateway for pushing data and loading data. + +By doing this a lot of space is saved on the main file and the readability wil increase. + +By doing this, it also solves the issues with the very precise naming and the often similar types of names. +This way it ensures no confusion on what the purpous of each segement is. + +First up this page imports different types of information, like the library's and the needed files and/or Node. + + ```py #Importing different librarys. import mysql.connector @@ -9,8 +17,19 @@ import json from classes_data import Node from classes_data import dbLogin ``` -Here a class is made to again provide more clear viewing and more reusability. -The +Here a Class is made as a child-class of the parent-class: "Node". + +This clas first makes a private variable, this being: "__query". +This is done so no other outside sources can interfere with this query and potentially cause problems down the line. + +After this the "__init__"function is called. +(In javascript this is known as the "constructor". +For further information visit https://www.w3schools.com/python/gloss_python_class_init.asp) + +Because this class is a child class, we want to use some functionality from the parent class. That is where the "super" comes in. This makes it so the class uses the values and propperties of the parent class. (for more information visit https://www.w3schools.com/python/python_inheritance.asp) + +The rest of the class contains a function in which the gatherd data +gets put into the database using the query and the gatherd data. ```py #Node is between brackets to show that this class is a child class from the parent class "Node" class EnqueteNode(Node): @@ -21,14 +40,25 @@ class EnqueteNode(Node): super().__init__(macAdress) self.response = response self.questionID = questionID +``` +The following function is meant to make a database connection, get the data from the websocket (this data will only be from the questionaire-node) +and send the gotten data to the database. + +The function starts with the database connection and calls uppon the websocket data. +It then creates variables with the data to put it in an array. + +This array then gets sorted and pushed thogether with the query to correctly sort it and push it to the database. + +In case of an error, it also asks for errors and prints it. +```py #making a database connection to then load in the processed data. async def processEnqueteNodeData(data, nodeID): try: mydb = dbLogin() cursor = mydb.cursor() - + #Getting the websocket data. processedData = json.loads(data) - + #Making variables of the different types of data. EnqueteNode.questionID = (processedData['QuestionID']) EnqueteNode.response = (processedData['Response']) @@ -37,13 +67,12 @@ class EnqueteNode(Node): #Push the data according to the query to the database. for i in pushingDataArray: - print(EnqueteNode.__query, i) cursor.execute(EnqueteNode.__query, i) mydb.commit() - #print an error. + #print an error. except mysql.connector.Error as err: print("MySQL Error:", err) finally: cursor.close() mydb.close() -``` \ No newline at end of file +``` diff --git a/server/web-data-connection/generalDatabaseFile.md b/server/web-data-connection/generalDatabaseFile.md index c82813d..d733fce 100644 --- a/server/web-data-connection/generalDatabaseFile.md +++ b/server/web-data-connection/generalDatabaseFile.md @@ -13,6 +13,11 @@ def dbLogin(): database="NodeData" ) return mydb +``` +The "__init__"function is called. +(In javascript this is known as the "constructor". +For further information visit https://www.w3schools.com/python/gloss_python_class_init.asp) +```py # A general class which acts as a database connector and a node identifyer class Node(): diff --git a/server/web-data-connection/sensorNodeClassFile.md b/server/web-data-connection/sensorNodeClassFile.md index db8f197..4c7413c 100644 --- a/server/web-data-connection/sensorNodeClassFile.md +++ b/server/web-data-connection/sensorNodeClassFile.md @@ -9,6 +9,11 @@ import json #Import classes and functions from different files. from classes_data import Node from classes_data import dbLogin +``` +After this the "__init__"function is called. +(In javascript this is known as the "constructor". +For further information visit https://www.w3schools.com/python/gloss_python_class_init.asp) +```py #A class to send data to the database. child class of "Node" class SensorNode(Node): #A private query only to be used in this class.