|
|
@@ -0,0 +1,62 @@ |
|
|
|
import bin.functions as fc |
|
|
|
import numpy as np |
|
|
|
import os |
|
|
|
import time |
|
|
|
|
|
|
|
|
|
|
|
class Arduino_data(): |
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
self.nb_captor_signals = 0 |
|
|
|
self.data_file_path = '' |
|
|
|
self.data_array = np.empty((1,1)) |
|
|
|
self.data_path_dir = os.path.abspath(os.path.dirname(__file__)) + "/data" |
|
|
|
if(not(os.path.isdir(self.data_path_dir))): #creer dossier si non existant |
|
|
|
os.mkdir(self.data_path_dir, 0o777) |
|
|
|
self.raw_data_temp = [[]] |
|
|
|
|
|
|
|
|
|
|
|
def add_captors_from_file(self, file): |
|
|
|
try: |
|
|
|
captors_file = open(file, "r") |
|
|
|
except: |
|
|
|
print("Le fichier des capteurs n'existe pas encore. Ajoutez au moins 1 capteur:\n") |
|
|
|
captors_file = open(file,"w") #création du fichier |
|
|
|
captors_file.close() |
|
|
|
self.add_captor_manually(file) |
|
|
|
else: |
|
|
|
lines = captors_file.readlines() |
|
|
|
self.nb_captor_signals = len(lines) |
|
|
|
self.data_array = np.empty((1,self.nb_captor_signals)) |
|
|
|
captors_file.close() |
|
|
|
self.raw_data_temp = np.empty((1,self.nb_captor_signals)) |
|
|
|
|
|
|
|
def add_captor_manually(self, file): |
|
|
|
self.nb_captor_signals += 1 |
|
|
|
captors_file = open(file, "a") |
|
|
|
captors_file.write(".\n") |
|
|
|
captors_file.close() |
|
|
|
self.raw_data_temp.append([]) |
|
|
|
self.data_array = np.empty((1,self.nb_captor_signals)) |
|
|
|
print("Capteur ajouté") |
|
|
|
|
|
|
|
|
|
|
|
def extract_data_to_array(self, raw_data_txt): |
|
|
|
for i in range(self.nb_captor_signals): |
|
|
|
carac_coma_nb = 1 |
|
|
|
while((raw_data_txt[carac_coma_nb] != ',') or (raw_data_txt[carac_coma_nb:carac_coma_nb+2] != "\n")): #fin de la donnee ou de la ligne |
|
|
|
carac_coma_nb +=1 |
|
|
|
single_data = int(raw_data_txt[0:carac_coma_nb]) |
|
|
|
raw_data_txt = raw_data_txt[carac_coma_nb+1:] |
|
|
|
self.raw_data_temp[0,i] = single_data |
|
|
|
np.append(self.data_array, raw_data_temp, axis=1) |
|
|
|
|
|
|
|
def create_data_file(self): |
|
|
|
self.data_file_path = self.data_path_dir + "/" + time.asctime()+".csv" |
|
|
|
file = open(self.data_file_path,"w") #mode append |
|
|
|
file.close() |
|
|
|
|
|
|
|
def append_data_to_file(self, data): |
|
|
|
file = open(self.data_file_path,"a") #mode append |
|
|
|
file.write(data) |
|
|
|
file.close() |