示例#1
0
    def get(self,
            row: str,
            table_name: str,
            table_namespace: str = "default",
            columns: Mapping[str, List[str]] = None,
            min_time: Optional[int] = None,
            max_time: Optional[int] = None,
            max_versions: Optional[int] = None) -> 'Result':
        if min_time is not None:
            _min_time = Int64Value(value=min_time)
        else:
            _min_time = Int64Value()

        if max_time is not None:
            _max_time = Int64Value(value=max_time)
        else:
            _max_time = Int64Value()

        if max_versions is not None:
            _max_versions = Int32Value(value=max_versions)
        else:
            _max_versions = Int32Value()

        query = Get(
            table=Table(name=table_name, namespace=table_namespace),
            row=row,
            columns={f: Columns(columns=c)
                     for f, c in columns.items()},
            max_versions=_max_versions,
            min_time=_min_time,
            max_time=_max_time)

        return Result(self._client.get(query))
示例#2
0
    def scan(
            self,
            table_name: str,
            table_namespace: str = "default",
            start_row: Optional[str] = None,
            stop_row: Optional[str] = None,
            prefix: Optional[str] = None,
            columns: Optional[Mapping[str, List[str]]] = None,
            min_time: Optional[int] = None,
            max_time: Optional[int] = None,
            max_versions: Optional[int] = None
    ) -> Iterator[Result]:

        if start_row is not None:
            _start_row = StringValue(value=start_row)
        else:
            _start_row = None

        if stop_row is not None:
            _stop_row = StringValue(value=stop_row)
        else:
            _stop_row = None

        if prefix is not None:
            _prefix = StringValue(value=prefix)
        else:
            _prefix = None

        if min_time is not None:
            _min_time = Int64Value(value=min_time)
        else:
            _min_time = None

        if max_time is not None:
            _max_time = Int64Value(value=max_time)
        else:
            _max_time = None

        if columns is not None:
            _columns = self._convert_columns(columns)
        else:
            _columns = []

        if max_versions is not None:
            _max_versions = Int32Value(value=max_versions)
        else:
            _max_versions = None

        query = ScanRequest(
            table=Table(name=table_name, namespace=table_namespace),
            start_row=_start_row,
            stop_row=_stop_row,
            prefix=_prefix,
            columns=_columns,
            min_time=_min_time,
            max_time=_max_time,
            max_versions=_max_versions
        )

        return self._client.Scan(query)
示例#3
0
def test_tracer_end_traced_span_do_post(m_thread, tracer):
    tracer.memory.current_span_id = 'test_span_id'
    tracer._post_spans_to_stackdriver_api = True
    tracer.stackdriver_trace_client = MagicMock()
    tracer.stackdriver_trace_client.span_path.return_value = 'test_span_name'
    tracer._delete_current_span = MagicMock()

    tracer.end_traced_span(exclude_from_posting=False)

    tracer.logger.debug.assert_called_with("Closing span test_span_id")
    tracer.stackdriver_trace_client.span_path.assert_called_with(
        'test_project_name', 'test_trace_id', 'test_span_id')

    expected_span_info = {
        'name': 'test_span_name',
        'span_id': 'test_span_id',
        'display_name': 'test_truncated_str',
        'start_time': 'test_start_time',
        'end_time': 'test_timestamp',
        'parent_span_id': 'test_parent_span_id',
        'same_process_as_parent_span': BoolValue(value=False),
        'child_span_count': Int32Value(value=0)
    }
    m_thread.assert_called_with(target=post_span,
                                args=(
                                    tracer.stackdriver_trace_client,
                                    expected_span_info,
                                ))
    assert tracer._delete_current_span.called
示例#4
0
 def GetLastTrainedVersion(self, request: SearchId,
                           context: grpc.ServicerContext) -> Int32Value:
     try:
         return Int32Value(value=self._manager.get_search(
             request).get_last_trained_version())
     except Exception as e:
         logger.exception(e)
         raise e
示例#5
0
 def default():
     config = CameraPipelineConfig()
     config.camera_configs.extend([
         CameraConfig(
             serial_number='15322110300',
             name='tracking_camera/front',
             model=CameraConfig.MODEL_INTEL_T265,
             udp_stream_port=Int32Value(value=5000),
         ),
         CameraConfig(
             serial_number='923322071915',
             name='tracking_camera/front_depth',
             model=CameraConfig.MODEL_INTEL_D435I,
             udp_stream_port=Int32Value(value=5001),
         ),
     ], )
     return config
示例#6
0
文件: crypto.py 项目: woky/pyrchain
def gen_block_hash_from_block(block: BlockMessage) -> bytes:
    signed_obj = b''.join([
        block.header.SerializeToString(), block.sender,
        StringValue(value=block.sigAlgorithm).SerializeToString(),
        Int32Value(value=block.seqNum).SerializeToString(),
        StringValue(value=block.shardId).SerializeToString(), block.extraBytes
    ])
    return blake2b_32(signed_obj).digest()
def list_calendars(stub: GoogleCalendarServiceStub,
                   user_id: str,
                   limit: int = 100):
    query = GoogleCalendar.Query.List(user_id=user_id,
                                      limit=Int32Value(value=limit))
    result = stub.ListGoogleCalendar(query)

    return list(
        result
    )  # Here, ListGoogleCalendar returns generator, not List; so, force to change into List.
