Skip to content

Commit

Permalink
Time To completition added
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMatchett committed May 19, 2018
1 parent 6643a08 commit bbfa549
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 0 deletions.
Binary file modified .vs/ExCell Art/v15/.suo
Binary file not shown.
Binary file modified .vs/ExCell Art/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/ExCell Art/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/ExCell Art/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
13 changes: 13 additions & 0 deletions ExCell Art/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions ExCell Art/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,53 @@ private void Start_Click(object sender, EventArgs e)

}

//for estimated time to completion counter
DateTime LastPercentageTime = DateTime.Now;
decimal LastPercentageValue = 0;
List<decimal> AverageTimeFor1Percent = new List<decimal>();

private void Bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//if not initiliased, or percentage has not increased since last execution
if(LastPercentageValue == 0 || e.ProgressPercentage == 0 || LastPercentageValue == e.ProgressPercentage)
{
LastPercentageTime = DateTime.Now;
LastPercentageValue = e.ProgressPercentage;
}
else
{
decimal PercentageDifference = e.ProgressPercentage - LastPercentageValue;
TimeSpan TimeDifference = DateTime.Now - LastPercentageTime;

//time for 1% = (1/percentageDifference * Time Difference)
decimal TimeFor1Percent = (1 / PercentageDifference) * Convert.ToDecimal(TimeDifference.TotalSeconds);
AverageTimeFor1Percent.Add(TimeFor1Percent);

if(AverageTimeFor1Percent.Count > 5)
{
AverageTimeFor1Percent.Remove(AverageTimeFor1Percent.First());
}

//now multiply time for 1% by the percentage remianing e.g. 45% done would be 55% percent to go
decimal SecondsRemaining = (AverageTimeFor1Percent.Average() * (100 - e.ProgressPercentage));
SecondsRemaining = Math.Floor(SecondsRemaining);

if (SecondsRemaining > 0)
{
//update labels and refresh values
TimeRemainingLabel.Text = ("Time Remaining: " + SecondsRemaining + " seconds");
LastPercentageTime = DateTime.Now;
LastPercentageValue = e.ProgressPercentage;
}
}


int percentage = Convert.ToInt32(e.ProgressPercentage);

//101 signifies finished, stop multithread sending multiple "finished" signal
if (percentage == 101)
{
TimeRemainingLabel.Text = ("Time Remaining: " + 0 + " seconds");
progressBar.Value = 100;
MessageBox.Show("Finished!");
foreach (ArtMaker A in BWList)
Expand Down Expand Up @@ -123,5 +163,10 @@ private void Cancel_Click(object sender, EventArgs e)
progressBar.Value = 0;
Start.Enabled = true;
}

private void TimeRemainingLabel_Click(object sender, EventArgs e)
{

}
}
}
Binary file modified ExCell Art/bin/Debug/ExCell Art.exe
Binary file not shown.
Binary file modified ExCell Art/bin/Debug/ExCell Art.pdb
Binary file not shown.
Binary file modified ExCell Art/obj/Debug/ExCell Art.csproj.GenerateResource.Cache
Binary file not shown.
Binary file modified ExCell Art/obj/Debug/ExCell Art.exe
Binary file not shown.
Binary file modified ExCell Art/obj/Debug/ExCell Art.pdb
Binary file not shown.

0 comments on commit bbfa549

Please sign in to comment.