public void UpdateHealth(PlottingStatistics stats) { int lastModifiedAtWarningThreashold = 0; int lastModifiedAtErrorThreashold = 0; switch (this.CurrentPhase) { case 1: lastModifiedAtWarningThreashold = (int)(((float)stats.Phase1AvgTimeNeed / 60 / 7 / this.Buckets) * 3); if (lastModifiedAtWarningThreashold == 0) { lastModifiedAtWarningThreashold = 15; } break; case 2: lastModifiedAtWarningThreashold = (int)((float)stats.Phase2AvgTimeNeed / 60 / 7 * 3); if (lastModifiedAtWarningThreashold == 0) { lastModifiedAtWarningThreashold = 10; } break; case 3: lastModifiedAtWarningThreashold = (int)(((float)stats.Phase3AvgTimeNeed / 60 / 7 / this.Buckets) * 3); if (lastModifiedAtWarningThreashold == 0) { lastModifiedAtWarningThreashold = 15; } break; case 4: lastModifiedAtWarningThreashold = (int)(((float)stats.Phase3AvgTimeNeed / 60 / this.Buckets) * 3); if (lastModifiedAtWarningThreashold == 0) { lastModifiedAtWarningThreashold = 15; } if (this.CurrentBucket == this.Buckets) { lastModifiedAtWarningThreashold = 20; } break; case 5: case 6: Health = Healthy.Instance; return; } if (lastModifiedAtWarningThreashold < 10) { lastModifiedAtWarningThreashold = 10; } lastModifiedAtWarningThreashold = (int)((float)lastModifiedAtWarningThreashold * 1.2f); lastModifiedAtErrorThreashold = lastModifiedAtWarningThreashold * 4; // Debug.WriteLine("lastModifiedAtWarningThreashold: " + lastModifiedAtWarningThreashold); // Debug.WriteLine("lastModifiedAtErrorThreashold: " + lastModifiedAtErrorThreashold); bool notLastAndNotDone = this.Progress < 100d && !this.IsLastInLogFile; bool lastModfiedAtWarning = false; bool lastModfiedAtError = false; bool lastLineError = this.IsLastLineTempError; TimeSpan?fileLastWrittenAge = null; int lastWriteMinutesAgo = 0; if (this.FileLastWritten != null) { fileLastWrittenAge = DateTime.Now - ((DateTime)this.FileLastWritten); if (((TimeSpan)fileLastWrittenAge).TotalMinutes > (lastModifiedAtWarningThreashold + 1)) { lastModfiedAtWarning = true; } if (((TimeSpan)fileLastWrittenAge).TotalMinutes > (lastModifiedAtErrorThreashold + 1)) { lastModfiedAtError = true; } lastWriteMinutesAgo = (int)((TimeSpan)fileLastWrittenAge).TotalMinutes; } // manual is set to false for now, it will be overwritten in ChiaPlotStatus.cs if necessary bool manual = false; if (notLastAndNotDone) { this.Health = new ConfirmedDead(manual); } else if (lastModfiedAtError) { this.Health = new PossiblyDead(lastWriteMinutesAgo, lastModifiedAtErrorThreashold); } else if (lastModfiedAtWarning) { this.Health = new Concerning(lastWriteMinutesAgo, lastModifiedAtWarningThreashold); } else if (lastLineError) { this.Health = TempError.Instance; } else { this.Health = Healthy.Instance; } }
public void UpdateEta(PlottingStatistics stats) { this.TimeRemaining = 0; if (this.Buckets == 0) { // log too short to know anything yet this.ETA = null; this.TimeRemaining = 0; return; } if (CurrentPhase == 6) { this.TimeRemaining = 0; } if (CurrentPhase <= 5) { float factor = 1; if (CurrentPhase == 5) { DateTime copyStart = ((DateTime)this.StartDate) .AddSeconds(this.Phase1Seconds) .AddSeconds(this.Phase2Seconds) .AddSeconds(this.Phase3Seconds) .AddSeconds(this.Phase4Seconds); int elapsed = (int)(DateTime.Now - copyStart).TotalSeconds; factor = (float)1 - (float)((float)elapsed / stats.CopyTimeAvgTimeNeed); if (factor < 0.01f) { factor = 0.01f; } } this.TimeRemaining += (int)(factor * (float)stats.CopyTimeAvgTimeNeed); } if (CurrentPhase <= 4) { float factor = 1; if (CurrentPhase == 4) { factor = (float)1 - ((float)((float)this.CurrentBucket / this.Buckets)); } this.TimeRemaining += (int)(factor * stats.Phase4AvgTimeNeed); } if (CurrentPhase <= 3) { float factor = 1; if (CurrentPhase == 3) { factor = (float)1 - ((float)(((float)this.Phase3Table - 1) + ((float)this.CurrentBucket / this.Buckets)) / 7); } this.TimeRemaining += (int)(factor * stats.Phase3AvgTimeNeed); } if (CurrentPhase <= 2) { float factor = 1; if (CurrentPhase == 2) { factor = (float)1 - ((float)((float)7 - this.Phase2Table) / 7); } this.TimeRemaining += (int)(factor * stats.Phase2AvgTimeNeed); } if (CurrentPhase == 1) { var factor = (float)1 - ((float)(((float)this.Phase3Table - 1) + ((float)this.CurrentBucket / this.Buckets)) / 7); this.TimeRemaining += (int)(factor * stats.Phase2AvgTimeNeed); } if (this.TimeRemaining > 0) { DateTime dt = DateTime.Now; dt = dt.AddSeconds(this.TimeRemaining); this.ETA = dt; } else { this.ETA = null; } }