示例#8
0
    def scan(self,
             table_name: str,
             table_namespace: str = "default",
             start_row: Optional[str] = None,
             stop_row: Optional[str] = None,
             prefix: Optional[str] = None,
             columns: Mapping[str, List[str]] = None,
             min_time: Optional[int] = None,
             max_time: Optional[int] = None,
             max_versions: Optional[int] = None) -> 'Result':

        if start_row is not None:
            _start_row = StringValue(value=start_row)
        else:
            _start_row = None

        if stop_row is not None:
            _stop_row = StringValue(value=stop_row)
        else:
            _stop_row = None

        if prefix is not None:
            _prefix = StringValue(value=prefix)
        else:
            _prefix = None

        if min_time is not None:
            _min_time = Int64Value(value=min_time)
        else:
            _min_time = None

        if max_time is not None:
            _max_time = Int64Value(value=max_time)
        else:
            _max_time = None

        if max_versions is not None:
            _max_versions = Int32Value(value=max_versions)
        else:
            _max_versions = None

        query = Scan(
            table=Table(name=table_name, namespace=table_namespace),
            start_row=_start_row,
            stop_row=_stop_row,
            prefix=_prefix,
            columns={f: Columns(columns=c)
                     for f, c in columns.items()},
            min_time=_min_time,
            max_time=_max_time,
            max_versions=_max_versions)

        return Result(self._client.scan(query))
示例#9
0
    def get(
            self,
            row: str,
            table_name: str,
            table_namespace: str = "default",
            columns: Optional[Mapping[str, List[str]]] = None,
            min_time: Optional[int] = None,
            max_time: Optional[int] = None,
            max_versions: Optional[int] = None
    ) -> 'Result':
        if min_time is not None:
            _min_time = Int64Value(value=min_time)
        else:
            _min_time = Int64Value()

        if max_time is not None:
            _max_time = Int64Value(value=max_time)
        else:
            _max_time = Int64Value()

        if max_versions is not None:
            _max_versions = Int32Value(value=max_versions)
        else:
            _max_versions = Int32Value()

        if columns is not None:
            _columns = self._convert_columns(columns)
        else:
            _columns = []

        query = GetRequest(
            table=Table(name=table_name, namespace=table_namespace),
            row=row,
            columns=_columns,
            max_versions=_max_versions,
            min_time=_min_time,
            max_time=_max_time
        )

        return self._client.Get(query)
def list_events(stub: GoogleCalendarServiceStub,
                user_id: str,
                calendar_id: str,
                limit: int = 100,
                start_time: datetime = None,
                end_time: datetime = None):
    query = GoogleCalendarEvent.Query.List(
        user_id=user_id,
        calendar_id=calendar_id,
        limit=Int32Value(value=limit),
        start_time=datetime_to_protobuf(start_time) if start_time else None,
        end_time=datetime_to_protobuf(end_time) if end_time else None)
    result = stub.ListGoogleCalendarEvent(query)

    return list(result)
示例#11
0
    def end_traced_span(self, exclude_from_posting=False):
        """
        End a span and collect details about the span, then post it to the API.

        Arguments:
            exclude_from_posting (bool): exclude this particular trace from being posted
        """
        self.logger.debug(f'Closing span {self.memory.current_span_id}')

        if self._post_spans_to_stackdriver_api and not exclude_from_posting:
            span_values = self.current_span['values']

            end_timestamp = get_timestamp()
            if self._post_spans_to_stackdriver_api:
                name = self.stackdriver_trace_client.span_path(
                    self.project_name, span_values[B3_TRACE_ID],
                    span_values[B3_SPAN_ID])
            else:
                name = f'{self.project_name}/{span_values[B3_TRACE_ID]}/{span_values[B3_SPAN_ID]}'

            span_info = {
                'name':
                name,
                'span_id':
                span_values[B3_SPAN_ID],
                'display_name':
                truncate_str(self.current_span['display_name'],
                             limit=SPAN_DISPLAY_NAME_BYTE_LIMIT),
                'start_time':
                self.current_span['start_timestamp'],
                'end_time':
                end_timestamp,
                'parent_span_id':
                span_values[B3_PARENT_SPAN_ID],
                'same_process_as_parent_span':
                BoolValue(value=False),
                'child_span_count':
                Int32Value(value=self.current_span['child_span_count'])
            }
            post_to_api_job = Thread(target=post_span,
                                     args=(self.stackdriver_trace_client,
                                           span_info))
            post_to_api_job.start()

        self._delete_current_span()
示例#12
0
def int32Value(field):
    if field is None:
        return None
    else:
        return Int32Value(value=field)
示例#13
0
 def configNucleo(self):
     msg = Int32Value(value=0)
     self.publishTopic('gui/out/commands/config_nucleo', msg)
示例#14
0
 def preMatch(self):
     msg = Int32Value(value=0)
     self.publishTopic('gui/out/commands/prematch', msg)
示例#15
0
 def odriveCalibration(self):
     msg = Int32Value(value=0)
     self.publishTopic('nucleo/in/propulsion/calibrate_odrive', msg)
示例#16
0
from google.protobuf.timestamp_pb2 import Timestamp
from google.protobuf.wrappers_pb2 import Int32Value

SERVICE_ACCOUNT_FILE = "<path to service account json file>"
PROJECT_NUM = "<project # or id>"

SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES)

client = retail.UserEventServiceClient(credentials=credentials)

timestamp = Timestamp()
timestamp.FromDatetime(dt=datetime.datetime.now())

quantity = Int32Value(value=1)

user_events = {
    "user_events": [{
        "event_type": "home-page-view",
        "event_time": timestamp,
        "visitor_id": "visitor-1",
        "user_info": {
            "user_id": "user12345"
        }
    }, {
        "event_type": "detail-page-view",
        "event_time": timestamp,
        "visitor_id": "visitor-1",
        "user_info": {
            "user_id": "user12345"
示例#17
0
 def setSide(self, side):
     self._side = side
     self.notifySide.emit()
     msg = Int32Value(value=side)
     self.publishTopic('gui/out/side', msg)