<commit_before>#!/usr/bin/python
import sys
import os
import sqlite3

def make_table(database):
    c = sqlite3.connect(database)
    res = c.execute(('select command_record.id, testname, hub, runs, errors, fails, '
                     'timeouts, exitcode, stdout from parsed_command_record join '
                     'command_record on parsed_command_record.id=command_record.id ')).fetchall()
    table = {} # testname -> hub -> test_result (runs, errors, fails, timeouts)
    hub_stats = {} # hub -> cumulative test_result
    tests = set()
    for id, testname, hub, runs, errors, fails, timeouts, exitcode, stdout in res:
        tests.add(testname)
        test_result = TestResult(runs, errors, fails, timeouts, exitcode, id, stdout)
        table.setdefault(testname, {})[hub] = test_result
        hub_stats.setdefault(hub, TestResult(0,0,0,0)).__iadd__(test_result)
    hubs = hub_stats.items()
    hubs.sort(key=lambda t: t[1].passed, reverse=True)
    return table, [x[0] for x in hubs], sorted(tests), hub_stats

class TestResult:

    def __init__(self, runs, errors, fails, timeouts, exitcode=None, id=None, output=None):
        self.runs = runs
        self.errors = errors
        self.fails = fails
        self.timeouts = timeouts
        self.exitcode = exitcode
        self.id = id
        self.output = output

    @property
    def passed(self):
        return self.runs - self.errors - self.fails

    def __iadd__(self, other):
        self.runs += other.runs
        self.errors += other.errors
        self.fails += other.fails
        self.timeouts += other.timeouts
        if self.exitcode != other.exitcode:
            self.exitcode = None
        self.id = None
        self.output = None

    def color(self):
        if self.timeouts or self.exitcode in [7, 9, 10]:
            return 'red'
        elif self.errors or self.fails or self.exitcode:
            return 'yellow'
        else:
            return '"#72ff75"'

    def text(self):
        errors = []
        if self.fails:
            errors += ['%s failed' % self.fails]
        if self.errors:
            errors += ['%s raised' % self.errors]
        if self.timeouts:
            errors += ['%s timeout' % self.timeouts]
        if not errors:
            if self.exitcode in [7, 9, 10]:
                errors += ['TIMEOUT']
            if self.exitcode:
                errors += ['exitcode=%s' % self.exitcode]
            if self.output is not None:
                output = self.output.lower()
                warning = output.count('warning')
                if warning:
                    errors += ['%s warnings' % warning]
                tracebacks = output.count('traceback')
                if tracebacks:
                    errors += ['%s tracebacks' % tracebacks]
        return '\n'.join(["%s passed" % self.passed] + errors)
       
    def format(self):
        text = self.text().replace('\n', '<br>\n')
        if self.id is not None:
            text = '<a href="%s.txt">%s</a>' % (self.id, text)
        return '<td align=center bgcolor=%s>%s</td>' % (self.color(), text)

def format_table(table, hubs, tests, hub_stats):<commit_msg>use &nbsp; for better formatting<commit_after>#!/usr/bin/python
import sys
import os
import sqlite3

def make_table(database):
    c = sqlite3.connect(database)
    res = c.execute(('select command_record.id, testname, hub, runs, errors, fails, '
                     'timeouts, exitcode, stdout from parsed_command_record join '
                     'command_record on parsed_command_record.id=command_record.id ')).fetchall()
    table = {} # testname -> hub -> test_result (runs, errors, fails, timeouts)
    hub_stats = {} # hub -> cumulative test_result
    tests = set()
    for id, testname, hub, runs, errors, fails, timeouts, exitcode, stdout in res:
        tests.add(testname)
        test_result = TestResult(runs, errors, fails, timeouts, exitcode, id, stdout)
        table.setdefault(testname, {})[hub] = test_result
        hub_stats.setdefault(hub, TestResult(0,0,0,0)).__iadd__(test_result)
    hubs = hub_stats.items()
    hubs.sort(key=lambda t: t[1].passed, reverse=True)
    return table, [x[0] for x in hubs], sorted(tests), hub_stats

class TestResult:

    def __init__(self, runs, errors, fails, timeouts, exitcode=None, id=None, output=None):
        self.runs = runs
        self.errors = errors
        self.fails = fails
        self.timeouts = timeouts
        self.exitcode = exitcode
        self.id = id
        self.output = output

    @property
    def passed(self):
        return self.runs - self.errors - self.fails

    def __iadd__(self, other):
        self.runs += other.runs
        self.errors += other.errors
        self.fails += other.fails
        self.timeouts += other.timeouts
        if self.exitcode != other.exitcode:
            self.exitcode = None
        self.id = None
        self.output = None

    def color(self):
        if self.timeouts or self.exitcode in [7, 9, 10]:
            return 'red'
        elif self.errors or self.fails or self.exitcode:
            return 'yellow'
        else:
            return '"#72ff75"'

    def text(self):
        errors = []
        if self.fails:
            errors += ['%s failed' % self.fails]
        if self.errors:
            errors += ['%s raised' % self.errors]
        if self.timeouts:
            errors += ['%s timeout' % self.timeouts]
        if not errors:
            if self.exitcode in [7, 9, 10]:
                errors += ['TIMEOUT']
            if self.exitcode:
                errors += ['exitcode=%s' % self.exitcode]
            if self.output is not None:
                output = self.output.lower()
                warning = output.count('warning')
                if warning:
                    errors += ['%s warnings' % warning]
                tracebacks = output.count('traceback')
                if tracebacks:
                    errors += ['%s tracebacks' % tracebacks]
        return '\n'.join(["%s passed" % self.passed] + errors).replace(' ', '&nbsp;')
       
    def format(self):
        text = self.text().replace('\n', '<br>\n')
        if self.id is not None:
            text = '<a href="%s.txt">%s</a>' % (self.id, text)
        return '<td align=center bgcolor=%s>%s</td>' % (self.color(), text)

def format_table(table, hubs, tests, hub_stats):
{'fraction_non_alphanumeric': 0.12759270898805783, 'fraction_numerical': 0.006285355122564425, 'mean_word_length': 2.0571565802113354, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '4983630', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1900, 'n_words': 504}