Exemple #1
0
    def rebuild_histogram(self, table, start=None, stop=None):
        """
        Rebuilds the histogram for a table. This may be necessary
        for example after bulk loading data.

        The rebuild may be constrained by using the
        ``start`` and ``stop`` parameters. When
        specified all partitions overlapping this range
        are reconsidered.

        .. note::
            Histogram rebuilds run synchronously: this
            method will await the outcome.

        :param str table: The name of the table
        :param start: Start time
        :type start: Optional[~datetime.datetime]
        :param stop: Stop time
        :type stop: Optional[~datetime.datetime]
        """
        req = table_pb2.RebuildHistogramRequest()
        if start:
            req.start.MergeFrom(to_server_time(start))
        if stop:
            req.stop.MergeFrom(to_server_time(stop))
        url = f"/archive/{self._instance}/tables/{table}:rebuildHistogram"
        self.ctx.post_proto(url, data=req.SerializeToString())
Exemple #2
0
    def remove_tof_intervals(self, start, stop):
        """
        Removes previously registered ToF intervals whose start date
        falls in the specified range ``[start, stop]``.

        :param ~datetime.datetime start: ERT start
        :param ~datetime.datetime stop: ERT stop
        """
        req = tco_pb2.DeleteTimeOfFlightIntervalsRequest()
        req.start.MergeFrom(to_server_time(start))
        req.stop.MergeFrom(to_server_time(stop))

        url = f"/tco/{self._instance}/{self._service}/tof:deleteIntervals"
        self.ctx.post_proto(url, data=req.SerializeToString())
Exemple #3
0
    def add_tof_intervals(self, intervals):
        """
        Adds multiple ToF intervals at once.

        :param .TofInterval[] intervals: List of ToF intervals.
        """
        req = tco_pb2.AddTimeOfFlightIntervalsRequest()
        for interval in intervals:
            tof = req.intervals.add()
            tof.ertStart.MergeFrom(to_server_time(interval.start))
            tof.ertStop.MergeFrom(to_server_time(interval.stop))
            tof.polCoef.extend(interval.polynomial)

        url = f"/tco/{self._instance}/{self._service}/tof:addIntervals"
        self.ctx.post_proto(url, data=req.SerializeToString())
Exemple #4
0
    def stream_parameter_values(self,
                                parameters,
                                start=None,
                                stop=None,
                                chunk_size=32 * 1024):
        """
        Reads parameter values between the specified start and stop time.

        Value updates are emitted for each unique generation time within
        the queried range. If one of the parameters does not have a value
        for a specific generation time, it is not included in the update.

        :param parameters: Parameter(s) to be queried.
        :type parameters: Union[str, str[]]
        :param ~datetime.datetime start: Minimum generation time of the returned
                                         values (inclusive)
        :param ~datetime.datetime stop: Maximum generation time of the returned
                                        values (exclusive)
        :return: :rtype: ~collections.abc.Iterable[:class:`.ParameterData`]
        """
        options = archive_pb2.StreamParameterValuesRequest()
        options.ids.extend(to_named_object_ids(parameters))
        if start is not None:
            options.start.MergeFrom(to_server_time(start))
        if stop is not None:
            options.stop.MergeFrom(to_server_time(stop))

        def generate():
            path = f"/stream-archive/{self._instance}:streamParameterValues"
            response = self.ctx.post_proto(path=path,
                                           data=options.SerializeToString(),
                                           stream=True)
            for message in split_protobuf_stream(
                    response.iter_content(chunk_size=chunk_size),
                    pvalue_pb2.ParameterData):
                yield ParameterData(message)

        return generate()
