<commit_before># Generic Statistics Thingy
from db import conn
import web


def get_edits(user=None):
    cur = conn.cursor()
    if user is None:
        cur.execute("SELECT score FROM edits")
        edits = cur.fetchall()
    else:
        cur.execute("SELECT score FROM edits WHERE username=(SELECT wp_username from users where uid=%s)", [str(user)])
        edits = cur.fetchall()
    cur.close()
    return edits


def get_total_score(user=None):
    edits = get_edits(user)
    return sum([i[0] for i in edits])


def get_avg_score(user=None):
    edits = get_edits(user)
    try:
        return sum([i[0] for i in edits])/len(edits)
    except:
        return 0


@web.app.context_processor
def hue():
    return {'get_edits': get_edits,
            'get_total_score': get_total_score,
            'get_avg_score': get_avg_score,
            'len': len}<commit_msg>wow so much userstats very rounding<commit_after># Generic Statistics Thingy
from db import conn
import web


def get_edits(user=None):
    cur = conn.cursor()
    if user is None:
        cur.execute("SELECT score FROM edits")
        edits = cur.fetchall()
    else:
        cur.execute("SELECT score FROM edits WHERE username=(SELECT wp_username from users where uid=%s)", [str(user)])
        edits = cur.fetchall()
    cur.close()
    return edits


def get_total_score(user=None):
    edits = get_edits(user)
    return sum([i[0] for i in edits])


def get_avg_score(user=None):
    edits = get_edits(user)
    try:
        return sum([i[0] for i in edits])/len(edits)
    except:
        return 0


@web.app.context_processor
def hue():
    return {'get_edits': get_edits,
            'get_total_score': get_total_score,
            'get_avg_score': get_avg_score,
            'len': len,
            'round': round}
{'fraction_non_alphanumeric': 0.11247216035634744, 'fraction_numerical': 0.0033407572383073497, 'mean_word_length': 2.7911392405063293, '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': '1499075', 'n_tokens_mistral': 608, 'n_tokens_neox': 591, 'n_words': 162}