Browse Source

+display: max heart rate

HOME 3 months ago
parent
commit
87c46b4876
1 changed files with 83 additions and 37 deletions
  1. 83 37
      BsWidget/MainForm.cs

+ 83 - 37
BsWidget/MainForm.cs

@@ -18,6 +18,8 @@ namespace BsWidget;
 
 internal class MainForm : BaseForm
 {
+    private const float RecordPixel = 2.5f;
+
     private const string FontName = "BIZ UDGothic Bold";
 
     private Timer _updateTimer;
@@ -65,7 +67,8 @@ internal class MainForm : BaseForm
     public float? CurrentGpuUsage { get; set; } = 45.6f;
     public YurStatus CurrentYurStatus { get; set; } = new YurStatus { HeartRate = 0, KcalPerMin = 0 };
 
-    public int MaxHitsPerSecond { get; set; }
+    public int? MaxHitsPerSecond { get; set; }
+    public float? MaxHeartRate { get; set; }
 
 
     /// <summary> FinalScore,CurrentCombo </summary>
@@ -135,26 +138,38 @@ internal class MainForm : BaseForm
         _pcTimer?.Start();
 
 #if DEBUG
-        //Task.Run(Function);
+        Task.Run(Debugging);
 #endif
     }
 
-    private async void Function()
+    private async void Debugging()
     {
+        lock (CutHistory)
+        {
+            CutHistory.Add(new HistoryModel { HeartRate = 30, KcalPerMin = 30 });
+            CutHistory.Add(new HistoryModel { HeartRate = 1, KcalPerMin = 1 });
+
+        }
+        var rng = new Random();
         while (Visible)
         {
-            var rng = new Random();
-            HistoryModel last = null;
-            CutHistory.Clear();
-            for (int i = 0; i < 400; i++)
+
+            lock (CutHistory)
             {
-                var historyModel = new HistoryModel { HitsPerSecond = last?.HitsPerSecond > 0 ? last.HitsPerSecond - 1 : rng.Next(20) };
+                if (CutHistory.Count > (Width / RecordPixel) * 2) CutHistory.RemoveRange(0, CutHistory.Count / 2);
+                var historyModel = new HistoryModel
+                {
+                    HitsPerSecond = rng.Next(15),
+                    HeartRate = 15 + rng.Next(2),
+                    KcalPerMin = 15 + rng.Next(2),
+                };
+                CutHistory.Add(historyModel);
                 CutHistory.Add(historyModel);
-                last = historyModel;
+                //CutHistory.Add(historyModel);
             }
-
-            await Task.Delay(2000);
             _queue.Add(UpdateFlags.NoteFullyCut);
+
+            await Task.Delay(1000 / 15);
         }
     }
 
@@ -293,7 +308,8 @@ internal class MainForm : BaseForm
             {
                 CurrentHitsPerSecond = 0;
                 lock (CutHistory) CutHistory.Clear();
-                MaxHitsPerSecond = 0;
+                MaxHitsPerSecond = null;
+                MaxHeartRate = null;
             }
 
             var comboDelta = e.LiveData.Combo - CurrentCombo;
@@ -310,7 +326,7 @@ internal class MainForm : BaseForm
                 var now = DateTime.Now;
                 var preNow = now.AddSeconds(-1);
                 CurrentHitsPerSecond = CutHistory.Where(p => p.Time > preNow).Sum(p => p.ComboDelta);
