<commit_before># <NAME> <<EMAIL>>
from ..mkdir_p import mkdir_p
import os
from ReadCounter import ReadCounter

##____________________________________________________________________________||
class TblCounter(object):
    def __init__(self, outPath, columnNames, analyzerName, fileName, levels):
        self._outPath = outPath
        self.analyzerName = analyzerName
        self.fileName = fileName
        self.levels = levels
        self.columnNames = columnNames
        self._readCounter = ReadCounter()
        self._rows = [['component'] + list(columnNames)]

    def begin(self): pass

    def read(self, component):
        path = os.path.join(getattr(component, self.analyzerName).path, self.fileName)
        counter = self._readCounter(path)
        row = [component.name]
        for level, column in zip(self.levels, self.columnNames):
            row.append(counter[level]['count'])
        self._rows.append(row)

    def end(self):
        transposed = [[r[i] for r in self._rows] for i in range(len(self._rows[0]))]
        transposed = [[int(e) if isinstance(e, float) and e.is_integer() else e for e in r] for r in transposed]
        transposed = [[str(e) for e in r] for r in transposed]
        columnWidths = [max([len(e) for e in r]) for r in transposed]
        format = " {:>" + "s} {:>".join([str(e) for e in columnWidths]) + "s}"
        f = self._open(self._outPath)
        for row in zip(*transposed):
            f.write(format.format(*row))
            f.write("\n")
        self._close(f)

    def _open(self, path):
        mkdir_p(os.path.dirname(path))
        return open(path, 'w')

    def _close(self, file): file.close()

##____________________________________________________________________________||<commit_msg>use listToAlignedText in TblCounter.py<commit_after># <NAME> <<EMAIL>>
from ..mkdir_p import mkdir_p
from ..listToAlignedText import listToAlignedText
import os
from ReadCounter import ReadCounter

##____________________________________________________________________________||
class TblCounter(object):
    def __init__(self, outPath, columnNames, analyzerName, fileName, levels):
        self._outPath = outPath
        self.analyzerName = analyzerName
        self.fileName = fileName
        self.levels = levels
        self.columnNames = columnNames
        self._readCounter = ReadCounter()
        self._rows = [['component'] + list(columnNames)]

    def begin(self): pass

    def read(self, component):
        path = os.path.join(getattr(component, self.analyzerName).path, self.fileName)
        counter = self._readCounter(path)
        row = [component.name]
        for level, column in zip(self.levels, self.columnNames):
            row.append(counter[level]['count'])
        self._rows.append(row)

    def end(self):
        f = self._open(self._outPath)
        f.write(listToAlignedText(self._rows))
        self._close(f)

    def _open(self, path):
        mkdir_p(os.path.dirname(path))
        return open(path, 'w')

    def _close(self, file): file.close()

##____________________________________________________________________________||
{'fraction_non_alphanumeric': 0.1170076726342711, 'fraction_numerical': 0.00031969309462915604, 'mean_word_length': 3.2056451612903225, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2538626', 'n_tokens_mistral': 887, 'n_tokens_neox': 871, 'n_words': 219}