bci.protocol.utils package

Submodules

bci.protocol.utils.context module

class bci.protocol.utils.context.Context(root)

Bases: object

Represents the current context in the application.

root

Root directory.

Type

str

user_id

The ID of the current user.

Type

str

snapshot_datetime

The datetime of the current snapshot.

Type

str

Parameters

root (str) – Root directory.

path(filename, is_raw=True)
save(filename, data, is_binary=True, is_raw=True)
save_blobs(user, snapshot)
set(*, user=None, user_id=None, snapshot=None, snapshot_datetime=None)

bci.protocol.utils.display module

bci.protocol.utils.display.display_snapshot(snapshot)

Displays snapshot in a human-readable form.

Parameters

snapshot (bci.protocol.sample_pb2.Snapshot) – Snapshot message.

bci.protocol.utils.display.display_user(user)

Displays user in a human-readable form.

Parameters

user (bci.protocol.sample_pb2.User) – User message.

bci.protocol.utils.display.get_datetime_str(timestamp, purpose='display', ms_to_sec=True)

Gets a string representation of timestamp.

Parameters
  • timestamp (typing.Union[int, str])) – Timestamp.

  • purpose (str) – For what purpose the result will be used. Default to ‘display’.

  • ms_to_sec (bool) – If true, convert timestamp from milliseconds to seconds. Default to True.

Returns

The required string according to purpose.

Return type

str

Raises

ValueError – If purpose is unknown.

bci.protocol.utils.display.get_gender_str(user_gender)

Gets a string representation of the given user’s gender field.

Parameters

user_gender (typing.Union[int, str]) – User’s gender.

Returns

The required string.

Return type

str

Raises

ValueError – If user_gender is unknown.

bci.protocol.utils.parse_serialize module

bci.protocol.utils.parse_serialize.parse_from_binary_seq(data)

Parses data to a tuple composed of User and Snapshot messages.

Parameters

data (bytes) – A binary with a sequence of message sizes and serialized messages (of that size), where where the first one is a User message and the second is a Snapshot message.

Returns

Tuple containing:
user (bci.protocol.sample_pb2.User): User message parsed

from data.

snapshot (bci.protocol.sample_pb2.Snapshot): Snapshot

message parsed from data.

Return type

tuple

bci.protocol.utils.parse_serialize.serialize_to_binary_seq(user, *snapshots)

Serializes user and snapshots to a binary with a sequence of message sizes and serialized messages (of that size), where the first one is user, and the rest are snapshots.

Parameters
  • user (bci.protocol.sample_pb2.User) – User message.

  • snapshots (List[bci.protocol.sample_pb2.Snapshot]) – List of Snapshot messages.

Returns: The required bytes.

bci.protocol.utils.parse_serialize.serialize_to_binary_tuple(message)

Serializes message to a binary consisting of the message size followed by the serialized message.

Parameters

message (google.protobuf.message.Message) – A message.

Returns

The required bytes.

Return type

bytes

bci.protocol.utils.read module

bci.protocol.utils.read.read_message(stream)

Reads binary data composed of a sequence of a message size (uint32) and a message of that size.

Parameters

stream (IOBase) – Stream we are reading from.

Returns

The message as a bytes object.

Return type

bytes

bci.protocol.utils.read.read_snapshot(stream)

Read a Snapshot message from stream.

Parameters

stream (IOBase) – Stream we are reading from.

Returns

The Snapshot message read from stream.

Return type

bci.protocol.sample.Snapshot

bci.protocol.utils.read.read_user(stream)

Read a User message from stream.

Parameters

stream (IOBase) – Stream we are reading from.

Returns

The User message read from stream.

Return type

bci.protocol.sample.User

bci.protocol.utils.to_dict module

bci.protocol.utils.to_dict.snapshot_to_dict(snapshot, color_image_path, depth_image_path)

Converts snapshot to a dictionary.

Parameters
  • snapshot (bci.protocol.sample_pb2.Snapshot) – Snapshot message.

  • color_image_path (str) – Path to the binary data of the snapshot’s color image field.

  • depth_image_path (str) – Path to the binary data of the snapshot’s depth image field.

Returns

A dictionary representation of snapshot, where images’ binary data substituted by the paths in which they were saved.

Return type

dict

bci.protocol.utils.to_dict.user_to_dict(user)

Converts user to a dictionary.

Parameters

user (bci.protocol.sample_pb2.User) – User message.

Returns

A dictionary representation of user.

Return type

dict

Module contents

class bci.protocol.utils.Context(root)

Bases: object

Represents the current context in the application.

root

Root directory.

Type

str

user_id

The ID of the current user.

Type

str

snapshot_datetime

The datetime of the current snapshot.

Type

str

Parameters

root (str) – Root directory.

path(filename, is_raw=True)
save(filename, data, is_binary=True, is_raw=True)
save_blobs(user, snapshot)
set(*, user=None, user_id=None, snapshot=None, snapshot_datetime=None)