private void Page_Loaded(object sender, RoutedEventArgs e) { _recorder.Start(); //recording for walking exercise always begins at window open Instructions.Text = "Make sure your whole body is visible, then turn right and walk"; _timer.Start(); startTime = DateTime.Now; //Set duration of data recording based on settings if (Application.Current.Properties["durationUnit"].ToString() == "seconds") { float seconds = float.Parse(Application.Current.Properties["duration"].ToString()); if (seconds == Math.Floor(seconds)) //if no decimals { duration = new TimeSpan(0, 0, Convert.ToInt32(seconds)); } else { duration = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(1000 * seconds)); //convert to milliseconds } } else //duration in minutes { float minutes = float.Parse(Application.Current.Properties["duration"].ToString()); if (minutes == Math.Floor(minutes)) //if no decimals { duration = new TimeSpan(0, Convert.ToInt32(minutes), 0); } else { duration = new TimeSpan(0, 0, Convert.ToInt32(60 * minutes)); } } }
void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var reference = e.FrameReference.AcquireFrame(); // Color using (var frame = reference.ColorFrameReference.AcquireFrame()) { if (frame != null) { if (viewer.Visualization == Visualization.Color) { viewer.Image = frame.ToBitmap(); } } } // Body using (var frame = reference.BodyFrameReference.AcquireFrame()) { if (frame != null) { var bodies = frame.Bodies(); _userReporter.Update(bodies); Body body = bodies.Closest(); if (body != null) { viewer.DrawBody(body, 15, Brushes.White, 8, Brushes.Aqua); _gesture.Update(body); if (_recorder.IsRecording) { _recorder.Update(body); DateTime currentT = DateTime.Now; TimeSpan elapsed = currentT - startTime; //Stop recording if duration is not default (0) and reached duration if (Application.Current.Properties["duration"].ToString() != "0") { if (elapsed >= duration) { _recorder.IsRecording = false; } } } //Display remaining repititions SittingCount.Text = sittingCounter.ToString(); Instructions.Text = "Raise your right arm above your head to begin this exercise"; if (body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.Head].Position.Y) { begin = true; //If data recording set to begin at exercise start, start recording when begin if (Application.Current.Properties["beginAtExerciseStart"].ToString() == "True" && !dataSaved && !_recorder.IsRecording) { _recorder.Start(); } } if (begin) { // knee height close to hip height if (body.Joints[JointType.HipLeft].Position.Y <= body.Joints[JointType.KneeLeft].Position.Y + .2) { //Update instructions Instructions.Text = "Stand up with your arms forward"; if (current == 1) { sittingCounter--; } current = 2; } else { //Update instructions Instructions.Text = "Sit down with your arms forward"; current = 1; } if (sittingCounter == 0) //end of exercise. Save node data { begin = false; Instructions.Text = "You have completed this exercise!"; _timer.Stop(); if (!dataSaved) { _recorder.Stop(); SaveFileDialog dialog = new SaveFileDialog { Filter = "Excel files|*.csv" }; dialog.ShowDialog(); if (!string.IsNullOrWhiteSpace(dialog.FileName)) { System.IO.File.Copy(_recorder.Result, dialog.FileName, true); } //Write data for report generation string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\..\UserData\SittingReportData.csv"); // This text is added only once to the file. if (!File.Exists(path)) { // Record duration and date of exercise using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("ExerciseDuration,Date"); sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d")); } } else { // This text is always added, making the file longer over time // if it is not deleted. using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d")); } } dataSaved = true; } } } } } } }
void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var reference = e.FrameReference.AcquireFrame(); // Color using (var frame = reference.ColorFrameReference.AcquireFrame()) { if (frame != null) { if (viewer.Visualization == Visualization.Color) { viewer.Image = frame.ToBitmap(); } } } // Body using (var frame = reference.BodyFrameReference.AcquireFrame()) { if (frame != null) { var bodies = frame.Bodies(); _userReporter.Update(bodies); Body body = bodies.Closest(); if (body != null) { viewer.DrawBody(body, 15, Brushes.White, 8, Brushes.Aqua); // Draw the Arm Angles rightArmAngle.Update(body.Joints[_startRight], body.Joints[_centerRight], body.Joints[_endRight], 100); leftArmAngle.Update(body.Joints[_startLeft], body.Joints[_centerLeft], body.Joints[_endLeft], 100); if (rcounter < startreps && onRightArmRaise) { //If data recording set to begin at exercise start, start recording after first rep if (rcounter == startreps - 1 && Application.Current.Properties["beginAtExerciseStart"].ToString() == "True" && !dataSaved && !_recorder.IsRecording) { _recorder.Start(); } } _gesture.Update(body); _gesture2.Update(body); if (_recorder.IsRecording) { _recorder.Update(body); DateTime current = DateTime.Now; TimeSpan elapsed = current - startTime; //Stop recording if duration is not default (0) and reached duration if (Application.Current.Properties["duration"].ToString() != "0") { if (elapsed >= duration) { _recorder.IsRecording = false; } } } if (onRightArmRaise) { Instructions.Text = "Raise your right arm above your head"; //Display remaining repititions ArmRaiseCount.Text = rcounter.ToString(); //Display arm angle value tblAngle.Text = ((int)rightArmAngle.Angle).ToString(); } else { //Update instructions Instructions.Text = "Raise your left arm above your head"; //Display arm angle value pageTitle.Text = "Left Arm Angle:"; tblAngle.Text = ((int)leftArmAngle.Angle).ToString(); //Display remaining repetitions ArmRaiseCount.Text = lcounter.ToString(); } if (lcounter == 0) //end of exercise. Save node data { Instructions.Text = "You have completed this exercise!"; _timer.Stop(); if (!dataSaved) { _recorder.Stop(); SaveFileDialog dialog = new SaveFileDialog { Filter = "Excel files|*.csv" }; dialog.ShowDialog(); if (!string.IsNullOrWhiteSpace(dialog.FileName)) { System.IO.File.Copy(_recorder.Result, dialog.FileName, true); } //Write data for report generation string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\UserData\ArmRaisesReportData.csv"); // This text is added only once to the file. if (!File.Exists(path)) { // Record duration and date of exercise using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("ExerciseDuration,Date"); sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d")); } } // This text is always added, making the file longer over time // if it is not deleted. else { using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d")); } } dataSaved = true; } } } } } }