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(); } }
private void UpdateBpmCollection() { var i = 0; foreach (var source in BpmCollection.ToList()) { i++; source.TimeInt = i; } }
private void UpdateBpmCollection() { var i = 0; if (_observableCollectionBpm == null) { _observableCollectionBpm = new DiagramCollection <HrModel>(); } _observableCollectionBpm.Clear(); foreach (var source in BpmCollection.ToList()) { i++; source.TimeInt = i; _observableCollectionBpm.Add(source); } }
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}"); }