/      日本語

mwings.parsers.app_cue Module

Parsers for packets sent from the TWELITE CUE mode and data structures to store their contents.

Parsers for packets sent from the TWELITE CUE mode and data structures to store their contents.

src/mwings/parsers/app_cue.py

PacketParser

Static class for parsing packets representing data sent from the Cue app (TWELITE CUE mode).

Inherits from: common.PacketParserBase

is_valid()

is_valid(bare_packet)

Checks whether the given bare packet is valid.

Parameters

NameTypeDescription
bare_packetcommon.BarePacketRaw packet data

Returns

TypeValueDescription
boolTrueValid and parsable
FalseInvalid and unparsable

parse()

parse(bare_packet)

Parses the given bare packet.

Parameters

NameTypeDescription
bare_packetcommon.BarePacketRaw packet data

Returns

TypeValueDescription
optional ParsedPacketParsedPacket typed dataParsed data
NoneUnparsable

ParsedPacket

Structure to store the result of parsing packets representing data sent from the Cue app (TWELITE CUE mode).

Inherits from: common.ParsedPacketBase

ParsedPacket()

ParsedPacket(*, time_parsed=None, packet_type=PacketType.BARE, sequence_number=None, source_serial_id=0, source_logical_id=0, lqi=None, supply_voltage=None, sample_count=10, samples_x=<mwings.common.TimeSeries object>, samples_y=<mwings.common.TimeSeries object>, samples_z=<mwings.common.TimeSeries object>, has_accel_event=False, accel_event=AccelEvent.NONE, magnet_state=MagnetState.NOT_DETECTED, magnet_state_changed=False)

Parameters

Including properties inherited from the base class.

NameTypeDescription
time_parsedoptional AwareDatetimeParsing timestamp
packet_typecommon.PacketTypePacket type
sequence_numberoptional common.UInt16Sequence number
source_serial_idcommon.UInt32Source serial ID
source_logical_idcommon.UInt8Source logical device ID
lqioptional common.UInt8Radio communication quality
supply_voltageoptional common.UInt16Supply voltage (mV)
router_serial_idcommon.UInt32Serial ID of the first relay device (no relay is 0x80000000) v1.0.13+
sample_countcommon.UInt8Number of accelerometer samples per axis
samples_xcommon.TimeSeries[common.Int16]X-axis accelerometer samples
samples_ycommon.TimeSeries[common.Int16]Y-axis accelerometer samples
samples_zcommon.TimeSeries[common.Int16]Z-axis accelerometer samples
has_accel_eventboolPresence of accelerometer event
accel_eventcommon.AccelEventAccelerometer event
magnet_statecommon.MagnetStateMagnet state
magnet_state_changedboolWhether magnet state has changed

You can also pass a dictionary unpacked with **.

to_df()

to_df(include=None, exclude=None, verbose=True)

Converts the parsed data to a pandas DataFrame.

Parameters

NameTypeDescription
includeoptional set[str]Set of columns (members) to include in the DataFrame
excludeoptional set[str]Set of columns (members) to exclude from the DataFrame
verboseboolWhether to include system information (only when other arguments are None)

Returns

TypeValueDescription
pd.DataFrame-Converted DataFrame

Exceptions

  • EnvironmentError if pandas is not installed

to_dict()

to_dict(include=None, exclude=None, verbose=True, spread=False, sort_keys=False)

Converts the parsed data to a dictionary.

Parameters

NameTypeDescription
includeoptional set[str]Set of keys (members) to include in the dictionary
excludeoptional set[str]Set of keys (members) to exclude from the dictionary
verboseboolWhether to include system information (only when other arguments are None)
spreadboolWhether to split non-time-series list-like data
sort_keysboolWhether to sort keys

Returns

TypeValueDescription
dict[str, Any]-Converted dictionary

to_json()

to_json(include=None, exclude=None, verbose=True, spread=False, indent=2, sort_keys=False)

Converts the parsed data to JSON format.

Parameters

NameTypeDescription
includeoptional set[str]Set of keys (members) to include in the JSON
excludeoptional set[str]Set of keys (members) to exclude from the JSON
verboseboolWhether to include system information (only when other arguments are None)
spreadboolWhether to split non-time-series list-like data
indentoptional intNumber of spaces for indentation (None for no newline)
sort_keysboolWhether to sort keys

Returns

TypeValueDescription
str-Converted JSON string

model_*()