<commit_before># Standard Libary
import logging
import django_rq
import json

# Django
from django.apps import apps
from django.contrib.auth.models import BaseUserManager
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.core.validators import URLValidator
from django.core.validators import validate_email
from django.db import IntegrityError
from django.db.models import Manager
from django.db.models import F
from django.db.models import CharField
from django.db.models import Value
from django.forms.models import model_to_dict
from django.utils.timezone import now
from api.tasks import get_accounts
from api.tasks import update_account
from api.tasks import delete_account
from django.db.models.functions import Concat

log = logging.getLogger(__name__)

validate_url = URLValidator()

validate_twitter = RegexValidator(
    regex=r'@([A-Za-z0-9_]+)',
    message="""
        Must be a single Twitter handle
        in the form `@twitter_handle`.
    """,
)


class AwardManager(Manager):
    def sort_tree(self):
        self.all().update(tree_sort=None)
        awards = self.order_by(
            '-status',
            'group__tree_sort',
            '-kind',
            '-is_primary',
            F('age').asc(nulls_first=True),
            'gender',
            'level',
            'size',
            'scope',
            'name',
        )
        i = 0
        for award in awards:
            i += 1
            award.tree_sort = i
            award.save()
        return


class GroupManager(Manager):
    def update_or_create_from_structure(self, structure, is_object=False):
        # Map between object/instance
        if is_object:
            mc_pk = structure[0]
            raw_name = structure[1]
            preferred_name = structure[2]
            chorus_name = structure[3]
            status = structure[4]
            kind = structure[5]
            start_date = structure[6]
            email = structure[7]
            phone = structure[8]
            website = structure[9]
            facebook = structure[10]
            twitter = structure[11]
            bhs_id = structure[12]
            parent = structure[13]<commit_msg>Manager sort comments<commit_after># Standard Libary
import logging
import django_rq
import json

# Django
from django.apps import apps
from django.contrib.auth.models import BaseUserManager
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.core.validators import URLValidator
from django.core.validators import validate_email
from django.db import IntegrityError
from django.db.models import Manager
from django.db.models import F
from django.db.models import CharField
from django.db.models import Value
from django.forms.models import model_to_dict
from django.utils.timezone import now
from api.tasks import get_accounts
from api.tasks import update_account
from api.tasks import delete_account
from django.db.models.functions import Concat

log = logging.getLogger(__name__)

validate_url = URLValidator()

validate_twitter = RegexValidator(
    regex=r'@([A-Za-z0-9_]+)',
    message="""
        Must be a single Twitter handle
        in the form `@twitter_handle`.
    """,
)


class AwardManager(Manager):
    def sort_tree(self):
        self.all().update(tree_sort=None)
        awards = self.order_by(
            '-status',  # Actives first
            'group__tree_sort',  # Basic BHS Hierarchy
            '-kind', # Quartet, Chorus
            '-is_primary',  # Primary awards first
            F('age').asc(nulls_first=True), # Null, Senior, Youth
            'gender', #Male, mixed
            'level', #Championship, qualifier
            'size', # Plateau v1
            'scope', # plateau
            'name', # alpha
        )
        i = 0
        for award in awards:
            i += 1
            award.tree_sort = i
            award.save()
        return


class GroupManager(Manager):
    def update_or_create_from_structure(self, structure, is_object=False):
        # Map between object/instance
        if is_object:
            mc_pk = structure[0]
            raw_name = structure[1]
            preferred_name = structure[2]
            chorus_name = structure[3]
            status = structure[4]
            kind = structure[5]
            start_date = structure[6]
            email = structure[7]
            phone = structure[8]
            website = structure[9]
            facebook = structure[10]
            twitter = structure[11]
            bhs_id = structure[12]
            parent = structure[13]
{'fraction_non_alphanumeric': 0.08522114347357065, 'fraction_numerical': 0.009708737864077669, 'mean_word_length': 2.3864134404674946, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6779416', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1257, 'n_words': 350}