-                if (CurrentHitsPerSecond > MaxHitsPerSecond) MaxHitsPerSecond = CurrentHitsPerSecond;
+                if (CurrentHitsPerSecond > MaxHitsPerSecond || MaxHitsPerSecond.HasValue == false) MaxHitsPerSecond = CurrentHitsPerSecond;
 
                 CutHistory.Add(new HistoryModel
                 {
@@ -363,6 +379,7 @@ internal class MainForm : BaseForm
     private void Yur_Event(object sender, YurStatus e)
     {
         CurrentYurStatus = e;
+        if (e.HeartRate > MaxHeartRate || MaxHeartRate.HasValue == false) MaxHeartRate = e.HeartRate;
         _queue.Add(UpdateFlags.Performance);
     }
 
@@ -449,7 +466,6 @@ internal class MainForm : BaseForm
 
             var chBottom = chTop + chHeight;
 
-            float RecordPixel = 2.5f;
             var LineWidth = 1.5f;
 
             var displayCount = (int)(chWidth / RecordPixel);
@@ -458,8 +474,18 @@ internal class MainForm : BaseForm
             using var comboPen = new Pen(Color.FromArgb(200, 0, 0, 255), LineWidth) { LineJoin = LineJoin.Round };
             using var accPen = new Pen(Color.FromArgb(200, Color.Purple), LineWidth) { LineJoin = LineJoin.Round };
             using var cpsPen = new Pen(Color.Yellow, LineWidth) { LineJoin = LineJoin.Round };
-            using var heartPen = new Pen(Color.FromArgb(200, Color.White), LineWidth) { LineJoin = LineJoin.Round };
-            using var calPen = new Pen(Color.FromArgb(200, Color.Lime), LineWidth) { LineJoin = LineJoin.Round };
+            using var calPen = new Pen(Color.FromArgb(200, Color.Lime), LineWidth) { LineJoin = LineJoin.Round, };
+            using var heartPen = new Pen(Color.White, LineWidth) { LineJoin = LineJoin.Round, DashStyle = DashStyle.Dot };
+
+            using var dashPen = new Pen(Color.DarkOrange);
+            dashPen.DashStyle = DashStyle.Dash;
+            dashPen.Width = LineWidth * 2;
+            dashPen.DashOffset = LineWidth * 2;
+
+            using var dashPen2 = new Pen(Color.DarkGray);
+            dashPen2.DashStyle = DashStyle.Dash;
+            dashPen2.Width = LineWidth * 2;
+            dashPen2.DashOffset = LineWidth * 2;
 
             //clear region 0,210 Wx200
             g.ClearRect(Color.Transparent, 0, chTop - 3, ViewSize.Width, chHeight + 6 + margin * 2);
@@ -515,8 +541,9 @@ internal class MainForm : BaseForm
                     var calPts = new List<PointF>();
                     var cpsPts = new List<PointF>();
 
-                    var lastPeak = -1;
                     var peaks = new List<Tuple<int, float>>();
+                    var skipFirst = true;
+
                     for (var i = 0; i < items.Length; i++)
                     {
                         var item = items[i];
@@ -528,6 +555,27 @@ internal class MainForm : BaseForm
                         heaPts.Add(new PointF(pointX, (chBottom - 1) - (chHeight - 2) * ((item.HeartRate - minHea) / rngHea)));
                         calPts.Add(new PointF(pointX, (chBottom - 1) - (chHeight - 2) * ((item.KcalPerMin - minCal) / rngCal)));
 
+                        if (peaks.Count > 0)
+                        {
+                            var maxVal = peaks.OrderByDescending(p => p.Item1).First();
+                            var topX = peaks.Where(p => p.Item1 == maxVal.Item1).OrderBy(p => p.Item2).Select(p => p.Item2).First();
+
+                            if (pointX - topX > margin * 2)
+                            {
+                                peaks.Clear();
+
+                                if (skipFirst)
+                                {
+                                    skipFirst = false;
+                                }
+                                else
+                                {
+                                    g.DrawLine(dashPen, topX, chTop, topX, chBottom);
+                                    g.DrawStringWithRoundedRect(maxVal.Item1 + "", _smallFont, topX - 4, chBottom, Brushes.Black, Brushes.Yellow, margin / 2.0f);
+                                }
+                            }
+                        }
+
                         if (i > 0 && i < items.Length - 1)
                         {
                             var prevItem = items[i - 1];
@@ -535,33 +583,31 @@ internal class MainForm : BaseForm
                             if (prevItem.HitsPerSecond <= item.HitsPerSecond && item.HitsPerSecond > nextItem.HitsPerSecond)
                             {
                                 //peak detected
-                                var peak = item.HitsPerSecond;
-                                if (peak != lastPeak)
+                                if (peaks.Count > 0)
                                 {
-                                    peaks.Add(new Tuple<int, float>(peak, pointX));
-                                    lastPeak = peak;
+                                    if (peaks.Max(p => p.Item1) < item.HitsPerSecond)
+                                    {
+                                        peaks.Add(new Tuple<int, float>(item.HitsPerSecond, pointX));
+                                        //g.DrawLine(dashPen2, pointX, chTop, pointX, chBottom);
+                                    }
                                 }
-                            }
-                            else
-                            {
-                                if (peaks.Count > 0 && peaks.Last().Item2 < pointX - 15)
+                                else
                                 {
-                                    var p = peaks.OrderByDescending(p => p.Item1).First();
-                                    g.DrawStringWithRoundedRect(p.Item1 + "", _smallFont, p.Item2, chBottom, Brushes.Black, Brushes.Yellow, margin / 2.0f);
-                                    peaks.Clear();
+                                    peaks.Add(new Tuple<int, float>(item.HitsPerSecond, pointX));
+                                    //g.DrawLine(dashPen2, pointX, chTop, pointX, chBottom);
                                 }
 
+
                             }
                         }
-
                     }
 
                     g.DrawLines(scorePen, scorePts.ToArray());
                     g.DrawLines(comboPen, comboPts.ToArray());
                     g.DrawLines(accPen, accPts.ToArray());
                     g.DrawLines(cpsPen, cpsPts.ToArray());
-                    g.DrawLines(heartPen, heaPts.ToArray());
                     g.DrawLines(calPen, calPts.ToArray());
+                    g.DrawLines(heartPen, heaPts.ToArray());
                 }
             }
         }
