Esempio n. 1
0
 def test_make_a_response_message(self):
     """Make a message."""
     seed = mommy.make_recipe('grunt.seed')
     message = Message(parent=seed, audio=self.audio)
     message.full_clean()
     message.save()
     self.assertEquals(message.parent, seed)
Esempio n. 2
0
    def save(self):
        """Create a transcription survey and messages for that survey."""
        survey = super(NewTranscriptionSurveyForm, self).save()

        game = self.cleaned_data.get('game')  # think this is a model
        generation = self.cleaned_data.get('generation')
        message_ids = self.cleaned_data.get('messages', [])
        catch_trial = self.cleaned_data.get('catch_trial')

        grunt_messages = []

        if game and generation:
            generation_messages = game.get_messages_by_generation(generation)
            grunt_messages.extend(list(generation_messages))

        specific_messages = Message.objects.filter(id__in=message_ids)
        grunt_messages.extend(specific_messages)

        if catch_trial:
            catch_message = Message(audio=catch_trial)
            catch_message.full_clean()
            catch_message.save()

            # Let the survey know which is a catch trial
            catch_transcription_message = survey.messages.create(given=catch_message)
            survey.catch_trial_id = catch_transcription_message.pk
            survey.save()

        # Create MessageToTranscribe objects for each grunt message
        for grunt_message in grunt_messages:
            survey.messages.create(given=grunt_message)

        return survey
Esempio n. 3
0
 def add_child(chain):
     parent = chain.pick_parent()
     with open(self.path_to_test_audio(), 'rb') as test_audio_handle:
         test_audio = File(test_audio_handle)
         child = Message(chain=chain, parent=parent, audio=test_audio)
         child.full_clean()
         child.save()
         parent.kill()
Esempio n. 4
0
    def create_game(self, name, nchains=1, depth=0, num_seeds_per_chain=1):
        """Create a game with the specified number of chains.

        Args:
            name: The name of the game to create.
            nchains: The number of chains to add to the game. Names for the
                chains are created automatically.
            depth: The number of recordings to add to each chain.
            num_seeds_per_chain: The number of seeds to add to each chain.
        """
        game = Game(name=name)
        game.full_clean()
        game.save()

        for n in range(nchains):
            chain = Chain(game=game, name='chain {}'.format(n))
            chain.full_clean()
            chain.save()

            for seed_ix in range(num_seeds_per_chain):
                seed_file = File(open(self.path_to_test_audio(), 'rb'))
                seed_message = Message(chain=chain, audio=seed_file)
                seed_message.full_clean()
                seed_message.save()
                seed_file.close()

        def add_child(chain):
            parent = chain.pick_parent()
            with open(self.path_to_test_audio(), 'rb') as test_audio_handle:
                test_audio = File(test_audio_handle)
                child = Message(chain=chain, parent=parent, audio=test_audio)
                child.full_clean()
                child.save()
                parent.kill()

        for chain in game.chains.all():
            for _ in range(depth):
                add_child(chain)
Esempio n. 5
0
 def test_make_a_response_message(self):
     seed = mommy.make_recipe('grunt.seed')
     message = Message(parent=seed, audio=self.audio)
     message.full_clean()
     message.save()
     self.assertEquals(message.parent, seed)
Esempio n. 6
0
 def test_make_a_seed_message(self):
     message = Message(chain=self.chain, audio=self.audio)
     message.full_clean()
     message.save()
Esempio n. 7
0
 def test_make_a_seed_message(self):
     """Make a seed message: a message without a parent."""
     message = Message(chain=self.chain, audio=self.audio)
     message.full_clean()
     message.save()