def set_byte_payload(self, byte_payload: Mapping[bytes]) -> "Event":
     """
     Sets the byte payload.
     :param byte_payload: Payload to set.
     :return: A modified instance of self.
     """
     check_type(byte_payload, [Mapping])
     self.__byte_payload.set_metadata(byte_payload.get_metadata())
     return self
Exemple #2
0
 def append_values(self, images: List[bytes]) -> "Image":
     """
     Appends multiple images to this sensor's image payload.
     :param images: Images to append as a list of bytes objects.
     :return: A modified instance of self
     """
     check_type(images, [List])
     self._proto.samples.extend(list(images))
     return self
 def set_numeric_payload(self, numeric_payload: Mapping[float]) -> "Event":
     """
     Sets the numeric payload.
     :param numeric_payload: Payload to set.
     :return: A modified instance of self.
     """
     check_type(numeric_payload, [Mapping])
     self.__numeric_payload.set_metadata(numeric_payload.get_metadata())
     return self
 def set_string_payload(self, string_payload: Mapping[str]) -> "Event":
     """
     Sets the string payload.
     :param string_payload: Payload to set.
     :return: A modified instance of self.
     """
     check_type(string_payload, [Mapping])
     self.__string_payload.set_metadata(string_payload.get_metadata())
     return self
 def set_description(self, description: str) -> "Event":
     """
     Sets the event description.
     :param description: Description to set.
     :return: A modified instance of self
     """
     check_type(description, [str])
     self._proto.description = description
     return self
Exemple #6
0
 def append_value(self, image: bytes) -> "Image":
     """
     Appends a single image to this sensors list of images.
     :param image: Image to append as serialized bytes.
     :return: A modified instance of self
     """
     check_type(image, [bytes])
     self._proto.samples.append(image)
     return self
 def set_name(self, name: str) -> "EventStream":
     """
     Sets the name of this event stream.
     :param name: Name to set.
     :return: A modified instance of self.
     """
     check_type(name, [str])
     self._proto.name = name
     return self
    def set_mean(self, mean: float) -> "SummaryStatistics":
        """
        Sets the mean.
        :param mean: Mean to set.
        :return: A modified instance of this
        """
        check_type(mean, [int, float])

        self._proto.mean = mean
        return self
    def set_range(self, range_value: float) -> "SummaryStatistics":
        """
        Sets the range.
        :param range_value: Range to set.
        :return: A modified instance of this
        """
        check_type(range_value, [int, float])

        self._proto.range = range_value
        return self
Exemple #10
0
 def set_unit(self, unit: Unit) -> "TimingPayload":
     """
     Sets the timing unit.
     :param unit: Unit to set.
     :return: A modified instance of self
     """
     check_type(unit, [Unit])
     # noinspection Mypy
     self._proto.unit = unit.into_proto()
     return self
 def set_timestamps(self, timestamps: TimingPayload) -> "EventStream":
     """
     Sets the timing payload.
     :param timestamps: Timing payload to set.
     :return: A modified instance of self.
     """
     check_type(timestamps, [TimingPayload])
     self.get_proto().timestamps.CopyFrom(timestamps.get_proto())
     self.__timestamps = TimingPayload(self.get_proto().timestamps)
     return self
Exemple #12
0
    def set_max(self, max_value: float) -> "SummaryStatistics":
        """
        Sets the max.
        :param max_value: Value to set.
        :return: A modified instance of this.
        """
        check_type(max_value, [int, float])

        self._proto.max = max_value
        return self
Exemple #13
0
 def set_timestamps(self, timestamps: common.TimingPayload) -> "Image":
     """
     Sets the timestamps.
     :param timestamps: Timestamps to set.
     :return: A modified instance of self.
     """
     check_type(timestamps, [common.TimingPayload])
     self.get_proto().timestamps.CopyFrom(timestamps.get_proto())
     self._timestamps = common.TimingPayload(self.get_proto().timestamps)
     return self
