<commit_before>from optparse import make_option
import sys
from django.core.management.base import BaseCommand
from challenge.models import Challenge, UserChallenge
from resources.models import Resource
from django.conf import settings
from django.db.models import Avg, Max, Min, Count

class Command(BaseCommand):
    args = ""
    help = "Update challenge total_questions and total_resources (post db import)"
    
    def handle(self, *args, **options):

        from wallextend.models import add_extended_wallitem

        challenges = Challenge.objects.filter(userchallenge__status=2).distinct()
        
        for challenge in challenges:
            userchallenge = challenge.userchallenge_set.order_by('-completed')[0]
            
            add_extended_wallitem(challenge.wall,userchallenge.user,created_at=userchallenge.completed,template_name='challenge_1stcomplete.html',extra_context={
                                                    'body':'is the first to complete!',
                                                    'challenge': challenge,
                                                    'userchallenge': userchallenge,
                                                    })            
                                                    
                                                            <commit_msg>Fix order for 'first to complete' calculation<commit_after>from optparse import make_option
import sys
from django.core.management.base import BaseCommand
from challenge.models import Challenge, UserChallenge
from resources.models import Resource
from django.conf import settings
from django.db.models import Avg, Max, Min, Count

class Command(BaseCommand):
    args = ""
    help = "Update challenge total_questions and total_resources (post db import)"
    
    def handle(self, *args, **options):

        from wallextend.models import add_extended_wallitem

        challenges = Challenge.objects.filter(userchallenge__status=2).distinct()
        
        for challenge in challenges:
            userchallenge = challenge.userchallenge_set.order_by('completed')[0]
            
            add_extended_wallitem(challenge.wall,userchallenge.user,created_at=userchallenge.completed,template_name='challenge_1stcomplete.html',extra_context={
                                                    'body':'is the first to complete!',
                                                    'challenge': challenge,
                                                    'userchallenge': userchallenge,
                                                    })            
                                                    
                                                            
{'fraction_non_alphanumeric': 0.06436189775652813, 'fraction_numerical': 0.002206693637366679, 'mean_word_length': 1.6204238921001928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '260738', 'n_tokens_mistral': 589, 'n_tokens_neox': 527, 'n_words': 142}