Selaa lähdekoodia

réarrangement du code, création d'un objet dans data.py, ajout de la possibilité de créer des signaux de capteurs, ajout de timers

tags/PoDoCor-v0.1
lilian 3 vuotta sitten
vanhempi
commit
0fd223bcc6
12 muutettua tiedostoa jossa 69 lisäystä ja 1 poistoa
  1. BIN
      bin/__pycache__/data.cpython-38.pyc
  2. BIN
      bin/__pycache__/functions.cpython-38.pyc
  3. +62
    -0
      bin/data.py
  4. +0
    -0
      bin/data/Wed Feb 10 16:35:08 2021.csv
  5. +0
    -0
      bin/data/Wed Feb 10 17:46:29 2021.csv
  6. +0
    -0
      bin/data/Wed Feb 10 17:58:13 2021.csv
  7. +0
    -0
      bin/data/Wed Feb 10 18:19:01 2021.csv
  8. +0
    -0
      bin/data/Wed Feb 10 18:20:02 2021.csv
  9. +0
    -0
      bin/data/Wed Feb 10 18:25:45 2021.csv
  10. +0
    -0
      bin/data/Wed Feb 10 18:30:32 2021.csv
  11. +0
    -0
      bin/data/Wed Feb 10 18:31:03 2021.csv
  12. +7
    -1
      bin/functions.py

BIN
bin/__pycache__/data.cpython-38.pyc Näytä tiedosto


BIN
bin/__pycache__/functions.cpython-38.pyc Näytä tiedosto


+ 62
- 0
bin/data.py Näytä tiedosto

@@ -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()

+ 0
- 0
bin/data/Wed Feb 10 16:35:08 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 17:46:29 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 17:58:13 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 18:19:01 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 18:20:02 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 18:25:45 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 18:30:32 2021.csv Näytä tiedosto


+ 0
- 0
bin/data/Wed Feb 10 18:31:03 2021.csv Näytä tiedosto


functions.py → bin/functions.py Näytä tiedosto

@@ -1,9 +1,15 @@
import os
if(os.name == "posix"):
import getch as gt #clavier
else:
import msvcrt as gt

def press_key(caracter, actual_state, future_state):
""" Cette fonction sert à détecter si le caractère est pressé, pour passer
d'un état (ou boucle) à un autre."""

pressed_key = gt.getch() #detection de touche pressee (arret procedure acquisition)
if(pressedKey == caracter):
if(pressed_key == caracter):
flag_data = future_state
else:
flag_data = actual_state

Loading…
Peruuta
Tallenna