Exemple #14
0
 def set_image_codec(self, codec: ImageCodec) -> "Image":
     """
     Sets the codec used to store the images.
     :param codec: Codec to set.
     :return: A modified instance of self
     """
     check_type(codec, [ImageCodec])
     # noinspection Mypy
     self._proto.image_codec = codec.into_proto()
     return self
Exemple #15
0
    def set_count(self, count: float) -> "SummaryStatistics":
        """
        Sets the count of values that were used to calculate these statistics.
        :param count:
        :return:
        """
        check_type(count, [int, float])

        self._proto.count = count
        return self
Exemple #16
0
    def set_min(self, min_value: float) -> "SummaryStatistics":
        """
        Sets the min value.
        :param min_value: Value to set.
        :return: A modified instance of this
        """
        check_type(min_value, [int, float])

        self._proto.min = min_value
        return self
Exemple #17
0
    def set_standard_deviation(
            self, standard_deviation: float) -> "SummaryStatistics":
        """
        Set's the standard deviation.
        :param standard_deviation: Standard deviation to set.
        :return: A modified instance of this
        """
        check_type(standard_deviation, [int, float])

        self._proto.standard_deviation = standard_deviation
        return self
    def append_metadata(self, key: str, value: str) -> "Metadata":
        """
        Appends a key-value pair to the metadata mapping.
        :param key: Key to append.
        :param value: Value to append.
        :return: This instance of Metadata.
        """
        check_type(key, [str])
        check_type(value, [str])

        self._metadata_proto[key] = value
        return self
Exemple #19
0
 def set_summary_statistics(
         self, summary_statistics: SummaryStatistics) -> "SamplePayload":
     """
     Sets the summary statistics sub-message field.
     :param summary_statistics: SummaryStatistics to set.
     :return: A modified version of self.
     """
     check_type(summary_statistics, [SummaryStatistics])
     self.get_proto().value_statistics.CopyFrom(
         summary_statistics.get_proto())
     self._summary_statistics = SummaryStatistics(
         self.get_proto().value_statistics)
     return self
Exemple #20
0
    def set_mean_sample_rate(self, mean_sample_rate: float) -> "TimingPayload":
        """
        Sets the mean sample rate.
        :param mean_sample_rate: Rate to set.
        :return: A modified instance of self
        """
        check_type(mean_sample_rate, [int, float])
        if mean_sample_rate < 0:
            raise errors.ApiMError(
                "mean_sample_rate must be strictly positive")

        self._proto.mean_sample_rate = mean_sample_rate
        return self
Exemple #21
0
 def set_timestamp_statistics(
         self, timestamp_statistics: SummaryStatistics) -> "TimingPayload":
     """
     Sets the timestamp statistics.
     :param timestamp_statistics: TimestampStatistics to set.
     :return: A modified instance of self.
     """
     check_type(timestamp_statistics, [SummaryStatistics])
     self.get_proto().timestamp_statistics.CopyFrom(
         timestamp_statistics.get_proto())
     self._timestamp_statistics = SummaryStatistics(
         self.get_proto().timestamp_statistics)
     return self
Exemple #22
0
    def set_stdev_sample_rate(self,
                              stdev_sample_rate: float) -> "TimingPayload":
        """
        Sets the standard deviation of the sample rate.
        :param stdev_sample_rate: Rate to set.
        :return: A modified instance of self
        """
        check_type(stdev_sample_rate, [int, float])
        if stdev_sample_rate < 0:
            raise errors.ApiMError(
                "stdev_sample_rate must be strictly positive")

        self._proto.stdev_sample_rate = stdev_sample_rate
        return self
