Пример #1
0
 public double InterpolateIntensity(double timePoint)
 {
     if (time != null && time.Count > 4)
     {
         if (interpole == null)
         {
             try
             {
                 //interpole = new MathNet.Numerics.Interpolation.Algorithms.CubicSplineInterpolation(time, intensityCount);
                 interpole = new MathNet.Numerics.Interpolation.Algorithms.AkimaSplineInterpolation(time, intensityCount);
                 //interpole = MathNet.Numerics.Interpolation.Interpolate.LinearBetweenPoints(time, intensityCount);
             }catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
             }
         }
         double intensity = interpole.Interpolate(timePoint);
         if (intensity < 0)
         {
             return(0);
         }
         else
         {
             return(intensity);
         }
     }
     return(0);
 }
Пример #2
0
        private void HRNodeClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            SplitContainer chartsplit = (SplitContainer)splitContainer2.Panel2.Controls["chartsplit"];
            Chart          chart1     = (Chart)chartsplit.Panel1.Controls["chart1"];

            Chart chart2 = (Chart)chartsplit.Panel2.Controls["chart2"];

            chart1.ChartAreas.Clear();
            chart2.ChartAreas.Clear();

            ChartArea area = new ChartArea("0");

            area.AxisX.Minimum           = 0;
            area.AxisX.Interval          = 3;
            area.AxisX.IntervalType      = DateTimeIntervalType.Number;
            area.AxisX.LabelStyle.Format = "#.##";
            chart1.ChartAreas.Add("0");
            chart2.ChartAreas.Add("1");

            TreeView tv = (TreeView)splitContainer2.Panel1.Controls[0];

            if (ModifierKeys.HasFlag(Keys.Control))
            {
                TreeNode selected = tv.SelectedNode;
                selected.BackColor = Color.Aqua;
            }
            else
            {
                chart1.Series.Clear();
                chart2.Series.Clear();
                foreach (TreeNode tn in tv.Nodes)
                {
                    tn.BackColor = Color.White;
                }
            }
            TreeNode node = e.Node;

            Series s = new Series();

            s.ChartType   = SeriesChartType.Line;
            s.BorderWidth = 3;
            HRWorkout hr = (HRWorkout)node.Tag;

            List <double> xarr = new List <double>();
            List <double> yarr = new List <double>();

            foreach (var samp in hr.exercises[0].samples.heartRate)
            {
                double x = (samp.dateTime - hr.startTime).TotalSeconds / 60;
                int    y = samp.value;
                xarr.Add(x);
                yarr.Add(y);
            }

            for (int i = 0; i < xarr.Count; i++)
            {
                DataPoint dp = new DataPoint();
                dp.SetValueXY(xarr[i], yarr[i]);
                dp.ToolTip = xarr[i].ToString("#.##") + " mins" + "\n" + yarr[i].ToString() + " bpm" + "\n" + node.Text;
                s.Points.Add(dp);
            }

            RemoveZeros(yarr);

            #region old
            //double sampRate = (double)xarr.Count / (xarr[xarr.Count - 1] * 60);

            //MathNet.Filtering.Median.OnlineMedianFilter filter =
            //    new MathNet.Filtering.Median.OnlineMedianFilter(17);

            //double[] filtered = filter.ProcessSamples(yarr.ToArray());

            //Series filteredHR = new Series();
            //filteredHR.ChartType = SeriesChartType.Line;
            //filteredHR.BorderWidth = 3;
            //filteredHR.Color = Color.Orange;

            //for (int i = 0; i < xarr.Count; i++)
            //{
            //    DataPoint dp = new DataPoint(xarr[i], filtered[i]);
            //    filteredHR.Points.Add(dp);
            //}
            //chart1.Series.Add(filteredHR);
            //chart2.Series.Add(SeriesDerivative(filteredHR, 100));
            #endregion

            MathNet.Numerics.Interpolation.IInterpolation interp = MathNet.Numerics.Interpolate.CubicSplineRobust(xarr, yarr);
            Series splineHR = new Series();
            splineHR.ChartType   = SeriesChartType.Line;
            splineHR.BorderWidth = 3;

            for (int i = 0; i < xarr.Count; i++)
            {
                DataPoint dp = new DataPoint(xarr[i], interp.Interpolate(xarr[i]));
                splineHR.Points.Add(dp);
            }

            Series sdiff = new Series();
            sdiff.ChartType   = SeriesChartType.Line;
            sdiff.BorderWidth = 3;

            for (int i = 0; i < xarr.Count; i++)
            {
                DataPoint dp = new DataPoint(xarr[i], interp.Differentiate(xarr[i]));
                sdiff.Points.Add(dp);
            }

            chart1.Series.Add(splineHR);
            chart2.Series.Add(sdiff);
        }