Ejemplo n.º 1
0
    def _progress_register(self, amount_of_work, description=None, stage=0):
        """ Registers a progress which can be reported/displayed via a progress bar.

        Parameters
        ----------
        amount_of_work : int
            Amount of steps the underlying algorithm has to perform.
        description : str, optional
            This string will be displayed in the progress bar widget.
        stage : int, optional, default=0
            If the algorithm has multiple different stages (eg. calculate means
            in the first pass over the data, calculate covariances in the second),
            one needs to estimate different times of arrival.
        """
        if hasattr(self, 'show_progress') and not self.show_progress:
            return

        # note this semantic makes it possible to use this class without calling
        # its constructor.
        if not hasattr(self, '_prog_rep_progressbars'):
            self._prog_rep_progressbars = {}

        if not is_int(amount_of_work):
            raise ValueError(
                "amount_of_work has to be of integer type. But is %s" %
                type(amount_of_work))

        self._prog_rep_progressbars[stage] = _ProgressBar(
            amount_of_work, description=description)
Ejemplo n.º 2
0
    def _progress_register(self, amount_of_work, description='', stage=0):
        """ Registers a progress which can be reported/displayed via a progress bar.

        Parameters
        ----------
        amount_of_work : int
            Amount of steps the underlying algorithm has to perform.
        description : str, optional
            This string will be displayed in the progress bar widget.
        stage : int, optional, default=0
            If the algorithm has multiple different stages (eg. calculate means
            in the first pass over the data, calculate covariances in the second),
            one needs to estimate different times of arrival.
        """
        if not self.show_progress:
            return

        if not is_int(amount_of_work):
            raise ValueError(
                "amount_of_work has to be of integer type. But is %s" %
                type(amount_of_work))

        # if we do not have enough work to do for the overhead of a progress bar,
        # we just define a dummy here
        if amount_of_work <= ProgressReporter._pg_threshold:

            class dummy(object):
                pass

            pg = dummy()
            pg.__str__ = lambda: description
            pg.__repr__ = pg.__str__
            pg._dummy = None
            pg.description = ''
        else:
            pg = _ProgressBar(amount_of_work, description=description)

        self._prog_rep_progressbars[stage] = pg
        # pg.description = description
        self._prog_rep_descriptions[stage] = description