Exemple #23
0
 def test_primitives_ok(self):
     good_types: List[Any] = [
         [1, [int]],
         [1.0, [float]],
         [True, [bool]],
         ["foo", [str]],
         [[1], [list]],
         [{1}, [set]],
         [{
             1: 2
         }, [dict]],
     ]
     good_type: List[Any]
     for good_type in good_types:
         check_type(*good_type)
    def set_metadata(self, metadata: Dict[str, str]) -> "Metadata":
        """
        Sets the metadata to passed in dictionary.
        :param metadata: Sets the metadata to this.
        :return: This instance of Metadata.
        """
        for key, value in metadata.items():
            check_type(key, [str])
            check_type(value, [str])

        self._metadata_proto.clear()
        for key, value in metadata.items():
            self._metadata_proto[key] = value

        return self
Exemple #25
0
    def append_value(self,
                     value: float,
                     update_value_statistics: bool = False) -> "SamplePayload":
        """
        Appends a single value to the payload.
        :param value: Value to append to the payload.
        :param update_value_statistics: Whether the statistics should be updated.
        :return: A modified instance of self
        """
        check_type(value, [int, float])
        self._proto.values.append(value)

        if update_value_statistics:
            self._summary_statistics.update_from_values(self.get_values())

        return self
Exemple #26
0
    def test_primitive_bad(self):
        bad_types: List[Any] = [[1, [float, bool, str, list, set, dict]],
                                [1.0, [int, bool, str, list, set, dict]],
                                [True, [int, float, str, list, set, dict]],
                                ["foo", [int, float, bool, list, set, dict]],
                                [[1], [int, float, bool, str, set, dict]],
                                [{1}, [int, float, bool, str, list, dict]],
                                [{
                                    1: 2
                                }, [int, float, bool, str, list, set]]]

        bad_type: List[Any]
        for bad_type in bad_types:
            with self.assertRaises(ApiMTypeError) as ctx:
                check_type(*bad_type)
            self.assertTrue("Expected type(s)" in str(ctx.exception))
Exemple #27
0
    def set_values(self,
                   values: np.ndarray,
                   update_value_statistics: bool = False) -> "SamplePayload":
        """
        Set's the values of this payload and optionally updates the statistics.
        :param values: Values to set in this payload.
        :param update_value_statistics: Optional, should the statistics be derived?
        :return: A modified instance of self
        """
        check_type(values, [np.ndarray])
        self._proto.values[:] = list(values)

        if update_value_statistics:
            self._summary_statistics.update_from_values(values)

        return self
Exemple #28
0
    def append_values(
            self,
            values: np.ndarray,
            update_value_statistics: bool = False) -> "SamplePayload":
        """
        Appends multiple values to this payload.
        :param values: Values to append.
        :param update_value_statistics: Whether the statistics should be updated.
        :return: A modified instance of self
        """
        check_type(values, [np.ndarray])
        self._proto.values.extend(list(values))

        if update_value_statistics:
            self._summary_statistics.update_from_values(self.get_values())

        return self
Exemple #29
0
    def set_timestamps(
            self,
            timestamps: np.ndarray,
            update_value_statistics: bool = False) -> "TimingPayload":
        """
        Set the timestamps.
        :param timestamps: Timestamps to set.
        :param update_value_statistics: Should the stats be updated?
        :return: A modified instance of self
        """
        check_type(timestamps, [np.ndarray])
        self._proto.timestamps[:] = list(timestamps)

        if update_value_statistics:
            self.update_timing_statistics_from_timestamps(timestamps)

        return self
Exemple #30
0
    def append_timestamps(
            self,
            timestamps: np.ndarray,
            update_value_statistics: bool = False) -> "TimingPayload":
        """
        Append multiple timestamps.
        :param timestamps: Timestamps to append.
        :param update_value_statistics: Should the stats be updated?
        :return: A modified instance of self
        """
        check_type(timestamps, [np.ndarray])
        self._proto.timestamps.extend(list(timestamps))

        if update_value_statistics:
            self.update_timing_statistics_from_timestamps(
                self.get_timestamps())

        return self