Пример #1
0
def producer_process():
    p = ProducerProcess(
        'test_process',
        document=Document(document_id=generate_unique_id(), started_at=utc_datetime()),
    )
    yield p
    if p.is_alive():
        p.join()
    assert not p.is_alive()
Пример #2
0
    def read(self) -> Tuple[datetime.datetime, dict]:
        """
        Read a single value from the sensor.

        :return: Datetime and value dictionary as a tuple
        """
        try:
            telegram = self.poll()
            value, _, _, _ = decode_telegram(telegram)
        except TelegramError as e:
            logger.error('Decode telegram failed! {}'.format(str(e)))
            value = None
        return utc_datetime(), {str(self.channels[0]): value}
Пример #3
0
    def create_document(self) -> Document:
        """
        Create a Document object from context.

        :return:
        :raises ValueError: if active patient is invalid
        """
        return Document(
            session_id=self.machine().session_id,
            patient_id=self.machine().patient_id,
            distractor_number=self.machine().distractor,
            operator=self.machine().operator,
            started_at=utc_datetime(),
            sensor_serial_number=self.machine().sensor_serial_number,
            distractor_type=Config.DEFAULT_DISTRACTOR,
        )
Пример #4
0
    def read(self) -> Tuple[datetime.datetime, dict]:
        """
        Read values from the registered input channels.

        :return: Datetime and value dictionary as a tuple
        """
        if len(self.channels) == 0:
            return None
        values = {}
        for c in self.channels:
            values[str(c)] = self.value_generator()
        # Sleep for 10 ms to slow down the sampling
        # If there is no wait between consecutive read() calls,
        # Too much data is generated for a plot widget to handle
        time.sleep(0.01)
        # Use UTC+0 time
        return utc_datetime(), values
Пример #5
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     if self.started_at is None:
         self.started_at = utc_datetime()