예제 #1
0
    def add(self, labels, value):
        """Add adds a single observation to the summary."""

        if type(value) not in (float, int):
            raise TypeError("Summary only works with digits (int, float)")

        # We have already a lock for data but not for the estimator
        with mutex:
            try:
                e = self.get_value(labels)
            except KeyError:
                # Initialize quantile estimator
                e = quantile.Estimator(*self.__class__.DEFAULT_INVARIANTS)
                self.set_value(labels, e)
            e.observe(float(value))
예제 #2
0
    def add(self, labels: LabelsType, value: NumericValueType) -> None:
        """ Add a single observation to the summary """

        value = cast(Union[float, int], value)  # typing check, no runtime behaviour.
        if type(value) not in (float, int):
            raise TypeError("Summary only works with digits (int, float)")

        try:
            e = self.get_value(labels)
        except KeyError:
            # Initialize quantile estimator
            e = quantile.Estimator(*self.invariants)
            self.set_value(labels, e)

        e.observe(float(value))  # type: ignore
예제 #3
0
    def _rotate(self):
        """
        rotate the ring buffer when the time threshold has been exceeded.
        Returns:
            The quantile.Estimator from the current time window bucket.
        """
        time_since_last_rotate_millis = time.time(
        ) * 1000 - self._last_rotate_timestamp_millis

        while time_since_last_rotate_millis > self._duration_between_rotates_millis:
            self._ring_buffer[self._current_bucket] = quantile.Estimator(
                *self._quantiles)

            self._current_bucket += 1
            if self._current_bucket >= len(self._ring_buffer):
                self._current_bucket = 0

            time_since_last_rotate_millis -= self._duration_between_rotates_millis
            self._last_rotate_timestamp_millis += self._duration_between_rotates_millis

        return self._ring_buffer[self._current_bucket]