How to use the protobuf.mauka_pb2 function in protobuf

To help you get started, we’ve selected a few protobuf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpowerquality / opq / mauka / plugins / laha_gc_plugin.py View on Github external
def handle_gc_update(self, gc_update: mauka_pb2.GcUpdate):
        """
        Handles a GC update message by calling the handler for the specified domain.
        :param gc_update: GcUpdate message.
        """
        self.debug("Handling GC update")
        if gc_update.from_domain == mauka_pb2.PHENOMENA:
            self.handle_gc_update_from_phenomena(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.INCIDENTS:
            self.handle_gc_update_from_incident(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.EVENTS:
            self.handle_gc_update_from_event(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.TRENDS:
            self.handle_gc_update_from_trend(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.MEASUREMENTS:
            self.handle_gc_update_from_measurement(gc_update.id)
        else:
            self.debug("gc_update unknown domain: %s" % str(gc_update.from_domain))
github openpowerquality / opq / mauka / plugins / makai_event_plugin.py View on Github external
end_timestamp)

    try:
        frequency_windowed = protobuf.pb_util.build_payload(name,
                                                            event_id,
                                                            box_id,
                                                            protobuf.mauka_pb2.FREQUENCY_WINDOWED,
                                                            analysis.frequency_per_cycle(waveform_calibrated),
                                                            start_timestamp,
                                                            end_timestamp)
        makai_event_plugin.debug("Got windowed frequency")
    except Exception as exception:
        frequency_windowed = protobuf.pb_util.build_payload(name,
                                                            event_id,
                                                            box_id,
                                                            protobuf.mauka_pb2.FREQUENCY_WINDOWED,
                                                            [],
                                                            start_timestamp,
                                                            end_timestamp)
        makai_event_plugin.logger.error("Error getting FREQUENCY_WINDOWED: %s", str(exception))

    return adc_samples, raw_voltage, rms_windowed_voltage, frequency_windowed
github openpowerquality / opq / mauka / protobuf / pb_util.py View on Github external
def deserialize_mauka_message(mauka_message_bytes: bytes) -> mauka_pb2.MaukaMessage:
    """
    Deserialized a mauka message from bytes to an instance of MaukaMessage.
    :param mauka_message_bytes: Serialized bytes
    :return: An instance of MaukaMessage
    """
    mauka_message = mauka_pb2.MaukaMessage()
    mauka_message.ParseFromString(mauka_message_bytes)
    return mauka_message
github openpowerquality / opq / mauka / plugins / makai_event_plugin.py View on Github external
makai_event_plugin.debug("Got ADC samples")
    except Exception as exception:
        makai_event_plugin.logger.error("Error getting ADC_SAMPLES %s", str(exception))
        adc_samples = protobuf.pb_util.build_payload(name,
                                                     event_id,
                                                     box_id,
                                                     protobuf.mauka_pb2.ADC_SAMPLES,
                                                     [],
                                                     start_timestamp,
                                                     end_timestamp)

    try:
        raw_voltage = protobuf.pb_util.build_payload(name,
                                                     event_id,
                                                     box_id,
                                                     protobuf.mauka_pb2.VOLTAGE_RAW,
                                                     waveform_calibrated,
                                                     start_timestamp,
                                                     end_timestamp)
        makai_event_plugin.debug("Got raw voltage")
    except Exception as exception:
        makai_event_plugin.logger.error("Error getting VOLTAGE_RAW: %s", str(exception))
        raw_voltage = protobuf.pb_util.build_payload(name,
                                                     event_id,
                                                     box_id,
                                                     protobuf.mauka_pb2.VOLTAGE_RAW,
                                                     [],
                                                     start_timestamp,
                                                     end_timestamp)

    try:
        rms_windowed_voltage = protobuf.pb_util.build_payload(name,
github openpowerquality / opq / mauka / plugins / makai_event_plugin.py View on Github external
# filtered frequency calc.
    frequencies = []
    while len(filtered_waveform) >= window_size:
        samples = filtered_waveform[:window_size]
        filtered_waveform = filtered_waveform[window_size:]
        frequencies.append(frequency(samples, down_sample_factor))

    # pylint: disable=len-as-condition
    if len(filtered_waveform) > 0:
        frequencies.append(frequency(filtered_waveform, down_sample_factor))

    return numpy.array(frequencies)


AcquireDataType = typing.Tuple[
    protobuf.mauka_pb2.MaukaMessage,
    protobuf.mauka_pb2.MaukaMessage,
    protobuf.mauka_pb2.MaukaMessage,
    protobuf.mauka_pb2.MaukaMessage]


def acquire_data(mongo_client: mongo.OpqMongoClient,
                 makai_event_plugin: 'MakaiEventPlugin',
                 event_id: int,
                 box_id: str,
                 name: str) -> AcquireDataType:
    """
    Given an event_id, acquire the raw data for each box associated with the given event. Perform feature
    extraction of the raw data and publish those features for downstream plugins.
    :param makai_event_plugin: An instance of the plugin.
    :param box_id: The box id.
    :param mongo_client: The mongo client to use to make this request.
github openpowerquality / opq / mauka / plugins / laha_gc_plugin.py View on Github external
self.debug("Handling gc_trigger %s" % str(gc_trigger))
        domains = set(gc_trigger.gc_domains)

        if mauka_pb2.MEASUREMENTS in domains:
            self.handle_gc_trigger_measurements()

        if mauka_pb2.TRENDS in domains:
            self.handle_gc_trigger_trends()

        if mauka_pb2.EVENTS in domains:
            self.handle_gc_trigger_events()

        if mauka_pb2.INCIDENTS in domains:
            self.handle_gc_trigger_incidents()

        if mauka_pb2.PHENOMENA in domains:
            self.handle_gc_trigger_phenomena()
github openpowerquality / opq / mauka / plugins / laha_gc_plugin.py View on Github external
def handle_gc_trigger_measurements(self):
        """
        GCs measurements by removing measurements older than their expire_at field.
        """
        self.debug("gc_trigger measurements")
        now = timestamp_s()
        delete_result = self.mongo_client.measurements_collection.delete_many({"expire_at": {"$lt": now}})
        self.produce(Routes.gc_stat, util_pb2.build_gc_stat(
            self.NAME, mauka_pb2.MEASUREMENTS, delete_result.deleted_count))
        self.debug("Garbage collected %d measurements" % delete_result.deleted_count)
github openpowerquality / opq / mauka / plugins / system_stats_plugin.py View on Github external
def handle_gc_stat_message(self, mauka_message: protobuf.mauka_pb2.MaukaMessage):
        """
        Handles a GcStatMessage and updates the number of gc counts for the provided domain.
        :param mauka_message: A MaukaMessage contains a laha.gc_stat message.
        """
        self.debug("handle_gc_stat_message")
        gc_domain = mauka_message.laha.gc_stat.gc_domain
        gc_cnt = mauka_message.laha.gc_stat.gc_cnt
        if gc_domain == protobuf.mauka_pb2.SAMPLES:
            self.gc_stats[protobuf.mauka_pb2.SAMPLES] += gc_cnt
        elif gc_domain == protobuf.mauka_pb2.MEASUREMENTS:
            self.gc_stats[protobuf.mauka_pb2.MEASUREMENTS] += gc_cnt
        elif gc_domain == protobuf.mauka_pb2.TRENDS:
            self.gc_stats[protobuf.mauka_pb2.TRENDS] += gc_cnt
        elif gc_domain == protobuf.mauka_pb2.EVENTS:
            self.gc_stats[protobuf.mauka_pb2.EVENTS] += gc_cnt
        elif gc_domain == protobuf.mauka_pb2.INCIDENTS:
            self.gc_stats[protobuf.mauka_pb2.INCIDENTS] += gc_cnt
        elif gc_domain == protobuf.mauka_pb2.PHENOMENA:
            self.gc_stats[protobuf.mauka_pb2.PHENOMENA] += gc_cnt
        else:
            self.logger.warning("Unknown domain %s", gc_domain)
github openpowerquality / opq / mauka / plugins / laha_gc_plugin.py View on Github external
def handle_gc_update(self, gc_update: mauka_pb2.GcUpdate):
        """
        Handles a GC update message by calling the handler for the specified domain.
        :param gc_update: GcUpdate message.
        """
        self.debug("Handling GC update")
        if gc_update.from_domain == mauka_pb2.PHENOMENA:
            self.handle_gc_update_from_phenomena(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.INCIDENTS:
            self.handle_gc_update_from_incident(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.EVENTS:
            self.handle_gc_update_from_event(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.TRENDS:
            self.handle_gc_update_from_trend(gc_update.id)
        elif gc_update.from_domain == mauka_pb2.MEASUREMENTS:
            self.handle_gc_update_from_measurement(gc_update.id)
        else:
            self.debug("gc_update unknown domain: %s" % str(gc_update.from_domain))
github openpowerquality / opq / mauka / plugins / semi_f47_plugin.py View on Github external
def on_message(self, topic: str, mauka_message: protobuf.mauka_pb2.MaukaMessage):
        if protobuf.pb_util.is_payload(mauka_message, protobuf.mauka_pb2.VOLTAGE_RMS_WINDOWED):
            self.debug("Recv windowed voltage")
            incident_ids = semi_violation(self.mongo_client, mauka_message, self)
            for incident_id in incident_ids:
                # Produce a message to the GC
                self.produce(Routes.laha_gc, protobuf.pb_util.build_gc_update(self.name,
                                                                              protobuf.mauka_pb2.INCIDENTS,
                                                                              incident_id))