Exemple #1
0
        private async void SetBpmValue(int bpmValue)
        {
            try
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    BpmValue = bpmValue;

                    var currentBpm = new HrModel
                    {
                        HeartRate = bpmValue,
                        PreviousMeasureHeartRate = bpmValue
                    };
                    if (_lastBpm != null)
                    {
                        currentBpm.PreviousMeasureHeartRate = _lastBpm.HeartRate;
                        currentBpm.PreviousMeasureTime      = _lastBpm.Time;
                    }
                    BpmCollection.Enqueue(currentBpm);
                    _lastBpm = currentBpm;
                });
            }
            catch (Exception exception)
            {
                var md = new MessageDialog(exception.ToString());
                await md.ShowAsync();
            }
        }
Exemple #2
0
        private void GenerateSampleData()
        {
            var rnd    = new Random();
            var myList = new List <HrModel>();

            var hr = new HrModel
            {
                Time      = 0,
                HeartRate = 65
            };

            myList.Add(hr);
            for (var i = 1; i < 100; i++)
            {
                hr = new HrModel
                {
                    Time      = i,
                    HeartRate = 70 + rnd.Next(5)
                };
                myList.Add(hr);
            }
            hr = new HrModel
            {
                Time      = 0,
                HeartRate = 90
            };
            myList.Add(hr);

            _lineSeries = LineChart.Series[0] as LineSeries;
            if (_lineSeries != null)
            {
                _lineSeries.ItemsSource = myList;
            }
        }
Exemple #3
0
        private async void DisplayHrData()
        {
            var myList = new List <HrModel>();

            for (var i = 0; i < 100; i++)
            {
                var hr = new HrModel {
                    Time = i
                };
                if (HrCollection.Count > i)
                {
                    hr.HeartRate = HrCollection[i].HeartRate;
                }
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                _lineSeries = LineChart.Series[0] as LineSeries;
                if (_lineSeries != null)
                {
                    _lineSeries.ItemsSource = myList;
                }
            });
        }
Exemple #4
0
        private void CalculateStressLevel()
        {
            var firstBpm = BpmCollection.FirstOrDefault();

            if (firstBpm == null)
            {
                return;
            }
            var currentBpm = BpmValue;
            var diffHr     = Math.Abs(currentBpm - firstBpm.HeartRate);

            if (diffHr > 3)
            {
                StressValue++;
                if (StressValue >= 8)
                {
                    StressValue = 8;
                    var doc = new XmlDocument();
                    doc.LoadXml(_notificationContent);
                    var notification = new TileNotification(doc)
                    {
                        ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(5)
                    };
                    TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
                }
            }
            else if (diffHr == 1 || diffHr == 2)
            {
            }
            else
            {
                StressValue--;
                if (StressValue < 3)
                {
                    StressValue = 3;
                }
            }


            // calculate stress level
            if (StressValue > 0 && StressValue < 5)
            {
                StressValueLevel = "Normal";
                TextBlockStressLevel.Foreground = new SolidColorBrush(Colors.LightGreen);
                _chartSeriesStress.Interior     = new SolidColorBrush(Colors.LightGreen);
            }
            else if (StressValue >= 5 && StressValue < 8)
            {
                StressValueLevel = "Moderate";
                TextBlockStressLevel.Foreground = new SolidColorBrush(Colors.Yellow);
                _chartSeriesStress.Interior     = new SolidColorBrush(Colors.Yellow);
            }
            else
            {
                StressValueLevel = "High";
                TextBlockStressLevel.Foreground = new SolidColorBrush(Colors.OrangeRed);
                _chartSeriesStress.Interior     = new SolidColorBrush(Colors.OrangeRed);
            }

            var item = new HrModel
            {
                Stress = StressValue,
                Time   = DateTime.Now
            };

            if (_observableCollectionStress.Count > HrCollectionCount)
            {
                _observableCollectionStress.RemoveAt(0);
            }
            _observableCollectionStress.Add(item);

            StressProcessingInformation = ($"Stress [{StressValue}] - Bpm: old {firstBpm.HeartRate} - current {BpmValue} - diff {diffHr} - time {firstBpm.Time:T}");
        }