@@ -597,25 +643,25 @@ internal class MainForm : BaseForm
             x += sz.Width + margin * 2;
 
             sz = g.DrawStringWithOutline($"{CurrentHitsPerSecond}", Font, x, y, Color.Black, Color.White);
-            g.DrawStringWithOutline($"{MaxHitsPerSecond} max", Font, x, y + 50, Color.Black, Color.White);
+            g.DrawStringWithOutline($"{(MaxHitsPerSecond.HasValue ? $"{MaxHitsPerSecond:N0}" : "-")} max", Font, x, y + Font.Height, Color.Black, Color.White);
             x += sz.Width + margin * 2;
 
             sz = g.DrawStringWithRoundedRectPerf("HIT / SEC", _smallFont, x, y + margin * 1.5f, Brushes.Black,
                 Brushes.Yellow, 2.5f);
             x += sz.Width + margin * 2;
 
-            sz = g.DrawStringWithOutline($"{CurrentYurStatus.HeartRate:N1}", Font, x, y, Color.Black, Color.White);
+            sz = g.DrawStringWithOutline($"{CurrentYurStatus.KcalPerMin:N1}", Font, x, y, Color.Black, Color.White);
             x += sz.Width + margin * 2;
 
-            sz = g.DrawStringWithRoundedRectPerf("HEART", _smallFont, x, y + margin * 1.5f, Brushes.Black,
-                Brushes.White, 2.5f);
+            sz = g.DrawStringWithRoundedRectPerf("KCAL / MIN", _smallFont, x, y + margin * 1.5f, Brushes.Black,
+                Brushes.Lime, 2.5f);
             x += sz.Width + margin * 2;
 
-            sz = g.DrawStringWithOutline($"{CurrentYurStatus.KcalPerMin:N1}", Font, x, y, Color.Black, Color.White);
+            sz = g.DrawStringWithOutline($"{CurrentYurStatus.HeartRate:N1}", Font, x, y, Color.Black, Color.White);
+            g.DrawStringWithOutline($"{(MaxHeartRate.HasValue ? $"{MaxHeartRate:N1}" : "-")} max", Font, x, y + Font.Height, Color.Black, Color.White);
             x += sz.Width + margin * 2;
 
-            sz = g.DrawStringWithRoundedRectPerf("KCAL / MIN", _smallFont, x, y + margin * 1.5f, Brushes.Black,
-                Brushes.Lime, 2.5f);
+            sz = g.DrawStringWithRoundedRectPerf("HEART", _smallFont, x, y + margin * 1.5f, Brushes.Black, Brushes.White, 2.5f);
             x += sz.Width + margin * 2;
 
             sz = g.DrawStringWithOutline($"{CurrentMissed}", Font, x, y, Color.Black, Color.White);