<commit_before>import os
import re

from flask import render_template, send_from_directory

from perfreports import app
from perfreports import data
from perfreports.constants import LABELS
from perfreports.plotter import plot


@app.route('/')
def index():
    snapshots = data.get_all_snapshots()
    return render_template('index.html', snapshots=snapshots)


@app.route('/favicon.ico')
def favicon():
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'favicon.ico')


def generate_filename(snapshot, source, metric):
    filename = '_'.join((snapshot, source, metric))
    filename = re.sub(r'[\[\]/\\:\*\?\"<>\|& ]', '', filename)
    return 'perfreports/static/charts/{}.png'.format(filename)


@app.route('/<snapshot>')
def report(snapshot):
    meta = []

    for data_path in data.get_data_paths(snapshot=snapshot):
        source, metric = data_path.split(':')
        fname = generate_filename(snapshot, source, metric)
        series = data.get_series(snapshot=snapshot, data_path=data_path)
        label = LABELS.get(metric, metric)

        plot(series=series, ylabel=label, fname=fname)

        if label == metric:
            chart_title = ' : '.join((source, metric))
        else:
            chart_title = ' : '.join((source, metric, label))
        meta.append((chart_title, fname.replace('perfreports', '')))

    return render_template('report.html', meta=meta)<commit_msg>Only show label in chart title<commit_after>import os
import re

from flask import render_template, send_from_directory

from perfreports import app
from perfreports import data
from perfreports.constants import LABELS
from perfreports.plotter import plot


@app.route('/')
def index():
    snapshots = data.get_all_snapshots()
    return render_template('index.html', snapshots=snapshots)


@app.route('/favicon.ico')
def favicon():
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'favicon.ico')


def generate_filename(snapshot, source, metric):
    filename = '_'.join((snapshot, source, metric))
    filename = re.sub(r'[\[\]/\\:\*\?\"<>\|& ]', '', filename)
    return 'perfreports/static/charts/{}.png'.format(filename)


@app.route('/<snapshot>')
def report(snapshot):
    meta = []

    for data_path in data.get_data_paths(snapshot=snapshot):
        source, metric = data_path.split(':')
        fname = generate_filename(snapshot, source, metric)
        series = data.get_series(snapshot=snapshot, data_path=data_path)
        label = LABELS.get(metric, metric)

        plot(series=series, ylabel=label, fname=fname)

        chart_title = ' : '.join((source, label))
        meta.append((chart_title, fname.replace('perfreports', '')))

    return render_template('report.html', meta=meta)
{'fraction_non_alphanumeric': 0.14229671897289586, 'fraction_numerical': 0.0, 'mean_word_length': 3.6672212978369383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5070171', 'n_tokens_mistral': 870, 'n_tokens_neox': 864, 'n_words': 182}