<commit_before># -*- coding: utf-8 -*-

from flask import Blueprint, abort, render_template
import itertools
from sqlalchemy.orm.exc import NoResultFound

from .db import session
from ..work import Credit, Work

ontology = Blueprint('ontology', __name__,
                     template_folder='templates/ontology/')


@ontology.route('/')
def index():
    return 'Hello cliche!'


@ontology.route('/work/')
def list_():
    names = [
        name
        for name, in session.query(Work.name).order_by(Work.name)
    ]
    return render_template(
        'work_list.html',
        work_list=names
    )


@ontology.route('/work/<path:title>/')
def page(title):
    try:
        work = session.query(Work).filter_by(name=title).one()
    except NoResultFound:
        abort(404)
    credits = session.query(Credit) \
                     .filter_by(work=work) \
                     .order_by(Credit.team_id)
    grouped_credits = [
        (team_id, list(group))
        for team_id, group in itertools.groupby(credits, lambda c: c.team_id)
    ]
    return render_template(
        'page_work.html',
        title=title,
        work=work,
        grouped_credits=grouped_credits
    )<commit_msg>add docstrings<commit_after># -*- coding: utf-8 -*-

from flask import Blueprint, abort, render_template
import itertools
from sqlalchemy.orm.exc import NoResultFound

from .db import session
from ..work import Credit, Work

ontology = Blueprint('ontology', __name__,
                     template_folder='templates/ontology/')


@ontology.route('/')
def index():
    """The root page. Currently no contents preserved yet."""
    return 'Hello cliche!'


@ontology.route('/work/')
def list_():
    """A list of works."""
    names = [
        name
        for name, in session.query(Work.name).order_by(Work.name)
    ]
    return render_template(
        'work_list.html',
        work_list=names
    )


@ontology.route('/work/<path:title>/')
def page(title):
    """More detailed data of a work."""
    try:
        work = session.query(Work).filter_by(name=title).one()
    except NoResultFound:
        abort(404)
    credits = session.query(Credit) \
                     .filter_by(work=work) \
                     .order_by(Credit.team_id)
    grouped_credits = [
        (team_id, list(group))
        for team_id, group in itertools.groupby(credits, lambda c: c.team_id)
    ]
    return render_template(
        'page_work.html',
        title=title,
        work=work,
        grouped_credits=grouped_credits
    )
{'fraction_non_alphanumeric': 0.12361331220285261, 'fraction_numerical': 0.003169572107765452, 'mean_word_length': 2.4779614325068873, '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': '7020562', 'n_tokens_mistral': 802, 'n_tokens_neox': 784, 'n_words': 173}