def GetZoomFocus(self, request: Empty, context): """Return zoom and focus of both cameras.""" req = GetCameraZoomFocus.Request() result = self._wait_for(self.get_zoom_focus_client.call_async(req)) return camera_reachy_pb2.ZoomFocusMessage( left_focus=UInt32Value(value=result.left_focus), left_zoom=UInt32Value(value=result.left_zoom), right_focus=UInt32Value(value=result.right_focus), right_zoom=UInt32Value(value=result.right_zoom), )
def ctc_beam_decoders( draw, return_kwargs: bool = False, alphabet_len: Optional[int] = None, blank_index: Optional[int] = None, ) -> Union[ st.SearchStrategy[ctc_beam_decoder_pb2.CTCBeamDecoder], st.SearchStrategy[Tuple[ctc_beam_decoder_pb2.CTCBeamDecoder, Dict]], ]: """Returns a SearchStrategy for CTCBeamDecoder plus maybe the kwargs.""" kwargs: Dict = {} end = 100 if alphabet_len is not None: end = max(0, alphabet_len - 1) if blank_index is not None: kwargs["blank_index"] = blank_index else: kwargs["blank_index"] = draw(st.integers(0, end)) kwargs["beam_width"] = draw(st.integers(1, 2048)) kwargs["prune_threshold"] = draw(st.floats(0.0, 1.0, allow_nan=False)) kwargs["language_model"] = draw(language_models()) if not isinstance(kwargs["language_model"], empty_pb2.Empty): kwargs["lm_weight"] = FloatValue( value=draw(st.floats(allow_nan=False, allow_infinity=False)) ) kwargs["separator_index"] = UInt32Value( value=draw( st.integers(0, end).filter(lambda v: v != kwargs["blank_index"]) ) ) kwargs["word_weight"] = draw( st.floats(allow_nan=False, allow_infinity=False) ) # initialise and return all_fields_set(ctc_beam_decoder_pb2.CTCBeamDecoder, kwargs) ctc_beam_decoder = ctc_beam_decoder_pb2.CTCBeamDecoder(**kwargs) if not return_kwargs: return ctc_beam_decoder return ctc_beam_decoder, kwargs
def translate_to_trace_proto(span_data): """Translates the opencensus spans to ocagent proto spans. :type span_data: :class:`~opencensus.trace.span_data.SpanData` :param span_data: SpanData tuples to convert to protobuf spans :rtype: :class:`~opencensus.proto.trace.Span` :returns: Protobuf format span. """ if not span_data: return None pb_span = trace_pb2.Span( name=trace_pb2.TruncatableString(value=span_data.name), kind=span_data.span_kind, trace_id=hex_str_to_bytes_str(span_data.context.trace_id), span_id=hex_str_to_bytes_str(span_data.span_id), parent_span_id=hex_str_to_bytes_str(span_data.parent_span_id) if span_data.parent_span_id is not None else None, start_time=proto_ts_from_datetime_str(span_data.start_time), end_time=proto_ts_from_datetime_str(span_data.end_time), status=trace_pb2.Status(code=span_data.status.code, message=span_data.status.message) if span_data.status is not None else None, same_process_as_parent_span=BoolValue( value=span_data.same_process_as_parent_span) if span_data.same_process_as_parent_span is not None else None, child_span_count=UInt32Value(value=span_data.child_span_count) if span_data.child_span_count is not None else None) # attributes if span_data.attributes is not None: for attribute_key, attribute_value \ in span_data.attributes.items(): add_proto_attribute_value(pb_span.attributes, attribute_key, attribute_value) # time events if span_data.time_events is not None: for span_data_event in span_data.time_events: if span_data_event.message_event is not None: pb_event = pb_span.time_events.time_event.add() pb_event.time.FromJsonString(span_data_event.timestamp) set_proto_message_event(pb_event.message_event, span_data_event.message_event) elif span_data_event.annotation is not None: pb_event = pb_span.time_events.time_event.add() pb_event.time.FromJsonString(span_data_event.timestamp) set_proto_annotation(pb_event.annotation, span_data_event.annotation) # links if span_data.links is not None: for link in span_data.links: pb_link = pb_span.links.link.add( trace_id=hex_str_to_bytes_str(link.trace_id), span_id=hex_str_to_bytes_str(link.span_id), type=link.type) if link.attributes is not None and \ link.attributes.attributes is not None: for attribute_key, attribute_value \ in link.attributes.attributes.items(): add_proto_attribute_value(pb_link.attributes, attribute_key, attribute_value) # tracestate if span_data.context.tracestate is not None: for (key, value) in span_data.context.tracestate.items(): pb_span.tracestate.entries.add(key=key, value=value) return pb_span