<commit_before>"""A separate Flask app that serves fake endpoints for demo purposes."""

# -*- coding: utf-8 -*-

import json
import os
from random import randrange as rr
from random import choice, random
import time

from flask import (
    Flask,
    abort,
)
from flask.ext.cors import CORS
from flask.ext.cors import cross_origin

app = Flask(__name__)
CORS(app)
app.config['SECRET_KEY'] = 'NOTSECURELOL'
app.debug = True

cwd = os.getcwd()


@cross_origin()
@app.route('/timeline/')
def timeline():
    """Fake endpoint."""
    with open('{}/examples/timeline3.json'.format(cwd), 'r') as timelinejson:
        return timelinejson.read()
    return json.dumps({})


@app.route('/dtable', methods=['GET'])
def dtable():
    """Fake endpoint."""
    with open('{}/examples/dtable.json'.format(os.getcwd()), 'r') as djson:
        return djson.read()
    return json.dumps({})


@cross_origin()
@app.route('/deadend/')
def test_die():
    """Fake endpoint that ends in a random 50x error."""
    # Simulate slow connection
    time.sleep(random())
    abort(choice([500, 501, 502, 503, 504]))


@cross_origin()
@app.route('/test4/')
def test4():
    """Fake endpoint."""
    # Simulate slow connection
    time.sleep(random())
    return json.dumps({
        "name": "foo",
        "children": [{
            "name": '---foo---', "size": i
        } for i in range(0, 30)]
    })


@cross_origin()
@app.route('/test3/')
def test3():
    """Fake endpoint."""
    # Simulate slow connection
    time.sleep(random())
    return json.dumps({
        "name": "foo",
        "children": [{
            "name": '---foo---', "size": i
        } for i in range(0, 30)]
    })


@cross_origin()
@app.route('/test1/')
def test1():
    """Fake endpoint."""
    # Simulate slow connection
    time.sleep(random())
    return json.dumps([
        ['data1'] + [rr(0, 100) for _ in range(12)],
        ['data2'] + [rr(0, 100) for _ in range(12)],
        ['data3'] + [rr(0, 100) for _ in range(12)],
        ['data4'] + [rr(0, 100) for _ in range(12)],
    ])


@cross_origin()<commit_msg>Clean up old endpoints, add support for venn.js example.<commit_after>"""A separate Flask app that serves fake endpoints for demo purposes."""

# -*- coding: utf-8 -*-

import json
import os
from random import randrange as rr
from random import choice, random
import time

from flask import (
    Flask,
    abort,
)
from flask.ext.cors import CORS
from flask.ext.cors import cross_origin

app = Flask(__name__)
CORS(app)
app.config['SECRET_KEY'] = 'NOTSECURELOL'
app.debug = True

cwd = os.getcwd()


@cross_origin()
@app.route('/timeline/')
def timeline():
    """Fake endpoint."""
    with open('{}/examples/timeline3.json'.format(cwd), 'r') as timelinejson:
        return timelinejson.read()
    return json.dumps({})


@app.route('/dtable', methods=['GET'])
def dtable():
    """Fake endpoint."""
    with open('{}/examples/dtable.json'.format(os.getcwd()), 'r') as djson:
        return djson.read()
    return json.dumps({})


@cross_origin()
@app.route('/deadend/')
def test_die():
    """Fake endpoint that ends in a random 50x error."""
    # Simulate slow connection
    time.sleep(random())
    abort(choice([500, 501, 502, 503, 504]))


@cross_origin()
@app.route('/venn/')
def test_venn():
    """Fake endpoint."""
    data = [
        {'sets': ['A'], 'size': rr(10, 100)},
        {'sets': ['B'], 'size': rr(10, 100)},
        {'sets': ['C'], 'size': rr(10, 100)},
        {'sets': ['A', 'B'], 'size': rr(10, 100)},
        {'sets': ['A', 'B', 'C'], 'size': rr(10, 100)},
    ]
    return json.dumps(data)


@cross_origin()
@app.route('/test1/')
def test1():
    """Fake endpoint."""
    # Simulate slow connection
    time.sleep(random())
    return json.dumps([
        ['data1'] + [rr(0, 100) for _ in range(12)],
        ['data2'] + [rr(0, 100) for _ in range(12)],
        ['data3'] + [rr(0, 100) for _ in range(12)],
        ['data4'] + [rr(0, 100) for _ in range(12)],
    ])


@cross_origin()
{'fraction_non_alphanumeric': 0.19598997493734335, 'fraction_numerical': 0.03333333333333333, 'mean_word_length': 3.0724489795918366, 'pattern_counts': {'":': 8, '<': 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': '1295768', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1361, 'n_words': 374}