From bd4fe6dba831f6afd55bcab8c99960a68c440d6d Mon Sep 17 00:00:00 2001 From: Mudiaga Obriki Date: Thu, 20 Feb 2025 16:46:06 +0100 Subject: [PATCH] Updated progress status and phased progress reporter --- .../Utils/PhasedProgressReporter.cs | 8 ++++- src/SIL.Machine/Utils/ProgressStatus.cs | 36 +++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/SIL.Machine/Utils/PhasedProgressReporter.cs b/src/SIL.Machine/Utils/PhasedProgressReporter.cs index 353b09f0a..fe7d1f91f 100644 --- a/src/SIL.Machine/Utils/PhasedProgressReporter.cs +++ b/src/SIL.Machine/Utils/PhasedProgressReporter.cs @@ -10,6 +10,10 @@ public class PhasedProgressReporter private readonly double _defaultPercentage; private int _currentPhaseIndex = -1; private double _percentCompleted; + + private readonly double _inferenceProgress = 0; // will perform the calculation + private readonly double _fineTuneProgress = 0; // will perform the calculation + private int _step; private int _prevPhaseLastStep; @@ -68,7 +72,9 @@ protected internal virtual void Report(ProgressStatus value) double percentCompleted = _percentCompleted + CurrentPhasePercentage * (value.PercentCompleted ?? 0); string message = value.Message ?? Phases[_currentPhaseIndex].Message; - _progress.Report(new ProgressStatus(_step, percentCompleted, message)); + _progress.Report( + new ProgressStatus(_step, percentCompleted, _fineTuneProgress, _inferenceProgress, message) + ); } } } diff --git a/src/SIL.Machine/Utils/ProgressStatus.cs b/src/SIL.Machine/Utils/ProgressStatus.cs index 89b7eb371..6119cf77d 100644 --- a/src/SIL.Machine/Utils/ProgressStatus.cs +++ b/src/SIL.Machine/Utils/ProgressStatus.cs @@ -5,22 +5,36 @@ namespace SIL.Machine.Utils public struct ProgressStatus : IEquatable { public ProgressStatus(int step, int stepCount, string message = null) - : this(step, stepCount == 0 ? 1.0 : (double)step / stepCount, message) { } + : this(step, stepCount == 0 ? (double?)1.0 : (double)step / stepCount, null, null, message) { } - public ProgressStatus(int step, double? percentCompleted = null, string message = null) + public ProgressStatus( + int step, + double? percentCompleted = null, + double? fineTuneProgress = null, + double? inferenceProgress = null, + string message = null + ) { Step = step; - PercentCompleted = percentCompleted; - Message = message; + PercentCompleted = percentCompleted ?? 0.0; + FineTuneProgress = fineTuneProgress ?? 0.0; + InferenceProgress = inferenceProgress ?? 0.0; + Message = message ?? string.Empty; } public int Step { get; } public double? PercentCompleted { get; } + public double? FineTuneProgress { get; } + public double? InferenceProgress { get; } public string Message { get; } public bool Equals(ProgressStatus other) { - return Step == other.Step && PercentCompleted == other.PercentCompleted && Message == other.Message; + return Step == other.Step + && PercentCompleted == other.PercentCompleted + && FineTuneProgress == other.FineTuneProgress + && InferenceProgress == other.InferenceProgress + && Message == other.Message; } public override bool Equals(object obj) @@ -30,11 +44,13 @@ public override bool Equals(object obj) public override int GetHashCode() { - int code = 23; - code = code * 31 + Step.GetHashCode(); - code = code * 31 + (PercentCompleted?.GetHashCode() ?? 0); - code = code * 31 + (Message?.GetHashCode() ?? 0); - return code; + int hash = 23; + hash = hash * 31 + Step.GetHashCode(); + hash = hash * 31 + (PercentCompleted?.GetHashCode() ?? 0); + hash = hash * 31 + (FineTuneProgress?.GetHashCode() ?? 0); + hash = hash * 31 + (InferenceProgress?.GetHashCode() ?? 0); + hash = hash * 31 + (Message?.GetHashCode() ?? 0); + return hash; } } }