To simplify implementation, each model (e.g. MaterialShape, Photo, ...) is expected to have certain attributes that implement various parts of the MTurk pipeline. For example, models that store user responses (“output content model”) is expected to have an mturk_submit method, and models that are used in tasks are expected to have an MTURK_PREFETCH list indicating which fields should be pre-fetched from the database.
As part of the MTurk API, the following attributes are expected to exist on input models to tasks:
Tuple of strings. When preparing to show a task, MTURK_PREFETCH declares which foreign key relationships will be used, thereby using 1 database query instead of many.
For example, if you have a model PhotoPair that represents a pair of photos (photo1 and photo2) that you are going to show to a user, you can fetch both photos at the same time by specifying:
class PhotoPair(...):
photo1 = ...
photo2 = ...
...
MTURK_PREFETCH = ('photo1', 'photo2')
The following attributes are expected to exist on output models for tasks. See server/intrinsic/models.py for example implementations.
This function is called when a MTurk HIT is submitted, and is in charge of storing the user’s response in the database. This function is free to perform slow operations, since it will be performed asynchronously by a celery worker.
Parameters: |
|
---|---|
Returns: | a dictionary mapping contents to a list of objects created from that content. The dictionary key is of the form (ContentType id, object id), called a “content tuple”, i.e. { common.utils.get_content_tuple(content): [new_obj] } for content in hit_contents. |
Process the results of a secret test (i.e. a subset of the objects have known answers). This only needs to be implemented if the experiment has test contents.
Parameters: |
|
---|---|
Returns: | (responses, responses_correct) where the \(i^\text{th}\) entry in responses is the extracted response from the \(i^\text{th}\) entry of test_contents, and the \(i^\text{th}\) entry of responses_correct is a bool indicating whether the \(i^\text{th}\) item in test_contents was correctly answered. |
Note
The mturk_grade_test method was added after the original OpenSurfaces publication, so many models do not contain this method. See server/intrinsic/models.py for a complete example.