<commit_before>from tg import expose, validate, tmpl_context, redirect, session
from moksha.lib.base import Controller

from moksha.apps.narcissus.decorators import (
    with_moksha_socket,
    with_ui_theme,
    with_menu
)
from moksha.apps.narcissus.controllers.api import APIController
import moksha.apps.narcissus.consumers
import moksha.widgets.narcissus.widgets as widgets
import moksha.utils

import tw2.core
import tw2.rrd
import tw2.jqplugins.ui

import docutils.examples
import datetime
import os

import logging
log = logging.getLogger(__name__)

def readme_as_html():
    """ Ridiculous """
    root = '/'.join(__file__.split('/')[:-4])
    fname = root + '/README.rst'
    with open(fname, 'r') as f:
        readme = f.read()
        readme = readme.split('.. split here')[1]
        return docutils.examples.html_body(unicode(readme))

# TODO -- this should be moved to its own controller
def get_rrd_filenames(category):
    basedir = moksha.apps.narcissus.consumers.rrd_dir + '/' + category + '/'
    files = os.listdir(basedir)
    return [basedir + f for f in files]

class NarcissusController(Controller):
    """ Main controller """

    # Mounting sub-controllers
    api = APIController()

    # TODO -- these should be shared between the consumers rrd-creation
    # timespans and here.

    # Constants
    timespans = {
        'hour' : datetime.timedelta(hours=1),
        'day' : datetime.timedelta(days=1),
        'week' : datetime.timedelta(days=7),
        'month' : datetime.timedelta(days=31),
        'quarter' : datetime.timedelta(days=90),
        'year' : datetime.timedelta(days=365),
    }
    charts = {
        'history' : tw2.rrd.RRDJitAreaChart(
            id='some_id',
            offset=0,
            showAggregates=tw2.core.JSSymbol(src="""
                function(name, left, right, node, acum) {
                    return acum.toFixed(1);
                }"""),
            showLabels=False,
            Label = {
                'size': 15,
                'family': 'Arial',
                'color': 'white'
            },
            Tips = {
                'enable': True,
                'onShow' : tw2.core.JSSymbol(src="""
                (function(tip, elem) {
                    tip.innerHTML = "<b>" + elem.name + "</b>: " +
                                        elem.value.toFixed(1) +
                                        " hits per second.";
                })""")
            }
        ),
        'summary' : tw2.rrd.RRDProtoBarChart(
            id='some_id',
            p_height=700,
            p_width=900,
            # Sort by total value<commit_msg>Future note about showLabels in thejit.<commit_after>from tg import expose, validate, tmpl_context, redirect, session
from moksha.lib.base import Controller

from moksha.apps.narcissus.decorators import (
    with_moksha_socket,
    with_ui_theme,
    with_menu
)
from moksha.apps.narcissus.controllers.api import APIController
import moksha.apps.narcissus.consumers
import moksha.widgets.narcissus.widgets as widgets
import moksha.utils

import tw2.core
import tw2.rrd
import tw2.jqplugins.ui

import docutils.examples
import datetime
import os

import logging
log = logging.getLogger(__name__)

def readme_as_html():
    """ Ridiculous """
    root = '/'.join(__file__.split('/')[:-4])
    fname = root + '/README.rst'
    with open(fname, 'r') as f:
        readme = f.read()
        readme = readme.split('.. split here')[1]
        return docutils.examples.html_body(unicode(readme))

# TODO -- this should be moved to its own controller
def get_rrd_filenames(category):
    basedir = moksha.apps.narcissus.consumers.rrd_dir + '/' + category + '/'
    files = os.listdir(basedir)
    return [basedir + f for f in files]

class NarcissusController(Controller):
    """ Main controller """

    # Mounting sub-controllers
    api = APIController()

    # TODO -- these should be shared between the consumers rrd-creation
    # timespans and here.

    # Constants
    timespans = {
        'hour' : datetime.timedelta(hours=1),
        'day' : datetime.timedelta(days=1),
        'week' : datetime.timedelta(days=7),
        'month' : datetime.timedelta(days=31),
        'quarter' : datetime.timedelta(days=90),
        'year' : datetime.timedelta(days=365),
    }
    charts = {
        'history' : tw2.rrd.RRDJitAreaChart(
            id='some_id',
            offset=0,
            showAggregates=tw2.core.JSSymbol(src="""
                function(name, left, right, node, acum) {
                    return acum.toFixed(1);
                }"""),
            showLabels=False,
            # This won't work until Nico accepts my patch to thejit-proper
            #showLabels=tw2.core.JSSymbol(src="""
            #    function(name, left, right, node) {
            #        return 'hai';
            #    }"""),
            Label = {
                'size': 15,
                'family': 'Arial',
                'color': 'white'
            },
            Tips = {
                'enable': True,
                'onShow' : tw2.core.JSSymbol(src="""
                (function(tip, elem) {
                    tip.innerHTML = "<b>" + elem.name + "</b>: " +
                                        elem.value.toFixed(1) +
                                        " hits per second.";
                })""")
            }
        ),
        'summary' : tw2.rrd.RRDProtoBarChart(
            id='some_id',
            p_height=700,
            p_width=900,
            # Sort by total value
{'fraction_non_alphanumeric': 0.12244528847892928, 'fraction_numerical': 0.011032736480376198, 'mean_word_length': 1.935244161358811, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3300775', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1699, 'n_words': 359}