<commit_before>from flask import Flask, abort, url_for
import json
import models
import database

app = Flask(__name__)
app.config.from_pyfile('config.py')

@app.route("/packages/")
def packages():
    packages = database.db_session.query(models.Package).all()
    package_links = map(
        lambda package: {"link": url_for( "package", package_name=package.package_name)},
        packages)
    return json.dumps(package_links)

@app.route('/packages/<package_name>')
def package(package_name):
    package = database.db_session.query(models.Package).filter(models.Package.package_name == package_name).first()
    if package == None:
        abort(404)
    else:
        return json.dumps(package.as_dict())

if __name__ == '__main__':
    app.debug = True
    database.init_db()
    app.run()<commit_msg>Jen - added fake version of a test results report<commit_after>from flask import Flask, abort, url_for, jsonify
import json
import models
import database
import random

class AggregatedTestResults:
   def make_division(self,i):
       return [i* self.divisions, (i+1) * self.divisions]
   def x_axis(self):
     return map(self.make_division, range(self.n))
   def __init__(self, n):
    self.n = n
    self.divisions = 100.0/n
   def fake_data(self):
       return map (lambda i: random.randint(10, 200), range(self.n))
   def create_report(self):
    return {"data" : self.fake_data(), "x_axis": self.x_axis()}


app = Flask(__name__)
app.config.from_pyfile('config.py')


def aggregated_test_results():
    return AggregatedTestResults(10).create_report()

@app.route("/packages/")
def packages():
    packages = database.db_session.query(models.Package).all()
    package_links = map(
        lambda package: {"link": url_for( "package", package_name=package.package_name)},
        packages)

    return jsonify(packages=package_links,
                   aggreated_test_results= aggregated_test_results())

@app.route('/packages/<package_name>')
def package(package_name):
    package = database.db_session.query(models.Package).filter(models.Package.package_name == package_name).first()
    if package == None:
        abort(404)
    else:
        return jsonify(package.as_dict())

if __name__ == '__main__':
    app.debug = True
    database.init_db()
    app.run()
{'fraction_non_alphanumeric': 0.1305300043802015, 'fraction_numerical': 0.00788436268068331, 'mean_word_length': 3.965217391304348, 'pattern_counts': {'":': 3, '<': 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': '6102587', 'n_tokens_mistral': 741, 'n_tokens_neox': 719, 'n_words': 155}