check point
This commit is contained in:
115
VisionBuilder.UI.Windows/Components/Stats.cs
Normal file
115
VisionBuilder.UI.Windows/Components/Stats.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System.Drawing.Imaging;
|
||||
using VisionBuilder.UI.Common.ViewModel;
|
||||
|
||||
namespace VisionBuilder.UI.Windows.Components
|
||||
{
|
||||
public partial class Stats : UserControl
|
||||
{
|
||||
|
||||
public void SetViewModel(StatisticsVM statisticsVm)
|
||||
{
|
||||
_statisticsVm = statisticsVm;
|
||||
_statisticsVm.PropertyChanged += _statisticsVm_PropertyChanged;
|
||||
}
|
||||
|
||||
private void _statisticsVm_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(StatisticsVM.SessionStarted):
|
||||
UpdateMeta("Started at", _statisticsVm.SessionStarted, true);
|
||||
break;
|
||||
case nameof(StatisticsVM.RecipeName):
|
||||
UpdateMeta("Recipe", _statisticsVm.RecipeName, true);
|
||||
break;
|
||||
case nameof(StatisticsVM.ProcessingTime):
|
||||
UpdateMeta("Processing time", _statisticsVm.ProcessingTime, true);
|
||||
break;
|
||||
case nameof(StatisticsVM.Good):
|
||||
UpdateMeta("Good", _statisticsVm.Good.ToString(), true);
|
||||
break;
|
||||
case nameof(StatisticsVM.Bad):
|
||||
UpdateMeta("Bad", _statisticsVm.Bad.ToString(), true);
|
||||
break;
|
||||
case nameof(StatisticsVM.Total):
|
||||
UpdateMeta("Total", _statisticsVm.Total.ToString(), true);
|
||||
break;
|
||||
case nameof(StatisticsVM.StatisticsDetails):
|
||||
UpdateMeta("Details", _statisticsVm.StatisticsDetails, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Stats()
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
_imageGoodIndicator = new Bitmap(32, 32, PixelFormat.Format32bppArgb);
|
||||
using (Graphics g = Graphics.FromImage(_imageGoodIndicator))
|
||||
{
|
||||
g.Clear(Color.Transparent);
|
||||
g.FillEllipse(Brushes.Green, 0, 0, 32, 32);
|
||||
}
|
||||
|
||||
_imageBadIndicator = new Bitmap(32, 32, PixelFormat.Format32bppArgb);
|
||||
using (Graphics g = Graphics.FromImage(_imageBadIndicator))
|
||||
{
|
||||
g.Clear(Color.Transparent);
|
||||
g.FillEllipse(Brushes.Red, 0, 0, 32, 32);
|
||||
}
|
||||
}
|
||||
private Dictionary<string, Control> _meta = new Dictionary<string, Control>();
|
||||
private readonly Bitmap _imageGoodIndicator;
|
||||
private readonly Bitmap _imageBadIndicator;
|
||||
private StatisticsVM _statisticsVm;
|
||||
|
||||
public void UpdateMeta(string name, string text, bool bold=false)
|
||||
{
|
||||
Action a = new Action(() =>
|
||||
{
|
||||
if (!_meta.ContainsKey(name))
|
||||
{
|
||||
metaPanel.Controls.Add(new Label() { AutoSize = true, Margin = new Padding(0, 8, 0, 0), Text = name + ":", Font = new Font(new FontFamily("Verdana"), 8, FontStyle.Bold) });
|
||||
_meta[name] = new Label() { AutoSize = true, Margin = new Padding(0) };
|
||||
_meta[name].Font = new Font(new FontFamily("Verdana"), 8, bold?FontStyle.Bold:FontStyle.Regular);
|
||||
metaPanel.Controls.Add(_meta[name]);
|
||||
|
||||
}
|
||||
_meta[name].Text = text;
|
||||
|
||||
|
||||
metaPanel.Refresh();
|
||||
});
|
||||
|
||||
if (metaPanel.InvokeRequired)
|
||||
{
|
||||
metaPanel.Invoke(a);
|
||||
}
|
||||
else
|
||||
{
|
||||
a();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static string ShortenString(string input, int maxLength)
|
||||
{
|
||||
if (input.Length <= maxLength)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
else
|
||||
{
|
||||
return input.Substring(0, maxLength) + "...";
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_meta.Clear();
|
||||
metaPanel.Controls.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user