<commit_before># -*- coding: utf-8 -*-
# Copyright 2016 <NAME>. All rights reserved.
# Use of this source code is governed by a MIT-style license that can be found
# in the LICENSE file.

from flask import jsonify, Blueprint, abort, request
from datetime import datetime, timedelta
from api import db
from .models import Visit
from .forms import VisitForm

visits = Blueprint('visits', __name__)

@visits.route('/', methods=['POST'])
def insert():
    """Insert a visit"""
    form = VisitForm(csrf_enabled=False)

    if form.validate():
        visit = Visit(request.form.get('start_time'), request.form.get('end_time'))
        db.session.add(visit)
        db.session.commit()
        return jsonify(), 204 # Insert successful, return no content

    return jsonify(errors=form.errors, success=False), 400

@visits.route('/')
def all():
    """Get all visits"""
    visits = Visit.query.all()
    # Make them JSON serializeable
    visits = [visit.serialize for visit in visits]

    return jsonify(data=visits, success=True)

@visits.route('/recent')
def recent():
    """Get all visits from the past day"""
    interval = datetime.now() - timedelta(days=1)
    visits = Visit.query.filter(Visit.start_time >= interval).order_by(Visit.start_time).all()

    return jsonify(data=visits, success=True)

@visits.route('/<int:id>')
def visit(id):
    """Get a visit by id"""
    visit = Visit.query.get(id)

    if visit:
        return jsonify(data=visit, success=True)

    abort(404, 'Visit "{}" not found'.format(id))<commit_msg>Serialize visits on all endpoints<commit_after># -*- coding: utf-8 -*-
# Copyright 2016 <NAME>. All rights reserved.
# Use of this source code is governed by a MIT-style license that can be found
# in the LICENSE file.

from flask import jsonify, Blueprint, abort, request
from datetime import datetime, timedelta
from api import db
from .models import Visit
from .forms import VisitForm

visits = Blueprint('visits', __name__)

@visits.route('/', methods=['POST'])
def insert():
    """Insert a visit"""
    form = VisitForm(csrf_enabled=False)

    if form.validate():
        visit = Visit(request.form.get('start_time'), request.form.get('end_time'))
        db.session.add(visit)
        db.session.commit()
        return jsonify(), 204 # Insert successful, return no content

    return jsonify(errors=form.errors, success=False), 400

@visits.route('/')
def all():
    """Get all visits"""
    visits = Visit.query.all()
    # Make them JSON serializeable
    visits = [visit.serialize for visit in visits]

    return jsonify(data=visits, success=True)

@visits.route('/recent')
def recent():
    """Get all visits from the past day"""
    interval = datetime.now() - timedelta(days=1)
    visits = Visit.query.filter(Visit.start_time >= interval).order_by(Visit.start_time).all()
    visits = [visit.serialize for visit in visits]

    return jsonify(data=visits, success=True)

@visits.route('/<int:id>')
def visit(id):
    """Get a visit by id"""
    visit = Visit.query.get(id)

    if visit:
        return jsonify(data=visit.serialize, success=True)

    abort(404, 'Visit "{}" not found'.format(id))
{'fraction_non_alphanumeric': 0.13877421403620196, 'fraction_numerical': 0.00952683391552874, 'mean_word_length': 3.7583081570996977, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1260655', 'n_tokens_mistral': 989, 'n_tokens_neox': 945, 'n_words': 293}