<commit_before>import datetime
import json
import logging
import os
import platform
import time

from flask import Flask, abort, request
from statsd import StatsClient

from . import settings
from .whisperdb import Whisper


logging.basicConfig(**settings.logging)
logger = logging.getLogger(__name__)


host = platform.node().replace('.', '_')
statsd = StatsClient('localhost', 48125, prefix="%s.metrickeep" % host)


app = Flask(__name__)


@app.route('/')
def root():
    return str(int(time.time()))


def find_whispers():
    whispers = []
    if not os.path.isdir(settings.whisper_path):
        return whispers
    
    # We're going to remove this prefix from results
    prefix = "%s/" % settings.whisper_path
    
    for root, _, files in os.walk(settings.whisper_path):
        root = root.replace(prefix, '')
        for name in files:
            # Drop the extension
            name = name.rsplit('.', 1)[0]
            path = os.path.join(root, name)
            whispers.append(path)
    
    return whispers


@app.route('/metrics', methods=['GET',])
def fetch():
    response = {'metrics': [w.replace('/','.') for w in find_whispers()]}
    return json.dumps(response)

<commit_msg>Add simple report of app version at runtime<commit_after>import datetime
import json
import logging
import os
import platform
import subprocess
import time

from flask import Flask, abort, request
from statsd import StatsClient

from . import settings
from .whisperdb import Whisper


logging.basicConfig(**settings.logging)
logger = logging.getLogger(__name__)


host = platform.node().replace('.', '_')
statsd = StatsClient('localhost', 48125, prefix="%s.metrickeep" % host)


app = Flask(__name__)


@app.route('/')
def root():
    return str(int(time.time()))


@app.route('/revision')
def gitrevision():
    process = subprocess.Popen('git log -1'.split(), stdout=subprocess.PIPE)
    git_info, _ = process.communicate()
    return git_info.replace('\n','<br />')


def find_whispers():
    whispers = []
    if not os.path.isdir(settings.whisper_path):
        return whispers
    
    # We're going to remove this prefix from results
    prefix = "%s/" % settings.whisper_path
    
    for root, _, files in os.walk(settings.whisper_path):
        root = root.replace(prefix, '')
        for name in files:
            # Drop the extension
            name = name.rsplit('.', 1)[0]
            path = os.path.join(root, name)
            whispers.append(path)
    
    return whispers


@app.route('/metrics', methods=['GET',])
def fetch():
    response = {'metrics': [w.replace('/','.') for w in find_whispers()]}
    return json.dumps(response)


{'fraction_non_alphanumeric': 0.13473842679713963, 'fraction_numerical': 0.005645464809936018, 'mean_word_length': 3.232484076433121, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '560863', 'n_tokens_mistral': 841, 'n_tokens_neox': 807, 'n_words': 223}