<commit_before>import config
import glob
import flask
import os
import json

app = flask.Flask(__name__)

@app.errorhandler(404)
def not_found(error):
    return flask.make_response(flask.jsonify( { 'error': 'Not found' } ), 404)

@app.route("/versions")
def get_recommended_versions():
    return flask.jsonify({"versions" : config.recommended_versions})

@app.route("/results", methods=['POST'])
def submit_result():
    result = flask.request.json
    if not result or "timestamp" not in result:
        flask.abort(400)

    file_name = "result-%s.json" % (result["timestamp"])

    #XXX: overwrite file if exists?
    #XXX: validate file?
    with open(file_name, "w") as result_fh:
        json.dump(result, result_fh)

    return flask.jsonify({"status":"success"}), 201
    
@app.route("/results")
def get_result():
    results = {}

    #XXX: cache the list of results?
    # look in results directory
    for path in glob.glob(os.path.join(config.results_dir,'[!_]*.json')):
        # get name of file and path
        file_name, ext = os.path.splitext(os.path.basename(path))
        # read the result file
        with open(path) as result_file:
            try:
                results[file_name] = json.load(result_file)
            except Exception, e:
                print "Couldn't open file - %s" % (path)

    return flask.jsonify({"results" : results})

@app.route("/experiments")
@app.route("/experiments/<name>")
def get_experiment_list(name=None):
    experiments = {}

    # look for experiments in experiments directory
    for path in glob.glob(os.path.join(config.experiments_dir,'[!_]*.py')):<commit_msg>Store the results in the results_dir<commit_after>import config
import glob
import flask
import os
import json

app = flask.Flask(__name__)

@app.errorhandler(404)
def not_found(error):
    return flask.make_response(flask.jsonify( { 'error': 'Not found' } ), 404)

@app.route("/versions")
def get_recommended_versions():
    return flask.jsonify({"versions" : config.recommended_versions})

@app.route("/results", methods=['POST'])
def submit_result():
    result = flask.request.json
    if not result or "timestamp" not in result:
        flask.abort(400)

    file_name = "result-%s.json" % (result["timestamp"])
    file_path = os.path.join(config.results_dir, file_name)

    #XXX: overwrite file if exists?
    #XXX: validate file?
    with open(file_path, "w") as result_fh:
        json.dump(result, result_fh)

    return flask.jsonify({"status":"success"}), 201
    
@app.route("/results")
def get_result():
    results = {}

    #XXX: cache the list of results?
    # look in results directory
    for path in glob.glob(os.path.join(config.results_dir,'[!_]*.json')):
        # get name of file and path
        file_name, ext = os.path.splitext(os.path.basename(path))
        # read the result file
        with open(path) as result_file:
            try:
                results[file_name] = json.load(result_file)
            except Exception, e:
                print "Couldn't open file - %s" % (path)

    return flask.jsonify({"results" : results})

@app.route("/experiments")
@app.route("/experiments/<name>")
def get_experiment_list(name=None):
    experiments = {}

    # look for experiments in experiments directory
    for path in glob.glob(os.path.join(config.experiments_dir,'[!_]*.py')):
{'fraction_non_alphanumeric': 0.138250223947447, 'fraction_numerical': 0.007166318303971335, 'mean_word_length': 3.345006485084306, 'pattern_counts': {'":': 2, '<': 5, '<?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': '7262253', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1041, 'n_words': 263}