<commit_before>import time
import sys
import math

class ProgressBar(object):

    @staticmethod
    def create(mx, mn=0):
        ProgressBar.mn = mn
        ProgressBar.mx = mx
        ProgressBar.at = mn
        ProgressBar.start = time.time()
        ProgressBar.last = 0
        sys.stderr.write('\n')
        ProgressBar.progress(mn)

    @staticmethod
    def progress(prg=None, fin=False):
        if prg is not None:
            ProgressBar.at = prg
        else:
            ProgressBar.at = ProgressBar.at + 1
            prg = ProgressBar.at
        curt = time.time()
        if curt - ProgressBar.last < 0.5 and not fin:
            return
        ProgressBar.last = curt
        sys.stderr.write('\033[1F')
        width = 50
        prog = 1 if ProgressBar.mn == ProgressBar.mx else float(prg - ProgressBar.mn) / (ProgressBar.mx - ProgressBar.mn)
        bars = int(round(prog * width))
        bars = max(0, min(width, bars))
        sys.stderr.write('%3d%% [%s%s]' % (round(prog * 100), '#' * bars, '-' * (width - bars)))
        elapsed = curt - ProgressBar.start
        # if elapsed >= 4 and prog > 0:
        show_time = None
        if fin:
            show_time = elapsed
        elif elapsed >= 2 and prog > 0:
            show_time = max(0, elapsed / prog - elapsed)
        if show_time is not None:
            h = math.floor(show_time / 60 / 60)
            show_time -= h * 60 * 60
            m = math.floor(show_time / 60)
            show_time -= m * 60
            s = math.floor(show_time)
            sys.stderr.write(' %02d:%02d:%02d' % (h,m,s))
        sys.stderr.write('\n')

    @staticmethod
    def finish():
        ProgressBar.progress(ProgressBar.mx, fin=True)

<commit_msg>Make progressbar work on Mac<commit_after>import time
import sys
import math

class ProgressBar(object):

    @staticmethod
    def create(mx, mn=0):
        ProgressBar.mn = mn
        ProgressBar.mx = mx
        ProgressBar.at = mn
        ProgressBar.start = time.time()
        ProgressBar.last = 0
        sys.stderr.write('\n')
        ProgressBar.progress(mn)

    @staticmethod
    def progress(prg=None, fin=False):
        if prg is not None:
            ProgressBar.at = prg
        else:
            ProgressBar.at = ProgressBar.at + 1
            prg = ProgressBar.at
        curt = time.time()
        if curt - ProgressBar.last < 0.5 and not fin:
            return
        ProgressBar.last = curt
        # sys.stderr.write('\033[1F')
        sys.stderr.write('\r')
        width = 50
        prog = 1 if ProgressBar.mn == ProgressBar.mx else float(prg - ProgressBar.mn) / (ProgressBar.mx - ProgressBar.mn)
        bars = int(round(prog * width))
        bars = max(0, min(width, bars))
        sys.stderr.write('%3d%% [%s%s] ' % (round(prog * 100), '#' * bars, '-' * (width - bars)))
        elapsed = curt - ProgressBar.start
        # if elapsed >= 4 and prog > 0:
        show_time = None
        if fin:
            show_time = elapsed
        elif elapsed >= 2 and prog > 0:
            show_time = max(0, elapsed / prog - elapsed)
        if show_time is not None:
            h = math.floor(show_time / 60 / 60)
            show_time -= h * 60 * 60
            m = math.floor(show_time / 60)
            show_time -= m * 60
            s = math.floor(show_time)
            sys.stderr.write(' %02d:%02d:%02d' % (h,m,s))
        # sys.stderr.write('\n')

    @staticmethod
    def finish():
        ProgressBar.progress(ProgressBar.mx, fin=True)
        sys.stderr.write('\n')


{'fraction_non_alphanumeric': 0.12329545454545454, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 1.7550860719874803, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6689990', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1099, 'n_words': 278}