# Path: accounts/utils.py
# def user_without_team(user):
#     return user.profile.team is None


from cities_light.models import Country
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Sum
from django.db.models.expressions import RawSQL
from django.db.models.functions import Coalesce
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete
from accounts.utils import user_without_team
        from challenges.models import Challenge
        from challenges.models import Challenge
        from challenges.models import Category
        from challenges.models import ChallengeSolved
        from challenges.models import Challenge
        from challenges.models import Challenge
    from SCTF.consumers import send_message_to_user
    from SCTF.consumers import send_message_to_user
    def total_points(self):
        return getattr(self, 'points', None) or self.solved_challenges.total_points()

    @property
    def num_success(self):
        return self.solved_challenges.count() or 0

    @property
    def num_fails(self):
        return self.failed_challenges.count() or 0

    @property
    def num_failed_challenges(self):
        return self.failed_challenges.distinct().count() or 0

    def num_never_tried_challenges(self):
        return Challenge.objects.count() - self.num_success - self.num_failed_challenges

    @property
    def progress(self):
        return int(self.solved_challenges.count() / (Challenge.objects.count() or 1) * 100)

    @property
    def position(self):
        # TODO check if can annotate it with sql rownumber
        # if not test if using value_list is faster or not
        elements = self.__class__.objects.ordered().values_list('id', flat=True)
        return next(i for i, e in enumerate(elements, 1) if e == self.pk)

    @property

# Path: accounts/utils.py
# def user_without_team(user):
#     return user.profile.team is None


# Path: accounts/models.py
from cities_light.models import Country
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Sum
from django.db.models.expressions import RawSQL
from django.db.models.functions import Coalesce
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete
from accounts.utils import user_without_team
        from challenges.models import Challenge
        from challenges.models import Challenge
        from challenges.models import Category
        from challenges.models import ChallengeSolved
        from challenges.models import Challenge
        from challenges.models import Challenge
    from SCTF.consumers import send_message_to_user
    from SCTF.consumers import send_message_to_user

    def total_points(self):
        return getattr(self, 'points', None) or self.solved_challenges.total_points()

    @property
    def num_success(self):
        return self.solved_challenges.count() or 0

    @property
    def num_fails(self):
        return self.failed_challenges.count() or 0

    @property
    def num_failed_challenges(self):
        return self.failed_challenges.distinct().count() or 0

    def num_never_tried_challenges(self):
        return Challenge.objects.count() - self.num_success - self.num_failed_challenges

    @property
    def progress(self):
        return int(self.solved_challenges.count() / (Challenge.objects.count() or 1) * 100)

    @property
    def position(self):
        # TODO check if can annotate it with sql rownumber
        # if not test if using value_list is faster or not
        elements = self.__class__.objects.ordered().values_list('id', flat=True)
        return next(i for i, e in enumerate(elements, 1) if e == self.pk)

    @property

    def score_over_time(self):