<commit_before>from flask import Blueprint, jsonify
from gfsad.models import db
from sqlalchemy import text
import datetime


stats_blueprint = Blueprint('stats', __name__, url_prefix='/stats')


def get_leaders(since='2015-01-01', source='ground', limit=30):
    kwargs = locals().copy()

    cmd = text("""
          SELECT record.count, initcap(u.first) AS first, upper(substring(u.last from 0 for 1)) AS last, u.organization FROM (SELECT record.user_id AS user_id, count(*) AS count
          FROM record
          LEFT JOIN location
          ON location.id = record.location_id
          WHERE location.use_deleted IS FALSE
          AND record.user_id IS NOT NULL
          AND record.source_type = :source
          AND record.date_created > DATE (:since)
          GROUP BY record.user_id) AS record
          LEFT JOIN "user" AS u ON u.id = record.user_id
          ORDER BY record.count DESC
          LIMIT :limit
          """)

    result = db.engine.execute(cmd, kwargs)

    return [dict(row) for row in result]


@stats_blueprint.route("/leaders")
def leader_view():
    month_ago = (datetime.date.today() - datetime.timedelta(days=30)).isoformat()
    week_ago = (datetime.date.today() - datetime.timedelta(days=7)).isoformat()
    day_ago = (datetime.datetime.today() - datetime.timedelta(hours=24)).isoformat()<commit_msg>1 based index<commit_after>from flask import Blueprint, jsonify
from gfsad.models import db
from sqlalchemy import text
import datetime


stats_blueprint = Blueprint('stats', __name__, url_prefix='/stats')


def get_leaders(since='2015-01-01', source='ground', limit=30):
    kwargs = locals().copy()

    cmd = text("""
          SELECT record.count, initcap(u.first) AS first, upper(substring(u.last from 1 for 1)) AS last, u.organization FROM (SELECT record.user_id AS user_id, count(*) AS count
          FROM record
          LEFT JOIN location
          ON location.id = record.location_id
          WHERE location.use_deleted IS FALSE
          AND record.user_id IS NOT NULL
          AND record.source_type = :source
          AND record.date_created > DATE (:since)
          GROUP BY record.user_id) AS record
          LEFT JOIN "user" AS u ON u.id = record.user_id
          ORDER BY record.count DESC
          LIMIT :limit
          """)

    result = db.engine.execute(cmd, kwargs)

    return [dict(row) for row in result]


@stats_blueprint.route("/leaders")
def leader_view():
    month_ago = (datetime.date.today() - datetime.timedelta(days=30)).isoformat()
    week_ago = (datetime.date.today() - datetime.timedelta(days=7)).isoformat()
    day_ago = (datetime.datetime.today() - datetime.timedelta(hours=24)).isoformat()
{'fraction_non_alphanumeric': 0.11251862891207154, 'fraction_numerical': 0.013040238450074515, 'mean_word_length': 3.025487256371814, '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': '6318272', 'n_tokens_mistral': 851, 'n_tokens_neox': 790, 'n_words': 225}