<commit_before>import uuid
import flask
import functools
from .service import SERVICES
from flask.ext.cors import cross_origin


DEFAULT_START_YEAR = 2015


class MyJSONEncoder(flask.json.JSONEncoder):
    def default(self, o):
        if hasattr(o, '__json__'):
            return o.__json__()
        return super(MyJSONEncoder, self).default(o)


app = flask.Flask(__name__)
app.json_encoder = MyJSONEncoder


def json_response(fn):
    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        result = fn(*args, **kwargs)
        return flask.jsonify(result)
    return wrapper


def _get_table_by_season_id(season_id, game_day):
    table = SERVICES['season'].get_current_table(season_id, game_day)
    result = []
    for i, row in enumerate(table):
        team, stats = row
        table_row = {
            "id": uuid.uuid4().hex,
            "pos": i + 1,
            "team": team,
        }
        table_row.update(stats)
        result.append(table_row)
    return result


@app.route('/current_seasons')
@cross_origin()
@json_response
def get_current_seasons():
    start_year = flask.request.args.get('start_year', 2015)
    return {
        'current_seasons': SERVICES['season'].get_current_seasons(start_year)
    }


def v2_route(app, route, *args, **kwargs):
    def decorator(fn):
        return app.route(route, *args, **kwargs)(
            cross_origin()(json_response(fn)))

    return decorator


@v2_route(app, '/v2/tables')<commit_msg>Add existingGames endpoint<commit_after>import uuid
import flask
import functools
from .service import SERVICES
from flask.ext.cors import cross_origin


DEFAULT_START_YEAR = 2015


class MyJSONEncoder(flask.json.JSONEncoder):
    def default(self, o):
        if hasattr(o, '__json__'):
            return o.__json__()
        return super(MyJSONEncoder, self).default(o)


app = flask.Flask(__name__)
app.json_encoder = MyJSONEncoder


def json_response(fn):
    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        result = fn(*args, **kwargs)
        return flask.jsonify(result)
    return wrapper


def _get_table_by_season_id(season_id, game_day):
    table = SERVICES['season'].get_current_table(season_id, game_day)
    result = []
    for i, row in enumerate(table):
        team, stats = row
        table_row = {
            "id": uuid.uuid4().hex,
            "pos": i + 1,
            "team": team,
        }
        table_row.update(stats)
        result.append(table_row)
    return result


@app.route('/current_seasons')
@cross_origin()
@json_response
def get_current_seasons():
    start_year = flask.request.args.get('start_year', 2015)
    return {
        'current_seasons': SERVICES['season'].get_current_seasons(start_year)
    }


def v2_route(app, route, *args, **kwargs):
    def decorator(fn):
        return app.route(route, *args, **kwargs)(
            cross_origin()(json_response(fn)))

    return decorator


@v2_route(app, '/v2/existingGames')
def existing_games():
    return {
        'savedGames': [
            {'id': 'abcdef'}  # TODO
        ]
    }


@v2_route(app, '/v2/tables')
{'fraction_non_alphanumeric': 0.12455630848660858, 'fraction_numerical': 0.0090351726363343, 'mean_word_length': 3.0259740259740258, 'pattern_counts': {'":': 6, '<': 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': '2163957', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1002, 'n_words': 210}