Exemple #5
0
    def send_event(
        self,
        instance,
        message,
        event_type=None,
        time=None,
        severity="info",
        source=None,
        sequence_number=None,
    ):
        """
        Post a new event.

        :param str instance: A Yamcs instance name.
        :param str message: Event message.
        :param Optional[str] event_type: Type of event.

        :param severity: The severity level of the event. One of ``info``,
                         ``watch``, ``warning``, ``critical`` or ``severe``.
                         Defaults to ``info``.
        :type severity: Optional[str]

        :param time: Time of the event. If unspecified, defaults to mission time.
        :type time: Optional[~datetime.datetime]

        :param source: Source of the event. Useful for grouping events in the
                       archive. When unset this defaults to ``User``.
        :type source: Optional[str]

        :param sequence_number: Sequence number of this event. This is primarily
                                used to determine unicity of events coming from
                                the same source. If not set Yamcs will
                                automatically assign a sequential number as if
                                every submitted event is unique.
        :type sequence_number: Optional[int]
        """
        req = events_service_pb2.CreateEventRequest()
        req.message = message
        req.severity = severity
        if event_type:
            req.type = event_type
        if time:
            req.time.MergeFrom(to_server_time(time))
        if source:
            req.source = source
        if sequence_number is not None:
            req.sequence_number = sequence_number

        url = f"/archive/{instance}/events"
        self.ctx.post_proto(url, data=req.SerializeToString())
Exemple #6
0
    def rebuild_parameter_archive(self, start, stop):
        """
        Rebuilds the Parameter Archive.

        The rebuild must be constrained by using the
        ``start`` and ``stop`` parameters. This values
        are only hints to the Parameter Archive, which
        will extend the requested range based on archive
        segmentation.

        .. note::
            Rebuilds run as an asynchronous operation: this
            method will not await the outcome.

        :param start: Start time
        :type start: ~datetime.datetime
        :param stop: Stop time
        :type stop: ~datetime.datetime
        """
        req = parameter_archive_service_pb2.RebuildRangeRequest()
        req.start.MergeFrom(to_server_time(start))
        req.stop.MergeFrom(to_server_time(stop))
        url = f"/archive/{self._instance}/parameterArchive:rebuild"
        self.ctx.post_proto(url, data=req.SerializeToString())
Exemple #7
0
    def override_coefficients(self, utc, obt, gradient=0, offset=0):
        """
        Manually override the assocation between UTC and
        onboard time.

        .. note::
            If later on you want to revert to automatically computed
            coefficients, use :meth:`reset_coefficients`.

        :param ~datetime.datetime utc: UTC
        :param int obt: Onboard time
        :param Optional[float] gradient: Gradient
        :param Optional[float] offset: Offset
        """
        req = tco_pb2.TcoCoefficients()
        req.utc.MergeFrom(to_server_time(utc))
        req.obt = obt
        req.gradient = gradient
        req.offset = offset

        url = f"/tco/{self._instance}/{self._service}/coefficients"
        self.ctx.post_proto(url, data=req.SerializeToString())
Exemple #8
0
    def set_parameter_values(self, values, generation_time=None):
        """
        Sets the value of multiple parameters.

        Values are specified with their native Python types. If you need
        to customize individual value generation times, use :class:`.ValueUpdate`
        instead.

        The method argument ``generation_time`` can be used to specify a custom
        generation time for all values at once. This has lower priority than
        a value-specific generation time.

        If no generation time is specified at all, Yamcs will determine one.

        :param dict values: Values keyed by parameter name. This name can be either
                            a fully-qualified XTCE name or an alias in the format
                            ``NAMESPACE/NAME``.
        :param generation_time: Generation time of the values.
        :type generation_time: Optional[~datetime.datetime]
        """
        req = processing_pb2.BatchSetParameterValuesRequest()
        for key in values:
            item = req.request.add()
            item.id.MergeFrom(to_named_object_id(key))

            value = values[key]
            value_time = generation_time
            if isinstance(values[key], ValueUpdate):
                value = values[key].value
                if values[key].generation_time:
                    value_time = values[key].generation_time

            item.value.MergeFrom(_build_value_proto(value))
            if value_time:
                item.generationTime.MergeFrom(to_server_time(value_time))
        url = f"/processors/{self._instance}/{self._processor}/parameters:batchSet"
        self.ctx.post_proto(url, data=req.SerializeToString())