Example #1
0
 def test_saving(self):
     data_lines = \
         [
             'Temperature1: 56',
             'Temperature2=54 ',
             'Temperature3=53',
             'Temperature3=52',
             'Temperature1=666',
             'Temperature1',
             'Error',
             'Temperature1=666degrees',
             'Temperature4=No data',
             'Temperature1=54',
             'Temperature1=55',
             'Temperature4=40',
             'Temperature3=55',
         ]
     parser = DataParser()
     for line in data_lines:
         parser.parse(line)
     parser.save_results('mixed_json_results.json')
     self.assertTrue(
         filecmp.cmp('mixed_json_results.json', 'json_files//mixed_json_results.json'),
         'Files are different')
     os.remove('mixed_json_results.json')
Example #2
0
class DataSession(QObject):
    signal_start_background_job = pyqtSignal()

    def __init__(self, plot_painter, params, port_settings=DEFAULT_PORT_SETTINGS):
        super().__init__()

        self.data_parser = DataParser(params)
        self.plot_painter = plot_painter

        self.worker = SerialWorker(port_settings)
        self.thread = QThread()
        self.worker.moveToThread(self.thread)
        self.worker.read_data_signal.connect(self.add_data)
        self.signal_start_background_job.connect(self.worker.run)

    def run(self):
        self.thread.start()
        self.signal_start_background_job.emit()

    def add_data(self, sensor_data):
        logger.debug(f"Data was read: {sensor_data}")
        parser_data = self.data_parser.parse(sensor_data)
        if parser_data:
            self.plot_painter.add_data(parser_data)
            # TODO: save to DB

    def stop(self, additional_params):
        self.worker.stop()
        self.thread.quit()
        self.thread.wait(1000)
        json_file_name = (
                "data_"
                + datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S")
                + ".json"
        )
        self.data_parser.save_results(json_file_name, additional_params)