class StoreData(): def __init__(self, port, row_list, voltage, current, power, cumpower): self.port = port self.row_list = row_list self.columns = ['ax1', 'ay1', 'az1', 'gx1', 'gy1', 'gz1','ax2', 'ay2', 'az2', 'gx2', 'gy2', 'gz2'] self.df = pd.DataFrame(columns = self.columns) self.counter = 0 self.voltage = voltage self.current = current self.power = power self.cumpower = cumpower self.model = ML() def run(self): #print("storing data") self.storeData() def storeData(self): #df = pd.DataFrame(self.list, columns = self.columns, header = None) self.df.loc[self.counter] = self.row_list #self.df.append(pd.DataFrame([self.row_list], columns=self.columns), ignore_index=False) #print("list appended!") #print(self.df) self.counter += 1 #check if client program should be closed shouldClose = False #collect required amount of data for machine learning model if(self.counter == 60): #function call action = self.model.predict(self.df) print(action) if action == 'logout': shouldClose = True data = "#" + action + "|" + str(self.voltage) + "|" + str(self.current) + "|" + str(self.power) + "|" + str(self.cumpower) + "|" client.sendToServer(data, shouldClose) quit() else: #send action to server data = "#" + action + "|" + str(self.voltage) + "|" + str(self.current) + "|" + str(self.power) + "|" + str(self.cumpower) + "|" client.sendToServer(data, shouldClose) self.df = pd.DataFrame(columns=self.columns) # print('Going to sleep bye bye ...') time.sleep(2) print('Woke up.') self.counter = 0