tracking

Tracking receiver implementation for the coding experiments library.

This module provides a receiver implementation that collects detailed statistics about message reception, including success rates, processing times, and compression metrics. It’s designed for experimental analysis and performance evaluation.

class codinglab.receivers.tracking.TransmissionStats(total_messages=0, successful_messages=0, decoded_messages=0, failed_messages=0, total_source_symbols=0, total_channel_symbols=0, decode_errors=0, validation_errors=0, total_processing_time=0.0, avg_message_time=0.0)[source]

Bases: object

Statistics collected during message transmission and reception.

This class tracks various metrics about the transmission process, including message counts, symbol counts, error rates, and timing information. It also provides computed properties for common performance indicators.

Parameters:
  • total_messages (int)

  • successful_messages (int)

  • decoded_messages (int)

  • failed_messages (int)

  • total_source_symbols (int)

  • total_channel_symbols (int)

  • decode_errors (int)

  • validation_errors (int)

  • total_processing_time (float)

  • avg_message_time (float)

total_messages: int = 0

Total number of messages processed.

successful_messages: int = 0

Number of correctly decoded messages.

decoded_messages: int = 0

Number of decoded messages.

failed_messages: int = 0

Number of messages that failed to decode.

total_source_symbols: int = 0

Total number of source symbols processed.

total_channel_symbols: int = 0

Total number of channel symbols processed.

decode_errors: int = 0

Number of decoding errors encountered.

validation_errors: int = 0

Number of validation errors (decoded message not match original).

total_processing_time: float = 0.0

Total time spent processing messages (seconds).

avg_message_time: float = 0.0

Average processing time per message (seconds).

property success_rate: float

Calculate the success rate of message transmission.

Returns:

Ratio of successful messages to total messages, or 0.0 if no messages have been processed

property compression_ratio: float

Calculate the compression ratio achieved by encoding.

Returns:

Ratio of source symbols to channel symbols, or 0.0 if no channel symbols have been processed

Note

Values greater than 1.0 indicate compression (fewer channel symbols than source symbols), while values less than 1.0 indicate expansion.

property average_code_len: float

Calculate the average code length per source symbol.

Returns:

Average number of channel symbols per source symbol, or 0.0 if no source symbols have been processed

__init__(total_messages=0, successful_messages=0, decoded_messages=0, failed_messages=0, total_source_symbols=0, total_channel_symbols=0, decode_errors=0, validation_errors=0, total_processing_time=0.0, avg_message_time=0.0)
Parameters:
  • total_messages (int)

  • successful_messages (int)

  • decoded_messages (int)

  • failed_messages (int)

  • total_source_symbols (int)

  • total_channel_symbols (int)

  • decode_errors (int)

  • validation_errors (int)

  • total_processing_time (float)

  • avg_message_time (float)

Return type:

None

class codinglab.receivers.tracking.TrackingReceiver(decoder, logger=<codinglab.logger.NullLogger object>)[source]

Bases: Receiver[SourceChar, ChannelChar]

Receiver that tracks detailed statistics about message reception.

This receiver not only decodes messages but also collects extensive statistics about the reception process, including timing information, success rates, and compression metrics. It’s ideal for experimental analysis and performance evaluation.

Note: stats will not contain failed_messages and successful_messages if logger does not have method check_message as their value can be computed based only on knowing messages sent by sender.

Parameters:
__init__(decoder, logger=<codinglab.logger.NullLogger object>)[source]

Initialize the tracking receiver.

Parameters:
  • decoder (Decoder[TypeVar(SourceChar), TypeVar(ChannelChar)]) – Decoder instance for converting channel symbols back to source messages

  • logger (TransmissionLogger) – Logger for recording transmission events (defaults to NullLogger)

Return type:

None

receive_stream(messages)[source]

Receive, decode, and track statistics for a stream of messages.

This implementation decodes each message, tracks detailed statistics about the decoding process, logs events, and yields True for successful decoding or False for failures.

Parameters:

messages (Iterator[Message[TypeVar(ChannelChar)]]) – Iterator of messages received from a channel

Yields:

True for each successfully received and decoded message, False for messages that failed to decode

Return type:

Iterator[bool]

Note

All statistics are updated incrementally as messages are processed, allowing real-time monitoring of performance.

get_last_message()[source]

Get the last successfully decoded message.

Return type:

Optional[Message[TypeVar(SourceChar)]]

Returns:

The last decoded source message, or None if no messages have been successfully decoded yet

get_stats()[source]

Get the current transmission statistics.

Return type:

TransmissionStats

Returns:

Copy of the current TransmissionStats object with all collected metrics

reset_stats()[source]

Reset all statistics and logs to their initial state.

This method clears all collected statistics and logs, allowing the receiver to start fresh for a new experiment or test run.

Return type:

None