@@ -0,0 +1,2051 @@
+from django.core.management.base import BaseCommand%0Aimport json%0Afrom datasets.models import CandidateAnnotation, Vote, TaxonomyNode, Dataset%0A%0A%0Aclass Command(BaseCommand):%0A    help = 'Extract user votes' %5C%0A           'Usage: python manage.py extract_votes %3Cdataset_shor_name%3E %3Coutput_file%3E'%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument('dataset_short_name', type=str)%0A        parser.add_argument('output_file', type=str)%0A%0A    def handle(self, *args, **options):%0A        dataset_short_name = options%5B'dataset_short_name'%5D%0A        output_file = options%5B'output_file'%5D%0A%0A        dataset = Dataset.objects.get(short_name=dataset_short_name)%0A        nodes = TaxonomyNode.objects.all()%0A        votes_dict = %7Bnode_id: %7B'PP': list(),%0A                                'PNP': list(),%0A                                'NP': list(),%0A                                'U': list(),%0A                                'candidates': list()%7D for node_id in nodes.values_list('node_id', flat=True)%7D%0A        vote_value_to_letter = %7B1: 'PP', 0.5: 'PNP', -1: 'NP', 0: 'U'%7D%0A%0A        votes_with_info = Vote.objects.filter(candidate_annotation__sound_dataset__dataset=dataset)%5C%0A            .values('vote', 'candidate_annotation__taxonomy_node__node_id',%0A                    'candidate_annotation__sound_dataset__sound__freesound_id')%0A        candidate_annotations = CandidateAnnotation.objects.filter(sound_dataset__dataset=dataset)%5C%0A            .values('taxonomy_node__node_id', 'sound_dataset__sound__freesound_id')%0A%0A        for vote in votes_with_info:%0A            votes_dict%5Bvote%5B'candidate_annotation__taxonomy_node__node_id'%5D%5D%5C%0A                %5Bvote_value_to_letter%5Bvote%5B'vote'%5D%5D%5D%5C%0A                .append(vote%5B'candidate_annotation__sound_dataset__sound__freesound_id'%5D)%0A%0A        for candidate_annotation in candidate_annotations:%0A            votes_dict%5Bcandidate_annotation%5B'taxonomy_node__node_id'%5D%5D%5B'candidates'%5D%5C%0A                .append(candidate_annotation%5B'sound_dataset__sound__freesound_id'%5D)%0A%0A        json.dump(votes_dict, open(output_file, 'w'))%0A

Add management command extract votes #126