<commit_before>import calendar
import datetime
from collections import OrderedDict
#import time

from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.db import connection
from django.db.models import Avg, Count, Max, Min, Sum
from django.http import Http404
from django.shortcuts import *
from django.template import RequestContext

from evething.thing.models import *
from evething.thing import queries

# ---------------------------------------------------------------------------
# How many days to start warning about expiring accounts
EXPIRE_WARNING = datetime.timedelta(10)

# ---------------------------------------------------------------------------
# Home page
@login_required
def home(request):
    total_balance = 0

    now = datetime.datetime.utcnow()

    # Grab the initial set of characters and do some stuff
    apikeys = set()
    training = set()
    chars = OrderedDict()
    for char in Character.objects.select_related('apikey').filter(apikey__user=request.user).order_by('apikey__name', 'name'):
        char.z_training = {}
        chars[char.eve_character_id] = char
        apikeys.add(char.apikey_id)
        total_balance += char.wallet_balance

        # See if the account expires soon
        timediff = char.apikey.paid_until - now
        if timediff < EXPIRE_WARNING:
            char.z_expires = timediff.total_seconds()

    # Do skill training check - this can't be in the model because it
    # scales like crap doing individual queries
    utcnow = datetime.datetime.utcnow()
    queues = SkillQueue.objects.select_related().filter(character__in=chars.keys(), end_time__gte=utcnow)
    for sq in queues:
        char = chars[sq.character_id]
        if 'sq' not in char.z_training:
            char.z_training['sq'] = sq
            char.z_training['skill_duration'] = (sq.end_time - utcnow).total_seconds()
            char.z_training['sp_per_hour'] = int(sq.skill.get_sp_per_minute(char) * 60)
            char.z_training['complete_per'] = sq.get_complete_percentage(now)
            training.add(char.apikey_id)<commit_msg>Fix error when an APIKey has been added but AccountStatus not yet updated<commit_after>import calendar
import datetime
from collections import OrderedDict
#import time

from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.db import connection
from django.db.models import Avg, Count, Max, Min, Sum
from django.http import Http404
from django.shortcuts import *
from django.template import RequestContext

from evething.thing.models import *
from evething.thing import queries

# ---------------------------------------------------------------------------
# How many days to start warning about expiring accounts
EXPIRE_WARNING = datetime.timedelta(10)

# ---------------------------------------------------------------------------
# Home page
@login_required
def home(request):
    total_balance = 0

    now = datetime.datetime.utcnow()

    # Grab the initial set of characters and do some stuff
    apikeys = set()
    training = set()
    chars = OrderedDict()
    for char in Character.objects.select_related('apikey').filter(apikey__user=request.user).order_by('apikey__name', 'name'):
        char.z_training = {}
        chars[char.eve_character_id] = char
        apikeys.add(char.apikey_id)
        total_balance += char.wallet_balance

        # See if the account expires soon
        if char.apikey.paid_until:
            timediff = char.apikey.paid_until - now
            if timediff < EXPIRE_WARNING:
                char.z_expires = timediff.total_seconds()

    # Do skill training check - this can't be in the model because it
    # scales like crap doing individual queries
    utcnow = datetime.datetime.utcnow()
    queues = SkillQueue.objects.select_related().filter(character__in=chars.keys(), end_time__gte=utcnow)
    for sq in queues:
        char = chars[sq.character_id]
        if 'sq' not in char.z_training:
            char.z_training['sq'] = sq
            char.z_training['skill_duration'] = (sq.end_time - utcnow).total_seconds()
            char.z_training['sp_per_hour'] = int(sq.skill.get_sp_per_minute(char) * 60)
            char.z_training['complete_per'] = sq.get_complete_percentage(now)
            training.add(char.apikey_id)
{'fraction_non_alphanumeric': 0.14677883551029444, 'fraction_numerical': 0.0035421740092982067, 'mean_word_length': 2.652384801940178, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2432066', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1239, 'n_words': 333}