🔍 Code Extractor

class ProgressIndicator

Maturity: 47

Abstract base class for progress indicators that display task completion as a percentage, providing a framework for implementing custom progress tracking mechanisms.

File:
/tf/active/vicechatdev/patches/util.py
Lines:
1297 - 1313
Complexity:
simple

Purpose

ProgressIndicator serves as a base class for creating progress tracking components that display completion percentages. It provides a standardized interface with configurable percentage ranges and labels, allowing progress bars to represent sub-tasks within larger operations. The class is designed to be subclassed with custom implementations of the __call__ method to handle actual progress display logic.

Source Code

class ProgressIndicator(param.Parameterized):
    """
    Baseclass for any ProgressIndicator that indicates progress
    as a completion percentage.
    """

    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.""")

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

    def __call__(self, completion):
        raise NotImplementedError

Parameters

Name Type Default Kind
bases param.Parameterized -

Parameter Details

percent_range: A tuple of two floats (min, max) defining the percentage range spanned by the progress indicator. Default is (0.0, 100.0). This allows breaking down overall progress into smaller sub-tasks, where each sub-task can complete to 100% within its allocated portion of the total range.

label: A string label describing the current progress operation. Default is 'Progress'. Can be None. Used to identify what task is being tracked by the progress indicator.

Return Value

Instantiation returns a ProgressIndicator object (or subclass instance). The __call__ method is abstract and must be implemented by subclasses to return appropriate progress display behavior. Subclasses should define what happens when the indicator is called with a completion percentage.

Class Interface

Methods

__init__(percent_range=(0.0, 100.0), label='Progress', **params)

Purpose: Initialize a ProgressIndicator instance with configurable percentage range and label

Parameters:

  • percent_range: Tuple of (min_percent, max_percent) defining the range this indicator spans. Default (0.0, 100.0)
  • label: String label for the progress indicator. Default 'Progress'. Can be None
  • **params: Additional parameters passed to param.Parameterized base class

Returns: ProgressIndicator instance

__call__(completion) -> None

Purpose: Abstract method to update progress display based on completion percentage. Must be implemented by subclasses.

Parameters:

  • completion: Float or int representing completion percentage from 0 to 100

Returns: Implementation-dependent. Base class raises NotImplementedError

Attributes

Name Type Description Scope
percent_range param.NumericTuple Tuple of two floats (min, max) defining the percentage range (0.0-100.0) that this progress indicator spans. Allows sub-task progress mapping. class
label param.String String label describing the current progress operation. Can be None. Default is 'Progress'. class

Dependencies

  • param

Required Imports

import param

Usage Example

# This is an abstract base class, so you must subclass it:
import param

class MyProgressIndicator(ProgressIndicator):
    def __call__(self, completion):
        # completion is a value between 0 and 100
        actual_percent = self.percent_range[0] + (completion / 100.0) * (self.percent_range[1] - self.percent_range[0])
        print(f"{self.label}: {actual_percent:.1f}%")

# Instantiate and use
progress = MyProgressIndicator(label='Loading Data', percent_range=(0.0, 50.0))
progress(0)    # Loading Data: 0.0%
progress(50)   # Loading Data: 25.0%
progress(100)  # Loading Data: 50.0%

Best Practices

  • This is an abstract base class and cannot be instantiated directly - you must create a subclass that implements the __call__ method
  • The __call__ method should accept a completion value between 0 and 100 representing the percentage complete
  • Use percent_range to map sub-task progress to a portion of overall progress (e.g., if a sub-task represents 20-40% of total work, set percent_range=(20.0, 40.0))
  • The label parameter should be descriptive of the current operation being tracked
  • Subclass implementations should handle the conversion from the 0-100 completion parameter to the actual percent_range values
  • This class inherits from param.Parameterized, so all param features (validation, watchers, dependencies) are available
  • The completion parameter passed to __call__ is expected to be in the 0-100 range regardless of the percent_range setting

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ProgressLogger 54.9% similar

    A progress tracking logger that monitors and reports the progress of long-running operations with timing statistics, error counts, and estimated completion times.

    From: /tf/active/vicechatdev/contract_validity_analyzer/utils/logging_utils.py
  • function api_index_progress 49.6% similar

    Flask API endpoint that retrieves the current progress status of an asynchronous indexing task by its task ID.

    From: /tf/active/vicechatdev/docchat/app.py
  • class BaseUIComponent 48.7% similar

    Base class for UI components that provides common notification functionality for displaying error, success, warning, and info messages.

    From: /tf/active/vicechatdev/CDocs/ui/base_ui.py
  • function enhanced_workflow_progress 46.6% similar

    Flask route handler that retrieves and returns the current progress status of an enhanced SQL workflow, including step completion, progress percentage, and final results if completed.

    From: /tf/active/vicechatdev/full_smartstat/app.py
  • class TrainingCompletion 45.4% similar

    UI component for completing training requirements.

    From: /tf/active/vicechatdev/CDocs/ui/training_completion.py
← Back to Browse