<commit_before>from flask import Flask, jsonify, send_file, send_from_directory

import db

app = Flask(__name__)

# Special route because "/" technically redirects to "index.html".
@app.route('/')
def index():
    return send_file('static/index.html')

@app.route('/api/total')
def total_logs():
    data = {
        'criminal_count': db.criminal_logs.count(),
        'non_criminal_count': db.non_criminal_logs.count()
    }
    return jsonify(data)

@app.route('/<path:path>')
def send_static(path):
    return send_from_directory('static', path)

if __name__ == '__main__':
    app.run(debug=True)<commit_msg>Added API with sample mongo aggregation.<commit_after>from flask import Flask, jsonify, send_file, send_from_directory

import db

app = Flask(__name__)

# Special route because "/" technically redirects to "index.html".
@app.route('/')
def index():
    return send_file('static/index.html')

@app.route('/api/total')
def total_logs():
    data = {
        'criminal_count': db.criminal_logs.count(),
        'non_criminal_count': db.non_criminal_logs.count()
    }
    return jsonify(data)

@app.route('/api/by_year')
def logs_by_year():
    pipeline = [{
        '$match': {
            'date_started': {
                '$ne': None
            }
        }
    },
    {
        '$project': {
            'year': {'$year': '$date_started'}
        }
    }, {
        '$group': {
            '_id': '$year',
            'count': {'$sum': 1}
        }
    }, {
        '$project': {
            '_id': False,
            'year': '$_id',
            'count': '$count'
        }
    }, {
        '$sort': {
            'count': 1
        }
    }]
    data = {
        'criminal_by_year': list(db.criminal_logs.aggregate(pipeline)),
        'non_criminal_by_year': list(db.non_criminal_logs.aggregate(pipeline))
    }
    return jsonify(data)

@app.route('/<path:path>')
def send_static(path):
    return send_from_directory('static', path)

if __name__ == '__main__':
    app.run(debug=True)
{'fraction_non_alphanumeric': 0.16091954022988506, 'fraction_numerical': 0.0009995002498750624, 'mean_word_length': 2.575, 'pattern_counts': {'":': 0, '<': 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': '6142079', 'n_tokens_mistral': 672, 'n_tokens_neox': 650, 'n_words': 125}