예제 #1
0
    def handle(self, *args, **options):
        if (options['input'] is None):
            raise CommandError("Must set input")

        with open(options['input']) as f:
            data = HeaderedRow.from_iterable(csv.reader(f))

            for datum in data:
                assignment_id = datum["AssignmentId"]
                worker_id = datum["WorkerId"]
                worker_time = datum["WorkTimeInSeconds"]
                tasks = map(int, datum["Answer.taskids"].split("\t"))
                prompts = datum["Answer.prompts"].split("\t")
                responses = datum["Answer.responses"].split("\t")

                NumericExpressionResponse.objects.bulk_create([
                    NumericExpressionResponse(
                        expression=NumericExpression.objects.get(id=task),
                        prompt=prompt,
                        description=response,
                        assignment_id=assignment_id,
                        worker_id=worker_id,
                        worker_time=worker_time,
                        approval=False,
                    ) for (task, prompt,
                           response) in zip(tasks, prompts, responses)
                ])
    def handle(self, *args, **options):
        if (options['input'] is None):
            raise CommandError("Must set input")

        with open(options['input']) as f:
            data = HeaderedRow.from_iterable(csv.reader(f))

            for datum in data:
                assignment_id = datum["AssignmentId"]
                worker_id = datum["WorkerId"]
                worker_time = datum["WorkTimeInSeconds"]
                tasks = map(int, datum["Answer.taskids"].split("\t"))
                prompts = datum["Answer.prompts"].split("\t")
                responses = datum["Answer.responses"].split("\t")

                NumericExpressionResponse.objects.bulk_create([
                    NumericExpressionResponse(
                        expression = NumericExpression.objects.get(id=task),
                        prompt = prompt,
                        description = response,
                        assignment_id = assignment_id,
                        worker_id = worker_id,
                        worker_time = worker_time,
                        approval = False,
                        )
                    for (task, prompt, response) in zip(tasks, prompts, responses)])
예제 #3
0
    def handle(self, *args, **options):
        if options['input'] is None:
            raise CommandError("Must set input")

        with open(options['input']) as f:
            data = HeaderedRow.from_iterable(csv.reader(f))

            for datum in data:
                assignment_id = datum["AssignmentId"]
                worker_id = datum["WorkerId"]
                worker_time = datum["WorkTimeInSeconds"]

                if datum["Answer.comments"] != '{}':
                    print(datum["Answer.comments"])

                for response in json.loads(datum["Answer.responses"]):
                    task = NumericMentionExpressionTask.objects.get(id=response['task_id'])
                    responses = map(int, response['responses'])
                    if len(responses) == 1 and responses[0] == -1:
                        responses = []

                    NumericMentionExpressionTaskResponse.objects.bulk_create([
                        NumericMentionExpressionTaskResponse(
                            task = task,
                            chosen = responses,
                            assignment_id = assignment_id,
                            worker_id = worker_id,
                            worker_time = worker_time,
                            approval = False,
                            inspected = False,
                            )])
예제 #4
0
    def handle(self, *args, **options):
        if options['input'] is None:
            raise CommandError("Must set input")

        with open(options['input']) as f:
            data = HeaderedRow.from_iterable(csv.reader(f))

            counter = Counter()

            task_responses = []
            for datum in data:
                assignment_id = datum["AssignmentId"]
                worker_id = datum["WorkerId"]
                worker_time = datum["WorkTimeInSeconds"]

                comments = datum["Answer.comments"] if datum["Answer.comments"] != '{}' else ""
                responses = json.loads(unquote(datum["Answer.responses"]))

                if len(responses) == 0:
                    print(assignment_id, worker_id, worker_time, comments, responses)


                for response in responses:
                    counter[len(response['responses'])] += 1
            #        task = NumericPerspectiveTask.objects.get(id=response['task_id'])
            #        framing, helpfulness, relevance = map(int, response['responses'])

            #        task_response = NumericPerspectiveTaskResponse(
            #            task = task,
            #            framing = framing,
            #            helpfulness = helpfulness,
            #            relevance = relevance,
            #            assignment_id = assignment_id,
            #            worker_id = worker_id,
            #            worker_time = worker_time,
            #            approval = False,
            #            inspected = False,
            #            comments = comments
            #            )
            #        task_responses.append(task_response)

            #NumericPerspectiveTaskResponse.objects.bulk_create(task_responses)
            print(counter)
예제 #5
0
    def handle(self, *args, **options):
        if options['input'] is None:
            raise CommandError("Must set input")

        with open(options['input']) as f, transaction.atomic():
            data = HeaderedRow.from_iterable(csv.reader(f))

            counter = Counter()
            task_responses = []
            for datum in data:
                assignment_id = datum["AssignmentId"]
                worker_id = datum["WorkerId"]
                worker_time = datum["WorkTimeInSeconds"]

                comments = datum["Answer.comments"] if datum[
                    "Answer.comments"] != '{}' else ""
                #ids = [r['task_id'] for r in json.loads(unquote(datum["Answer.responses"]))]
                responses = json.loads(unquote(datum["Answer.responses"]))

                #if len(responses) == 0:
                #    print(assignment_id, worker_id, worker_time, comments, responses)

                #for task_id in ids:
                for response in responses:
                    task_id = response["task_id"]
                    #response = int(datum['Answer.response-'+str(task_id)])
                    winner = response["response"]
                    counter[winner] += 1

                    task_response = NumericPerspectiveRatingTaskResponse(
                        task_id=task_id,
                        winner=winner,
                        assignment_id=assignment_id,
                        worker_id=worker_id,
                        worker_time=worker_time,
                        approval=False,
                        inspected=False,
                        comments=comments)
                    task_responses.append(task_response)

            print(counter)
            NumericPerspectiveRatingTaskResponse.objects.bulk_create(
                task_responses)
    def handle(self, *args, **options):
        if options['input'] is None:
            raise CommandError("Must set input")

        with open(options['input']) as f, transaction.atomic():
            data = HeaderedRow.from_iterable(csv.reader(f))

            counter = Counter()
            task_responses = []
            for datum in data:
                assignment_id = datum["AssignmentId"]
                worker_id = datum["WorkerId"]
                worker_time = datum["WorkTimeInSeconds"]

                comments = datum["Answer.comments"] if datum["Answer.comments"] != '{}' else ""
                #ids = [r['task_id'] for r in json.loads(unquote(datum["Answer.responses"]))]
                responses = json.loads(unquote(datum["Answer.responses"]))

                #if len(responses) == 0:
                #    print(assignment_id, worker_id, worker_time, comments, responses)

                #for task_id in ids:
                for response in responses:
                    task_id = response["task_id"]
                    #response = int(datum['Answer.response-'+str(task_id)])
                    winner = response["response"]
                    counter[winner] += 1

                    task_response = NumericPerspectiveRatingTaskResponse(
                        task_id = task_id,
                        winner = winner,
                        assignment_id = assignment_id,
                        worker_id = worker_id,
                        worker_time = worker_time,
                        approval = False,
                        inspected = False,
                        comments = comments
                        )
                    task_responses.append(task_response)

            print(counter)
            NumericPerspectiveRatingTaskResponse.objects.bulk_create(task_responses)