def configurer(): ADRESSE_SERVEUR = "158.69.192.249:8080" AUTHENTIFICATION = "capture" global CapteurGas CapteurGas.configurer() global serviceDAO serviceDAO = ServiceDAO(ADRESSE_SERVEUR, AUTHENTIFICATION)
def test_mq2_fake_zip(self): """ Test MQ² with a fake zip file """ mapqtl_folder = MQ2.set_tmp_folder() MQ2.extract_zip(TEST_INPUT_FAKE, self.mapqtl_folder) self.assertTrue(os.path.exists(self.mapqtl_folder)) found_files = os.listdir(self.mapqtl_folder) self.assertTrue(found_files == [])
def test_extract_zip(self): """ Test the extract_zip function. """ MQ2.extract_zip(TEST_INPUT_PASSED, self.mapqtl_folder) self.assertTrue(os.path.exists(self.mapqtl_folder)) expected_files = ['Session 2 (IM)_A_trait01.mqo', 'Session 2 (IM)_A_trait02.mqo'] found_files = os.listdir(self.mapqtl_folder) found_files.sort() self.assertEqual(found_files, expected_files)
def test_extract_zip(self): """ Test the extract_zip function. """ MQ2.extract_zip(TEST_INPUT_PASSED, self.mapqtl_folder) self.assertTrue(os.path.exists(self.mapqtl_folder)) expected_files = [ 'Session 2 (IM)_A_trait01.mqo', 'Session 2 (IM)_A_trait02.mqo' ] found_files = os.listdir(self.mapqtl_folder) found_files.sort() self.assertEqual(found_files, expected_files)
def test_mq2_read_input_file(self): """ Test MQ² read_input_file function """ matrix = MQ2.read_input_file(os.path.join(TEST_FOLDER, 'mapqtl', 'qtls.exp'), sep=',') self.assertEqual(len(matrix), 5) self.assertEqual(len(matrix[0]), 14)
def test_MQ2_write_matrix(self): """ Test MQ² write_matrix function """ data = [[1, 2, 3], [1, 2, 3, 4], 'test'] datafile = os.path.join(TEST_FOLDER, 'test_matrix.csv') self.assertFalse(os.path.exists(datafile)) MQ2.write_matrix(datafile, data) self.assertTrue(os.path.exists(datafile)) matrix = MQ2.read_input_file(datafile, sep=',') self.assertEqual(len(matrix), 3) self.assertEqual(len(matrix[0]), 3) self.assertEqual(len(matrix[1]), 4) self.assertEqual(len(matrix[2]), 1) os.unlink(datafile) self.assertFalse(os.path.exists(datafile))
def test_MQ2_write_matrix(self): """ Test MQ² write_matrix function """ data = [[1,2,3], [1,2,3,4], 'test'] datafile = os.path.join(TEST_FOLDER, 'test_matrix.csv') self.assertFalse(os.path.exists(datafile)) MQ2.write_matrix(datafile, data) self.assertTrue(os.path.exists(datafile)) matrix = MQ2.read_input_file(datafile, sep=',') self.assertEqual(len(matrix), 3) self.assertEqual(len(matrix[0]), 3) self.assertEqual(len(matrix[1]), 4) self.assertEqual(len(matrix[2]), 1) os.unlink(datafile) self.assertFalse(os.path.exists(datafile))
def boucler(): while True: tempsCourant = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') position = {"latitude": 48.840689, "longitude": -67.497454} valeur = CapteurGas.recupererGas() #print(valeur) contenuEnvoi = { "capteur": { "pollution": { "date": tempsCourant, "position": position, "valeur": valeur } } } reponse = serviceDAO.ajouter(contenuEnvoi) print(reponse) time.sleep(60)
def detruire(): CapteurGas.detruire() serviceDAO.detruire() print("Au revoir !")
from MQ2 import * from MQ9 import * from MQ135 import * import sys, time try: print("Press CTRL+C to abort.") MQ2 = MQ2() MQ9 = MQ9() MQ135 = MQ135() while True: perc_mq2 = MQ2.MQPercentage() perc_mq9 = MQ9.MQPercentage() perc_mq135 = MQ135.MQPercentage() sys.stdout.write("\r") sys.stdout.write("\033[K") sys.stdout.write( "LPG: %g ppm, CO: %g ppm, Smoke: %g ppm, H2: %g ppm, CH4: %g ppm, , Alc: %g ppm, C3H8: %g ppm, LPG-2: %g ppm, CO-2: %g ppm, CH4-2: %g ppm, CO2: %g ppm, CO-3: %g ppm, Alc-2: %g ppm, NH4: %g ppm, CH3: %g ppm, (CH3)2CO: %g ppm" % (perc_mq2["GAS_LPG"], perc_mq2["GAS_CO"], perc_mq2["GAS_SMOKE"], perc_mq2["GAS_HYDROGEN"], perc_mq2["GAS_METHANE"], perc_mq2["GAS_PROPANE"], perc_mq9["GAS_LPG"], perc_mq9["GAS_CO"], perc_mq9["GAS_METHANE"], perc_mq135["GAS_CO2"], perc_mq135["GAS_CO"], perc_mq135["GAS_ALCOHOL"], perc_mq135["GAS_AMMONIUM"], perc_mq135["GAS_TOLUENE"], perc_mq135["GAS_ACETONE"])) sys.stdout.flush() time.sleep(0.1) except: print("\nAbort by user")
def __init__(self, method_name='runTest'): """ Constructor. """ unittest.TestCase.__init__(self, method_name) self.mapqtl_folder = MQ2.set_tmp_folder()
def test_mq2_get_matrix_dimensions(self): """ Test MQ² get_matrix_dimensions function """ (length, width) = MQ2.get_matrix_dimensions( os.path.join(TEST_FOLDER, 'mapqtl', 'qtls.exp')) self.assertEqual(length, 5) self.assertEqual(width, 14)
def test_mq2_read_input_file(self): """ Test MQ² read_input_file function """ matrix = MQ2.read_input_file( os.path.join(TEST_FOLDER, 'mapqtl', 'qtls.exp'), sep=',') self.assertEqual(len(matrix), 5) self.assertEqual(len(matrix[0]), 14)
def test_mq2_get_matrix_dimensions(self): """ Test MQ² get_matrix_dimensions function """ (length, width) = MQ2.get_matrix_dimensions( os.path.join(TEST_FOLDER,'mapqtl', 'qtls.exp')) self.assertEqual(length, 5) self.assertEqual(width, 14)