NewMessageThreads

toloka.metrics.metrics.NewMessageThreads | Source code

NewMessageThreads(
self,
cursor_time_lag: timedelta = ...,
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

ParametersTypeDescription
cursor_time_lagtimedelta

Time lag for cursor. This controls time lag between message threads being created and this metric being updated. See BaseCursor.time_lag for details and reasoning behind this.

count_nameOptional[str]

Metric name for a count of new messages.

projects_nameDict[str, str]

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

pools_nameDict[str, str]

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

join_eventsbool

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

MethodDescription
get_line_namesReturns a list of metric names that can be generated by this class instance.

Last updated: August 28, 2023

Toloka-Kit
OverviewGetting API keyQuick start
Recipes
Reference
toloka.client
toloka.async_client
toloka.autoquality [autoquality]
toloka.metrics
toloka.streaming