Aggregate the responses from Tolokers for all completed tasks in a pool.
We recommend that you try our crowd-kit library. It has various aggregation methods and executes on your computer.
Connect the Toloka-Kit library to your script.
import toloka.client as toloka
Replace the sample API key with your own one.
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION');
Set up the parameters which you want to use for the aggregation: in this example we choose tasks from the pool with the pool_id
value, set the aggregation type to DAWID_SKENE
, and specify output fields to aggregate. The aggregate_solutions_by_pool()
method starts the aggregation.
aggregation_operation = toloka_client.aggregate_solutions_by_pool(
type=toloka.aggregation.AggregatedSolutionType.DAWID_SKENE,
pool_id='36502086',
fields=[toloka.aggregation.PoolAggregatedSolutionRequest.Field(name='result')]
)
Aggregation takes some time depending on the number of tasks and responses from Tolokers. The wait_operation()
method displays the progress of the aggregation operation and shows when it finishes.
aggregation_operation = toloka_client.wait_operation(aggregation_operation)
The output from the code portion above will look like this.
100%|████████████████████████████████████████████| 100/100 [00:52<00:00, 1.92it/s]
After the aggregation operation 100% finished, get the results with the help of the get_aggregated_solutions()
method and iterate through them.
aggregation_results = toloka_client.get_aggregated_solutions(aggregation_operation.id)
for result in aggregation_results:
print(result.task_id, result.output_values['result'])
You should get an output with the task IDs and the result
output data values which looks like this.
00022cfa46--637cf3e76e13181a0164e4b3 cat00022cfa46--637cf3e76e13181a0164e4b7 cat00022cfa46--637cf3e76e13181a0164e4bc dog00022cfa46--637cf3e86e13181a0164e4c0 cat00022cfa46--637cf3e86e13181a0164e4c4 cat00022cfa46--637cf3e86e13181a0164e4c8 dog00022cfa46--637cf3e86e13181a0164e4cd dog00022cfa46--637cf3e86e13181a0164e4d0 dog
import toloka.client as tolokatoloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')aggregation_operation = toloka_client.aggregate_solutions_by_pool( type=toloka.aggregation.AggregatedSolutionType.DAWID_SKENE, pool_id='36502086', fields=[toloka.aggregation.PoolAggregatedSolutionRequest.Field(name='result')])aggregation_operation = toloka_client.wait_operation(aggregation_operation)aggregation_results = toloka_client.get_aggregated_solutions(aggregation_operation.id)for result in aggregation_results: print(result.task_id, result.output_values['result'])
Last updated: February 7, 2023