<commit_before>#!/usr/bin/env python2
import re
import time
import sys
from bottle import route, template, request, static_file, redirect, response
import config
import preferences
import structured_metrics
from backend import Backend, MetricsError
import thread
import logging

# contains all errors as key:(title,msg) items.
# will be used throughout the runtime to track all encountered errors
errors = {}

# will contain the latest data
metrics = targets_all = graphs_all = None
last_update = None

logger = logging.getLogger('app')
logger.setLevel(logging.DEBUG)
chandler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
chandler.setFormatter(formatter)
logger.addHandler(chandler)
if config.log_file:
    fhandler = logging.FileHandler(config.log_file)
    fhandler.setFormatter(formatter)
    logger.addHandler(fhandler)

logger.debug('app starting')
backend = Backend(config)
s_metrics = structured_metrics.StructuredMetrics()
logger.debug("loading plugins")
for e in s_metrics.load_plugins():
    errors['plugin_%s' % e.plugin] = (e.msg, e.underlying_error)

def build_data():
    global metrics
    global targets_all
    global graphs_all
    global last_update
    logger.debug('build_data() start')
    try:
        (metrics, targets_all, graphs_all) = backend.update_data(s_metrics)
        last_update = time.time()
        logger.debug('build_data() end ok')
    except MetricsError, e:
        errors['metrics_file'] = (e.msg, e.underlying_error)
        logger.error("[%s] %s", e.msg, e.underlying_error)
        logger.error('build_data() failed')

thread.start_new_thread(build_data, ())


def data_ready():
    return bool(metrics and targets_all and graphs_all)
<commit_msg>bugfix: fix data_ready() check, avoid bogus 'server is building..'<commit_after>#!/usr/bin/env python2
import re
import time
import sys
from bottle import route, template, request, static_file, redirect, response
import config
import preferences
import structured_metrics
from backend import Backend, MetricsError
import thread
import logging

# contains all errors as key:(title,msg) items.
# will be used throughout the runtime to track all encountered errors
errors = {}

# will contain the latest data
metrics = targets_all = graphs_all = None
last_update = None

logger = logging.getLogger('app')
logger.setLevel(logging.DEBUG)
chandler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
chandler.setFormatter(formatter)
logger.addHandler(chandler)
if config.log_file:
    fhandler = logging.FileHandler(config.log_file)
    fhandler.setFormatter(formatter)
    logger.addHandler(fhandler)

logger.debug('app starting')
backend = Backend(config)
s_metrics = structured_metrics.StructuredMetrics()
logger.debug("loading plugins")
for e in s_metrics.load_plugins():
    errors['plugin_%s' % e.plugin] = (e.msg, e.underlying_error)

def build_data():
    global metrics
    global targets_all
    global graphs_all
    global last_update
    logger.debug('build_data() start')
    try:
        (metrics, targets_all, graphs_all) = backend.update_data(s_metrics)
        last_update = time.time()
        logger.debug('build_data() end ok')
    except MetricsError, e:
        errors['metrics_file'] = (e.msg, e.underlying_error)
        logger.error("[%s] %s", e.msg, e.underlying_error)
        logger.error('build_data() failed')

thread.start_new_thread(build_data, ())


def data_ready():
    ret = bool(metrics is not None)
    logger.debug("data_ready() called, returning %s", str(ret))
    return ret

{'fraction_non_alphanumeric': 0.11046831955922864, 'fraction_numerical': 0.0005509641873278236, 'mean_word_length': 4.736176935229068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '837644', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1098, 'n_words': 290}