Toloka documentation

NewMessageThreads

toloka.metrics.metrics.NewMessageThreads | Source code

NewMessageThreads(
    self,
    count_name: Optional[str] = None,
    projects_name: Dict[str, str] = ...,
    pools_name: Dict[str, str] = ...,
    join_events: bool = False,
    *,
    toloka_client: Optional[TolokaClient] = None,
    atoloka_client: Optional[AsyncTolokaClient] = None,
    timeout: timedelta = ...
)

Tracking the new messages

Could count messages in projects or pools. If you want to track messages count in several projects/pools, don't get several NewMessageThreads instance. You can gather all in one instance.

Parameters Description

Parameters Type Description
count_name Optional[str]

Metric name for a count of new messages.

projects_name Dict[str, str]

Dictionary that allows count messages on exact projects. {project_id: line_name}

pools_name Dict[str, str]

Dictionary that allows count messages on exact pools. {pool_id: line_name}

join_events bool

Count all events in one point. Default False. "Values" never join.

Examples:

How to collect this metrics:

def print_metric(metric_dict):
    print(metric_dict)

collector = MetricCollector
(
    [
        NewMessageThreads(
            toloka_client=toloka_client,
            count_name='messages_count'
            pools_name={'123': 'my_train_pool', '456': 'my_working_pool'},
            projects_name={'01': 'pedestrian_proj', '02': 'checking_proj'},
            join_events=True,
        )
    ],
    print_metric
)
asyncio.run(collector.run())
# all messages in all projects and pools
'messages_count': [(datetime.datetime(2021, 11, 19, 9, 40, 15, 970000), 10)],
# messages on this exact pool
'my_train_pool': [(datetime.datetime(2021, 11, 19, 12, 42, 50, 554830), 4)],
# with 'join_events=True' it will be zero if no messages
'my_working_pool': [(datetime.datetime(2021, 11, 19, 12, 42, 50, 554830), 0)],
'pedestrian_proj': [(datetime.datetime(2021, 11, 19, 12, 42, 50, 554830), 1)],
# total count != sum of other counts, because could exist different pools and projects
'checking_proj': [(datetime.datetime(2021, 11, 19, 12, 42, 50, 554830), 1)],

}

Methods Summary

Method Description
get_line_names Returns a list of metric names that can be generated by this class instance.