<commit_before>#!/usr/bin/env python

from contextlib import closing
from sqlite3 import connect
from os.path import isfile
from bottle import request, template, route, run

@route('/virustotal/<db>')
def virus(db):
    if not isfile(db):
        return 'The database does not exist: "%s"' % db
    with connect(db, timeout=10) as connection:
        with closing(connection.cursor()) as cursor:
            cursor.execute('SELECT detected, count(*) FROM virus GROUP BY detected ORDER BY detected')
            return template('virustotal', title=db, cursor=cursor, refresh=request.query.refresh)
<commit_msg>Improve virustotal/server.py to group virus score by range<commit_after>#!/usr/bin/env python

from contextlib import closing
from sqlite3 import connect
from os.path import isfile
from bottle import request, template, route, run

@route('/virustotal/<db>')
def virus(db):
    if not isfile(db):
        return 'The database does not exist: "%s"' % db
    with connect(db, timeout=10) as connection:
        with closing(connection.cursor()) as cursor:
            cursor.execute('SELECT count(*), CAST(0.999 + detected * 10 AS INT) || '0%' AS score'
                           'FROM virus WHERE detected >= 0 GROUP BY score ORDER BY score')
            return template('virustotal', title=db, cursor=cursor, refresh=request.query.refresh)

{'fraction_non_alphanumeric': 0.10971089696071164, 'fraction_numerical': 0.010378057820607857, 'mean_word_length': 3.5918367346938775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '1836322', 'n_tokens_mistral': 390, 'n_tokens_neox': 369, 'n_words': 137}