Progress Tracker¶
progress_tracker ¶
Classes¶
ProgressTracker ¶
Simplified progress tracker for multi-stage processing.
This class tracks progress across 8 weighted processing stages without threading complexity, designed specifically for single-threaded Dash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id | str | Unique session identifier for tracking | required |
Attributes:
| Name | Type | Description |
|---|---|---|
session_id | str | Session identifier |
_stages | Dict[int, str] | Stage number to description mapping |
_stage_weights | Dict[int, float] | Stage number to weight mapping (sums to 100.0) |
_current_stage | int | Current stage number (1-8) |
_current_message | str | Current processing message |
_start_time | float | Timestamp when processing started |
_error | Optional[str] | Error message if processing failed |
Methods:
| Name | Description |
|---|---|
start_stage | Start a new processing stage |
update_progress | Update progress within current stage |
complete | Mark processing as complete |
set_error | Set error message and halt progress |
get_progress | Get current progress as DTO |
calculate_overall_progress | Calculate weighted overall progress |
Notes
8 Processing Stages with Weights: 1. Input Validation (5%) 2. Data Parsing (10%) 3. BioRemPP Merge (30%) 4. KEGG Merge (20%) 5. HADEG Merge (15%) 6. ToxCSM Merge (10%) 7. Result Preparation (5%) 8. Finalization (5%)
Simplifications from Legacy: - NO threading.Lock (single-threaded Dash) - NO callback notifications (handled externally) - Simple dict storage instead of complex state machine - Weighted progress calculation preserved
Examples:
>>> tracker = ProgressTracker("session_1")
>>> tracker.start_stage(1, "Validation", "Validating input")
>>> tracker.update_progress(50.0, "Checked 3/5 samples")
>>> progress = tracker.get_progress()
'Validation'
Initialize simplified progress tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id | str | Unique session identifier | required |
Source code in src/application/services/progress_tracker.py
Functions¶
start_stage ¶
Start a new processing stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stage | int | Stage number (1-8) | required |
stage_name | str | Stage description (optional, uses default if empty) | required |
message | str | Initial stage message | "" |
Raises:
| Type | Description |
|---|---|
ValueError | If stage number is invalid |
Examples:
>>> tracker = ProgressTracker("session_1")
>>> tracker.start_stage(1, "Validation", "Starting validation")
Source code in src/application/services/progress_tracker.py
update_progress ¶
Update progress within current stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress | float | Progress percentage within stage (0.0-100.0) | required |
message | Optional[str] | Optional progress message | None |
Raises:
| Type | Description |
|---|---|
ValueError | If progress is out of range |
Examples:
>>> tracker.start_stage(3, "Merge", "Merging data")
>>> tracker.update_progress(50.0, "Processed 500/1000 records")
Source code in src/application/services/progress_tracker.py
complete ¶
Mark processing as complete (100%).
Examples:
Source code in src/application/services/progress_tracker.py
set_error ¶
Set error message and halt progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error | str | Error description | required |
Examples:
Source code in src/application/services/progress_tracker.py
get_progress ¶
Get current progress as DTO.
Returns:
| Type | Description |
|---|---|
ProcessingProgressDTO | Current progress information |
Examples:
>>> tracker.start_stage(3, "Merge", "Processing")
>>> tracker.update_progress(50.0)
>>> dto = tracker.get_progress()
>>> dto.current_stage
'BioRemPP Database Merge'
Source code in src/application/services/progress_tracker.py
calculate_overall_progress ¶
Calculate weighted overall progress across all stages.
Returns:
| Type | Description |
|---|---|
float | Overall progress percentage (0.0-100.0) |
Notes
Formula: Σ(completed_stages_weights) + (current_stage_weight * stage_progress%)
Examples:
>>> tracker.start_stage(3, "Merge", "Processing")
>>> tracker.update_progress(50.0) # 50% of stage 3
>>> overall = tracker.calculate_overall_progress()
>>> # Stages 1-2 complete (15%) + 50% of stage 3 (15% of 30%)
>>> round(overall, 1)
30.0