-
Notifications
You must be signed in to change notification settings - Fork 2
/
Progress.cs
122 lines (108 loc) · 3.55 KB
/
Progress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EnergyBalanceSolver
{
public partial class Progress : Form
{
private readonly System.Threading.CancellationTokenSource userCts;
private Stopwatch timer = new Stopwatch();
public double TotalSolutions;
public double CompletedCount;
public Progress(System.Threading.CancellationTokenSource userCts)
{
InitializeComponent();
this.userCts = userCts;
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
timer.Start();
}
private void button1_Click(object sender, EventArgs e)
{
userCts.Cancel();
}
internal void UpdateLabel(string v)
{
lblStep.BeginInvoke(new Action(() => lblStep.Text = v));
}
private void timer1_Tick(object sender, EventArgs e)
{
lblElapsed.Text = timer.Elapsed.ToString("hh\\:mm\\:ss");
if (TotalSolutions > 0)
{
var percent = (CompletedCount / TotalSolutions) * 100;
if (percent <= 100) //skip this update if it seems out of whack...
{
progressBar1.Value = (int)percent;
lblPercent.Text = $"{Math.Round(percent, 2)}%";
}
} else
{
lblPercent.Text = "0%";
progressBar1.Value = 0;
}
}
const int EasyThreshold = 125_000_000;
const int MediumThreshold = 250_000_000;
const int HardThreshold = 325_000_000;
const int HarderThreshold = 400_000_000;
const int ImpossibleThreshold = 500_000_000;
internal void SetDificulty(int v)
{
//Rudimentary difficulty levels
// 0 -> 125M - Easy
// 125 -> 250M - Medium
// 250 -> 325M - Hard
// 325 -> 400M - Harder
//> 500M - Impossible
lblDifficulty.BeginInvoke(new Action(() =>
{
if(v == -1)
{
lblDifficulty.Text = "Calculating";
lblDifficulty.ForeColor = Color.Black;
}
else if( v >= MediumThreshold )
{
lblDifficulty.ForeColor = Color.DarkRed;
if (v >= ImpossibleThreshold)
{
lblDifficulty.Text = "Insane";
}
else if(v >= HarderThreshold)
{
lblDifficulty.Text = "Even Harder";
}
else if(v >= HardThreshold)
{
lblDifficulty.Text = "Harder";
}
else
{
lblDifficulty.Text = "Hard";
}
} else
{
lblDifficulty.ForeColor = Color.DarkGreen;
if(v >= EasyThreshold)
{
lblDifficulty.Text = "Medium";
}
else
{
lblDifficulty.Text = "Easy";
}
}
}));
}
}
}