Daemo API Client

class daemo.client.DaemoClient(credentials_path='credentials.json', rerun_key=None, multi_threading=False, host=None, is_secure=True, is_sandbox=False, log_config=None)[source]

Initializes Daemo Client by authentication with Daemo host server.

First download the credentials file from your Daemo User Profile. Fill in the RERUN_KEY which is considered incremental number here for each run.

RERUN_KEY = '0001'

client = DaemoClient(rerun_key=RERUN_KEY)
Parameters:
  • credentials_path – path of the daemo credentials file which can be downloaded from daemo user profile (Menu >> Get Credentials)
  • rerun_key – a string used to differentiate each script run. If this key is same, it replays the last results from worker responses and brings you to the last point when script stopped execution.
  • multi_threading – False by default, bool value to enable multi-threaded response handling
  • host – daemo server to connect to - uses a default server if not defined
  • is_secure – boolean flag to control if connection happen via secure mode or not
  • is_sandbox – boolean flag to control if tasks will be posted to sandbox instead of production system of Daemo
  • log_config – standard python logging module based dictionary config to control logging
peer_review(project_key, worker_responses, review_completed, inter_task_review=False)[source]

Performs peer review for all the worker responses and when all ratings from peer feedback are received, review_completed callback is triggered.

Parameters:
  • project_key – string key for the project as shown in Daemo’s Project Authoring Interface. It is a unique for each project
  • worker_responses – list of worker responses to the given task
  • review_completed – a callback function to process all the ratings received from peer feedback on the worker responses
  • inter_task_review – a boolean value to control if peer feedback should be allowed across workers on same task or not. If True, it will allow peer feedback for workers for any task they completed in the past irrespective of their similiarity. If False, it only allows peer feedback among workers for the same task they completed
::
def review_completed(worker_responses):
client.rate(PROJECT_KEY, worker_responses)
client.peer_review(
project_key=PROJECT_KEY, worker_responses=worker_responses, review_completed=review_completed

)

Returns:review response
peer_review_and_rate(project_key, worker_responses, inter_task_review=False)[source]

Performs peer review for all the worker responses and when all ratings from peer feedback are received, these ratings are fed back to the platform to update worker ratings.

Parameters:
  • project_key – string key for the project as shown in Daemo’s Project Authoring Interface. It is unique for each project
  • worker_responses – list of worker responses to the given task
  • review_completed – a callback function to process all the ratings received from peer feedback on the worker responses
  • inter_task_review – a boolean value to control if peer feedback should be allowed across workers on same task or not. If True, it will allow peer feedback for workers for any task they completed in the past irrespective of their similiarity. If False, it only allows peer feedback among workers for the same task they completed
Returns:

review response

publish(project_key, tasks, approve, completed, mock_workers=None, stream=False)[source]

Publishes the project if not already published and creates new tasks based on the tasks list provided

A typical usage is given below and each of the callbacks are explained further:

client.publish(
    project_key='k0BXZxVz4P3w',
    tasks=[{
        "id": id,
        "tweet": text
    }],
    approve=approve_tweet,
    completed=post_to_twitter
)
Parameters:
  • project_key – string key for the project as shown in Daemo’s Project Authoring Interface. It is unique for each project.
  • tasks – list object with data for each task in a key-value pair where each key is used in Daemo’s Project Authoring Interface as replaceable value

A typical tasks list object is given below which passes an id and tweet text as input for each task. Remember these keys – id, tweet – have been used while creating task fields on Daemo task authoring interface.

tasks=[{
    "id": id,
    "tweet": text
}]
Parameters:approve – a callback function which process worker responses to produce boolean value indicating if each worker response should be accepted and thus, paid or not.

A typical approve callback function is given below which checks if tweet text in worker response is not empty.

def approve_tweet(worker_responses):
    approvals = [len(get_tweet_text(response)) > 0 for response in worker_responses]
    return approvals
Parameters:completed – a callback function similiar to approve callback but process only the approved worker responses. It doesn’t return any value.

A typical completed callback function is given below which posts all the approved worker responses to twitter.

def post_to_twitter(worker_responses):
    for worker_response in worker_responses:
        twitter.post(worker_response)
Parameters:mock_workers – a callback function which simulates workers passing responses to different tasks

A typical mock_workers callback function is given below which provides some text for tweet on behalf of count number of workers.

def mock_workers(task, count):
    results = [
        [{
            "name": "tweet",
            "value": "%d. Trump Trump everywhere not a Hillary to see." % num
        }] for num in range(count)]
    return results
Parameters:stream – a boolean value which controls whether worker response should be received as soon as each worker has submitted or wait for all of them to complete.
rate(project_key, ratings, ignore_history=False)[source]

Rate a worker submission

Parameters:
  • project_key – string key for the project as shown in Daemo’s Project Authoring Interface. It is unique for each project.
  • ratings – list object which provides ratings for one or more worker responses.

Below, a single rating object is shown which must have three parameters - task_id, worker_id and weight.

rating = {
        "task_id": unique ID for the task (is available from the worker response),
        "worker_id": unique ID for the worker (is available from the worker response),
        "weight": rating value (can be integer or float)
}

ratings = [rating]
Parameters:ignore_history – boolean value that determines whether historical ratings should be considered for updating this new rating.

If true, a worker’s score will be set to the score that is provided to rate. If peer review is being used, this value should be set to True.

::
client.rate(
project_key=’k0BXZxVz4P3w’, ratings=ratings

)

Returns:rating response