<commit_before>#!/usr/bin/env python2
# https://github.com/rshk/elo/blob/master/elo.py
from __future__ import division
import random

def expected(A, B):
    """
    Calculate expected score of A in a match against B
    :param A: Elo rating for player A
    :param B: Elo rating for player B
    """
    return 1 / (1 + 10 ** ((B - A) / 400))

def elo(old, exp, score, k=32):
    """
    Calculate the new Elo rating for a player
    :param old: The previous Elo rating
    :param exp: The expected score for this match
    :param score: The actual score for this match
    :param k: The k-factor for Elo (default: 32)
    """
    return old + k * (score - exp)

ranges = [[0,6], [3, 8], [5, 10]]
maxidx = len(ranges) - 1
elos = [1000] * len(ranges)

## begin one game

a = random.randint(0, maxidx)
b = a
while b == a:
    b = random.randint(0, maxidx)

print a, b
print ranges[a], ranges[b]
a_s = random.uniform(*ranges[a])
b_s = random.uniform(*ranges[b])
print a_s, b_s

ascore = 0.5
bscore = 0.5
if a_s > b_s:
    print a, "wins"
    ascore = 1
    bscore = 0
else:
    print b, "wins"
    ascore = 0
    bscore = 1

ex = expected(elos[a], elos[b])
print "expected", ex
print a, "new", elo(elos[a], ex, ascore)
print b, "new", elo(elos[b], ex, bscore)<commit_msg>Many games, one printout line per game.<commit_after>#!/usr/bin/env python2
# https://github.com/rshk/elo/blob/master/elo.py
from __future__ import division
import random

def expected(A, B):
    """
    Calculate expected score of A in a match against B
    :param A: Elo rating for player A
    :param B: Elo rating for player B
    """
    return 1 / (1 + 10 ** ((B - A) / 400))

def elo(old, exp, score, k=32):
    """
    Calculate the new Elo rating for a player
    :param old: The previous Elo rating
    :param exp: The expected score for this match
    :param score: The actual score for this match
    :param k: The k-factor for Elo (default: 32)
    """
    return old + k * (score - exp)

ranges = [[0,6], [3, 8], [5, 10]]
maxidx = len(ranges) - 1
elos = [1000] * len(ranges)

for i in range(100):
    a = random.randint(0, maxidx)
    b = a
    while b == a:
        b = random.randint(0, maxidx)
    #print a, b
    #print ranges[a], ranges[b]
    a_s = random.uniform(*ranges[a])
    b_s = random.uniform(*ranges[b])
    #print a_s, b_s
    ascore = 0.5
    bscore = 0.5
    if a_s > b_s:
        print a, "wins", b, "loses", 
        ascore = 1
        bscore = 0
    else:
        print b, "wins", a, "loses", 
        ascore = 0
        bscore = 1
    ex = expected(elos[a], elos[b])
    #print "expected", ex
    ea = elo(elos[a], ex, ascore)
    eb = elo(elos[b], ex, bscore)
    #print a, "new", ea
    #print b, "new", eb
    elos[a] = ea
    elos[b] = eb
    print map(lambda x: round(x, 1), elos)
{'fraction_non_alphanumeric': 0.14408602150537633, 'fraction_numerical': 0.025806451612903226, 'mean_word_length': 2.5966494845360826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7157282', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1063, 'n_words': 364}