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

import sqlite3

conn = sqlite3.connect('yalcov')

class yalcov:
    def __init__(self, logfile):
        self.logfn = logfile
        logf = open(self.logfn, "r")
        parse_log(logf)
        report()

    def parse_log(self, logf):
        c = conn.cursor()

        # Create table
        c.execute('''CREATE TABLE cov
                       (filepath text, line real, hitcnt real)''')

        for line in logf.readlines():
            lineno = line.split(':')[1]
            path = line.split(':')[0]

            c.execute("SELECT hitcnt FROM cov WHERE filepath = '%s' AND line = '%d'" % path, lineno)
            row = cur.fetchone()
            if row is None:
                # Insert a row of data
                c.execute("INSERT INTO cov VALUES (%s, %d, 1)" % path, lineno)
            else:
                c.execute("UPDATE cov SET hitcnt = hitcnt + 1 WHERE filepath = '%s' AND line = '%d'" % path, lineno)

            # Save (commit) the changes
            conn.commit()

        # We can also close the connection if we are done with it.
        # Just be sure any changes have been committed or they will be lost.
        # conn.close()

    def report(self):
        c = conn.cursor()

        c.execute('''SELECT filepath FROM cov''')
        rows = c.fetchall()
        files = []
        for row in rows:
            files.append(row[0])

        for f in files:
            c.execute("SELECT * FROM cov WHERE filepath = '%s' ORDER BY line" % f)
            filecov = c.fetchall()

            linecov = {}
            for row in filecov:
                linecov[row[1]] = row[2]

            lineno = 1
            srcfile = open(f, "r")
            for line in srcfile:
                hitcnt = 0
                if lineno in linecov:
                    hitcnt = linecov[lineno]
                print '%4d|%4d|%s' % lineno, hitcnt, line

            srcfile.close()

def main(argv):
    yc = yalcov(argv[0])

if __name__ == '__main__':
    main(sys.argv[1:])<commit_msg>first working version<commit_after>#!/usr/bin/env python

from __future__ import print_function
import sys
import os
import sqlite3

try:
    os.remove('yalcov.db')
except OSError:
    pass

conn = sqlite3.connect('yalcov.db')


class yalcov:
    def __init__(self, logfile):
        self.logfn = logfile
        logf = open(self.logfn, "r")
        self.parse_log(logf)
        self.report()

    def parse_log(self, logf):
        c = conn.cursor()

        # Create table
        c.execute('''CREATE TABLE cov
                       (filepath text, line int, hitcnt int)''')

        for line in logf.readlines():
            lineno = int(line.split(':')[1])
            path = line.split(':')[0]

            c.execute("SELECT hitcnt FROM cov WHERE filepath = '%s' AND line = '%d'" % (path, lineno))
            row = c.fetchone()
            if row is None:
                # Insert a row of data
                c.execute("INSERT INTO cov VALUES (?, ?, 1)", (path, lineno))
            else:
                c.execute("UPDATE cov SET hitcnt = hitcnt + 1 WHERE filepath = '%s' AND line = '%d'" % (path, lineno))

            # Save (commit) the changes
            conn.commit()

        # We can also close the connection if we are done with it.
        # Just be sure any changes have been committed or they will be lost.
        # conn.close()

    def report(self):
        c = conn.cursor()

        c.execute('''SELECT filepath FROM cov''')
        rows = c.fetchall()
        files = []
        for row in rows:
            files.append(row[0])

        for f in files:
            c.execute("SELECT * FROM cov WHERE filepath = '%s' ORDER BY line" % f)
            filecov = c.fetchall()

            linecov = {}
            for row in filecov:
                linecov[row[1]] = row[2]

            lineno = 1
            srcfile = open(f, "r")
            for line in srcfile:
                hitcnt = 0
                if lineno in linecov:
                    hitcnt = linecov[lineno]
                print('%4d|%4d|%s' % (lineno, hitcnt, line), end='')
                lineno = lineno + 1

            srcfile.close()


def main(argv):
    yalcov(argv[0])

if __name__ == '__main__':
    main(sys.argv[1:])
{'fraction_non_alphanumeric': 0.12065727699530517, 'fraction_numerical': 0.00727699530516432, 'mean_word_length': 1.620541205412054, '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': '4835891', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1267, 'n_words': 394}