Example #1
0
    def get(self, assignment_target):
        # Extract assignment
        assignments = [
            self.data_handler.get_assignment_data(assignment_target)
        ]
        pairings = self.data_handler.get_pairings_for_assignment(
            assignment_target)
        processed_assignments = merge_assignments_with_pairings(
            assignments, pairings, 'assignment {}'.format(assignment_target))
        assignment = processed_assignments[0]

        # Get assignment details to retrieve assignment content
        run_id = assignment['run_id']
        onboarding_id = assignment['onboarding_id']
        conversation_id = assignment['conversation_id']
        worker_id = assignment['worker_id']

        onboard_data = None
        if onboarding_id is not None:
            onboard_data = MTurkDataHandler.get_conversation_data(
                run_id, onboarding_id, worker_id, self.state['is_sandbox'])

        assignment_content = {
            'onboarding':
            onboard_data,
            'task':
            MTurkDataHandler.get_conversation_data(run_id, conversation_id,
                                                   worker_id,
                                                   self.state['is_sandbox']),
            'task_name':
            '_'.join(run_id.split('_')[:-1]),
        }

        # Get assignment instruction html. This can be much improved
        taskname = '_'.join(run_id.split('_')[:-1])
        guess_loc = tasks[taskname].split('tasks/')[1]
        guess_class = '.'.join(guess_loc.split('/'))
        base_format = 'parlai.mturk.tasks.{}.task_config'
        if 'parlai_internal' in guess_loc:
            base_format = 'parlai_internal.mturk.tasks.{}.task_config'
        find_location = base_format.format(guess_class)
        try:
            # Try to find the task at specified location
            t = importlib.import_module(find_location)
            task_instructions = t.task_config['task_description']
        except ImportError:
            task_instructions = None

        data = {
            'assignment_details': assignment,
            'assignment_content': assignment_content,
            'assignment_instructions': task_instructions,
        }

        self.write(json.dumps(data))
Example #2
0
    def get(self, assignment_target):
        # Extract assignment
        assignments = [self.data_handler.get_assignment_data(
            assignment_target)]
        pairings = self.data_handler.get_pairings_for_assignment(
            assignment_target)
        processed_assignments = merge_assignments_with_pairings(
            assignments, pairings, 'assignment {}'.format(assignment_target))
        assignment = processed_assignments[0]

        # Get assignment details to retrieve assignment content
        run_id = assignment['run_id']
        onboarding_id = assignment['onboarding_id']
        conversation_id = assignment['conversation_id']
        worker_id = assignment['worker_id']

        onboard_data = None
        if onboarding_id is not None:
            onboard_data = MTurkDataHandler.get_conversation_data(
                run_id, onboarding_id, worker_id, self.state['is_sandbox'])

        assignment_content = {
            'onboarding': onboard_data,
            'task': MTurkDataHandler.get_conversation_data(
                run_id, conversation_id, worker_id, self.state['is_sandbox']),
        }

        # Get assignment instruction html
        taskname = '_'.join(run_id.split('_')[:-1])
        find_location = 'parlai.mturk.tasks.{}.task_config'.format(taskname)
        find_location_internal = \
            'parlai_internal.mturk.tasks.{}.task_config'.format(taskname)
        try:
            # Try to find the task config in public tasks
            t = importlib.import_module(find_location)
            task_instructions = t.task_config['task_description']
        except ImportError:
            try:
                # Try to find the task in local tasks
                t = importlib.import_module(find_location_internal)
                task_instructions = t.task_config['task_description']
            except ImportError:
                task_instructions = None

        data = {
            'assignment_details': assignment,
            'assignment_content': assignment_content,
            'assignment_instructions': task_instructions,
        }

        self.write(json.dumps(data))
Example #3
0
    def get(self, task_target):
        hits = self.data_handler.get_hits_for_run(task_target)
        processed_hits = []
        for res in hits:
            processed_hits.append(row_to_dict(res))
        assignments = self.data_handler.get_assignments_for_run(task_target)
        pairings = self.data_handler.get_pairings_for_run(task_target)
        processed_assignments = merge_assignments_with_pairings(
            assignments, pairings, 'task {}'.format(task_target))

        # get feedback data and put into assignments if present
        for assignment in processed_assignments:
            assignment['received_feedback'] = None
            run_id = assignment['run_id']
            conversation_id = assignment['conversation_id']
            worker_id = assignment['worker_id']
            if conversation_id is not None:
                task_data = MTurkDataHandler.get_conversation_data(
                    run_id, conversation_id, worker_id,
                    self.state['is_sandbox'])
                if task_data['data'] is not None:
                    assignment['received_feedback'] = \
                        task_data['data'].get('received_feedback')

        run_details = row_to_dict(self.data_handler.get_run_data(task_target))
        # TODO implement run status determination
        run_details['run_status'] = 'unimplemented'
        data = {
            'run_details': run_details,
            'assignments': processed_assignments,
            'hits': processed_hits,
        }

        self.write(json.dumps(data))