<commit_before>import sys, math, time

import numpy as np
from collections import OrderedDict

from nose.plugins.skip import SkipTest

try:
    import IPython
    from IPython.core.display import clear_output
except:
    clear_output = None
    raise SkipTest("IPython extension requires IPython >= 0.12")
from IPython.display import display
from IPython.core.pylabtools import print_figure
try:
    from IPython.html import widgets
    from IPython.html.widgets import FloatSliderWidget
except:
    widgets = None
    FloatSliderWidget = object

try:
    import mpld3
except:
    mpld3 = None

# IPython 0.13 does not have version_info
ipython2 = hasattr(IPython, 'version_info') and (IPython.version_info[0] == 2)

import param

from .. import GridLayout, NdMapping
from ..views import Layout, Overlay, View
from ..sheetviews import CoordinateGrid
from ..plots import GridLayoutPlot, Plot
from .magics import ViewMagic


class ProgressBar(param.Parameterized):
    """
    A simple text progress bar suitable for both the IPython notebook
    and the IPython interactive prompt.
    """

    display = param.Boolean(default=True, doc="""
       Class parameter to disable the progress bar display. Disabling
       the progress bar can be useful e.g. when running
       non-interactive jobs where standard output is logged to file.""")

    label = param.String(default='Progress', allow_None=True, doc="""
        The label of the current progress bar.""")

    width = param.Integer(default=70, doc="""
        The width of the progress bar as the number of chararacters""")

    fill_char = param.String(default='#', doc="""
        The character used to fill the progress bar.""")

    blank_char = param.String(default=' ', doc="""
        The character for the blank portion of the progress bar.""")

    percent_range = param.NumericTuple(default=(0.0,100.0), doc="""
        The total percentage spanned by the progress bar when called
        with a value between 0% and 100%. This allows an overall
        completion in percent to be broken down into smaller sub-tasks
        that individually complete to 100 percent.""")

    def __init__(self, **kwargs):
        super(ProgressBar,self).__init__(**kwargs)

    def __call__(self, percentage):
        " Update the progress bar within the specified percent_range"
        if not self.display: return
        span = (self.percent_range[1]-self.percent_range[0])
        percentage = self.percent_range[0] + ((percentage/100.0) * span)
        if clear_output and not ipython2: clear_output()
        if clear_output and ipython2: clear_output(wait=True)
        percent_per_char = 100.0 / self.width
        char_count = int(math.floor(percentage/percent_per_char)<commit_msg>ProgressBar.display now selects between different display modes<commit_after>import sys, math, time

import numpy as np
from collections import OrderedDict

from nose.plugins.skip import SkipTest

try:
    import IPython
    from IPython.core.display import clear_output
except:
    clear_output = None
    raise SkipTest("IPython extension requires IPython >= 0.12")
from IPython.display import display
from IPython.core.pylabtools import print_figure
try:
    from IPython.html import widgets
    from IPython.html.widgets import FloatSliderWidget
except:
    widgets = None
    FloatSliderWidget = object

try:
    import mpld3
except:
    mpld3 = None

# IPython 0.13 does not have version_info
ipython2 = hasattr(IPython, 'version_info') and (IPython.version_info[0] == 2)

import param

from .. import GridLayout, NdMapping
from ..views import Layout, Overlay, View
from ..sheetviews import CoordinateGrid
from ..plots import GridLayoutPlot, Plot
from .magics import ViewMagic


class ProgressBar(param.Parameterized):
    """
    A simple text progress bar suitable for both the IPython notebook
    and the IPython interactive prompt.
    """

    display = param.ObjectSelector(default='stdout',
                                   objects=['stdout', 'disabled'],
                                   doc="""
       Parameter to control display of the progress bar. By default,
       progress is shown on stdout but this may be disabled e.g. for
       jobs that log standard output to file.""")

    label = param.String(default='Progress', allow_None=True, doc="""
        The label of the current progress bar.""")

    width = param.Integer(default=70, doc="""
        The width of the progress bar as the number of chararacters""")

    fill_char = param.String(default='#', doc="""
        The character used to fill the progress bar.""")

    blank_char = param.String(default=' ', doc="""
        The character for the blank portion of the progress bar.""")

    percent_range = param.NumericTuple(default=(0.0,100.0), doc="""
        The total percentage spanned by the progress bar when called
        with a value between 0% and 100%. This allows an overall
        completion in percent to be broken down into smaller sub-tasks
        that individually complete to 100 percent.""")

    def __init__(self, **kwargs):
        super(ProgressBar,self).__init__(**kwargs)

    def __call__(self, percentage):
        " Update the progress bar within the specified percent_range"
        span = (self.percent_range[1]-self.percent_range[0])
        percentage = self.percent_range[0] + ((percentage/100.0) * span)

        if self.display == 'disabled': return
        elif self.display == 'stdout':
            self._stdout_display(percentage)
            return

    def _stdout_display(self, percentage):
        if clear_output and not ipython2: clear_output()
        if clear_output and ipython2: clear_output(wait=True)
        percent_per_char = 100.0 / self.width
        char_count = int(math.floor(percentage/percent_per_char)
{'fraction_non_alphanumeric': 0.08681394546082154, 'fraction_numerical': 0.013462202278218847, 'mean_word_length': 3.2392099487929773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3281293', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1579, 'n_words': 567}