Changeset 1813 for trunk/eraser6
- Timestamp:
- 2/11/2010 5:50:39 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/eraser6/Eraser.Util/ProgressManager.cs (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util/ProgressManager.cs
r1802 r1813 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Text; 25 26 … … 61 62 62 63 /// <summary> 63 /// Computes the speed of the erase, in unitsof completion per second,64 /// Computes the speed of the erase, in percentage of completion per second, 64 65 /// based on the information collected in the previous 15 seconds. 65 66 /// </summary> 66 public abstract int Speed67 public abstract float Speed 67 68 { 68 69 get; … … 156 157 } 157 158 158 public override int Speed 159 { 160 get 161 { 162 if (DateTime.Now == StartTime) 163 return 0; 164 165 if ((DateTime.Now - lastSpeedCalc).Seconds < 5 && lastSpeed != 0) 159 public override float Speed 160 { 161 get 162 { 163 if ((DateTime.Now - lastSpeedCalc).Seconds <= 1 && lastSpeed != 0) 166 164 return lastSpeed; 167 165 … … 172 170 173 171 //Then compute the speed of the calculation 174 lastSpeed = ( int)((Completed - lastCompleted) / timeElapsed);172 lastSpeed = (float)((Completed - lastCompleted) / timeElapsed / total); 175 173 lastSpeedCalc = DateTime.Now; 176 174 lastCompleted = Completed; … … 183 181 get 184 182 { 185 if (Speed == 0) 183 float speed = Speed; 184 if (speed == 0.0) 186 185 return TimeSpan.Zero; 187 return new TimeSpan(0, 0, (int)((Total - Completed) / Speed)); 186 187 return TimeSpan.FromSeconds((1.0f - Progress) / speed); 188 188 } 189 189 } … … 203 203 /// The last calculated speed of the operation. 204 204 /// </summary> 205 private int lastSpeed;205 private float lastSpeed; 206 206 207 207 /// <summary> … … 412 412 get 413 413 { 414 float result = 0.0f; 415 lock (ListLock) 416 foreach (SteppedProgressManagerStep step in Steps) 417 result += step.Progress.Progress * step.Weight; 418 419 return result; 420 } 421 } 422 423 public override int Speed 414 lock (ListLock) 415 return Steps.Sum(step => step.Progress.Progress * step.Weight); 416 } 417 } 418 419 public override float Speed 424 420 { 425 421 get … … 436 432 get 437 433 { 438 long ticksElapsed = (DateTime.Now - StartTime).Ticks; 439 float progressRemaining = 1.0f - Progress; 440 return new TimeSpan((long) 441 (progressRemaining * (ticksElapsed / (double)Progress))); 434 float speed = Speed; 435 if (speed == 0.0) 436 return TimeSpan.Zero; 437 438 return TimeSpan.FromSeconds((1.0f - Progress) / speed); 442 439 } 443 440 } … … 687 684 get 688 685 { 689 float result = 0.0f;690 686 lock (TaskLock) 691 foreach (ProgressManagerBase subTask in Tasks) 692 result += subTask.Progress * (1.0f / Tasks.Count); 693 694 return result; 695 } 696 } 697 698 public override int Speed 699 { 700 get 701 { 702 int maxSpeed = 0; 687 return Tasks.Sum(task => task.Progress * (1.0f / Tasks.Count)); 688 } 689 } 690 691 public override float Speed 692 { 693 get 694 { 703 695 lock (TaskLock) 704 foreach (ProgressManagerBase subTask in Tasks) 705 maxSpeed = Math.Max(subTask.Speed, maxSpeed); 706 707 return maxSpeed; 696 return Tasks.Max(task => task.Speed); 708 697 } 709 698 } … … 713 702 get 714 703 { 715 TimeSpan maxTime = TimeSpan.MinValue;716 704 lock (TaskLock) 717 foreach (ProgressManagerBase subTask in Tasks) 718 if (maxTime < subTask.TimeLeft) 719 maxTime = subTask.TimeLeft; 720 721 return maxTime; 705 return Tasks.Max(task => task.TimeLeft); 722 706 } 723 707 }
Note: See TracChangeset
for help on using the changeset viewer.
