@@ -0,0 +1,2101 @@
+from django.core.management.base import BaseCommand%0Afrom django.core.cache import cache%0Afrom django.db.models import Prefetch%0A%0Afrom mla_game.apps.transcript.tasks import (%0A    calculate_phrase_confidence, calculate_correction_confidence,%0A    process_transcripts_awaiting_stats_update,%0A)%0A%0Afrom ...models import (%0A    Transcript, TranscriptPhrase,%0A    TranscriptPhraseDownvote, TranscriptPhraseCorrection,%0A)%0A%0A%0Aclass Command(BaseCommand):%0A    help = '''Recalculate all stats:%0A            - Transcript statistics%0A            - Phrase confidence%0A            - Correction confidence'''%0A%0A    def handle(self, *args, **options):%0A        transcript_qs = Transcript.objects.only('pk')%0A        phrase_qs = TranscriptPhrase.objects.only('pk').prefetch_related(%0A            Prefetch('transcript', queryset=transcript_qs)%0A        )%0A%0A        all_phrase_downvotes = TranscriptPhraseDownvote.objects.all(%0A            ).prefetch_related(Prefetch('transcript_phrase', queryset=phrase_qs))%0A%0A        all_phrase_upvotes = TranscriptPhraseCorrection.objects.filter(%0A            not_an_error=True%0A        ).prefetch_related(Prefetch('transcript_phrase', queryset=phrase_qs))%0A%0A        phrases_to_recalculate = set(%0A            %5Bvote.transcript_phrase for vote in all_phrase_downvotes%5D +%0A            %5Bvote.transcript_phrase for vote in all_phrase_upvotes%5D%0A        )%0A        corrections_to_recalculate = TranscriptPhraseCorrection.objects.filter(%0A            not_an_error=False%0A        )%0A%0A        transcripts_to_recalculate = set(%0A            %5Bphrase.transcript for phrase in phrases_to_recalculate%5D +%0A            %5Bcorrection.transcript_phrase.transcript%0A             for correction in corrections_to_recalculate%5D%0A        )%0A        for phrase in phrases_to_recalculate:%0A            calculate_phrase_confidence(phrase)%0A%0A        for correction in corrections_to_recalculate:%0A            calculate_correction_confidence(correction)%0A%0A        cache.set(%0A            'process_transcripts_awaiting_stats_update',%0A            transcripts_to_recalculate,%0A            60*120%0A        )%0A%0A        process_transcripts_awaiting_stats_update()%0A

Add recalculate_all command