<commit_before># -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from django.db import connection
from math import exp
from geography.models import Elo


class Command(BaseCommand):
    help = u'''Recompute derived data'''

    def handle(self, *args, **options):
        if len(args) > 0:
            raise CommandError('The command doesn\'t need any option.')
        self.load_derived_data()

    def load_derived_data(self):
        cursor = connection.cursor()
        # foreach answer update new datasets
        skills = {}
        local_skills = {}
        difficulties = {}
        cursor.execute('SELECT * FROM geography_answer')
        answer = self.fetchone(cursor)
        while answer:
            skill = skills.get(answer['user_id'], (0, 1))
            difficulty = difficulties.get(answer['place_asked_id'], (0, 1))
            local_skill = local_skills.get(
                (answer['user_id'], answer['place_asked_id']),
                ((skill[0] - difficulty[0]), 1))
            guess = 1.0 / answer['number_of_options'] if answer['number_of_options'] != 0 else 0
            prediction = self.predict(local_skill[0], guess)
            result = answer['place_asked_id'] == answer['place_answered_id']
            if local_skills.get((answer['user_id'], answer['place_asked_id']), None):
                skills[answer['user_id']] = (
                    skill[0] + Elo.alpha_fun(Elo.ALPHA_1, skill[1]) * (result - prediction),
                    skill[1] + 1
                )
                difficulties[answer['place_asked_id']] = (
                    difficulty[0] - Elo.alpha_fun(Elo.ALPHA_1, difficulty[1]) * (result - prediction),
                    difficulty[1] + 1
                )
            local_skills[(answer['user_id'], answer['place_asked_id'])] = (
                local_skill[0] + Elo.ALPHA_2 * (result - prediction),
                local_skill[1] + 1
            )
            answer = self.fetchone(cursor)
        # empty precomputed datasets<commit_msg>fix precomputation of prior knowledge #45<commit_after># -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from django.db import connection
from math import exp
from geography.models import Elo


class Command(BaseCommand):
    help = u'''Recompute derived data'''

    def handle(self, *args, **options):
        if len(args) > 0:
            raise CommandError('The command doesn\'t need any option.')
        self.load_derived_data()

    def load_derived_data(self):
        cursor = connection.cursor()
        # foreach answer update new datasets
        skills = {}
        local_skills = {}
        difficulties = {}
        cursor.execute('SELECT * FROM geography_answer')
        answer = self.fetchone(cursor)
        while answer:
            skill = skills.get(answer['user_id'], (0, 1))
            difficulty = difficulties.get(answer['place_asked_id'], (0, 1))
            local_skill = local_skills.get(
                (answer['user_id'], answer['place_asked_id']),
                ((skill[0] - difficulty[0]), 1))
            guess = 1.0 / answer['number_of_options'] if answer['number_of_options'] != 0 else 0
            prediction = self.predict(local_skill[0], guess)
            result = answer['place_asked_id'] == answer['place_answered_id']
            if not local_skills.get((answer['user_id'], answer['place_asked_id']), None):
                skills[answer['user_id']] = (
                    skill[0] + Elo.alpha_fun(Elo.ALPHA_1, skill[1]) * (result - prediction),
                    skill[1] + 1
                )
                difficulties[answer['place_asked_id']] = (
                    difficulty[0] - Elo.alpha_fun(Elo.ALPHA_1, difficulty[1]) * (result - prediction),
                    difficulty[1] + 1
                )
            else:
                skills[answer['user_id']] = (skill[0], skill[1] + 1)
                difficulties[answer['place_asked_id']] = (difficulty[0], difficulty[1] + 1)
            local_skills[(answer['user_id'], answer['place_asked_id'])] = (
                local_skill[0] + Elo.ALPHA_2 * (result - prediction),
                local_skill[1] + 1
            )
            answer = self.fetchone(cursor)
        # empty precomputed datasets
{'fraction_non_alphanumeric': 0.12921217755054612, 'fraction_numerical': 0.01487334417848013, 'mean_word_length': 2.174041297935103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4153529', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1240, 'n_words': 258}