public void setMyoValues(List <string> values) { if (isRecording) { var update = new FrameObject(startRecordingTime, myoNames, values); var updateChunk = new FrameObject(startChunkTime, myoNames, values); if (!values.SequenceEqual(lastValues)) { myMyoRecordingObject.Frames.Add(update); lastValues = values; if (!sendingData && myoChunk != null) { try { myoChunk.Frames.Add(updateChunk); } catch (System.IndexOutOfRangeException ex) { myoChunk = null; Console.WriteLine("System.IndexOutOfRangeException", updateChunk.ToString()); } } } } }
public void setFeedbackValues(List <string> feedbackNames, List <string> feedbackValues) { if (isRecording) { var update = new FrameObject(startRecordingTime, feedbackNames, feedbackValues); feedbackObject.Frames.Add(update); } }
public void setMyoValues(List <string> values) { if (isRecording) { var update = new FrameObject(startRecordingTime, myoNames, values); var updateChunk = new FrameObject(startChunkTime, myoNames, values); if (!values.SequenceEqual(lastValues)) { myMyoRecordingObject.Frames.Add(update); lastValues = values; if (!sendingData && myoChunk != null) { myoChunk.Frames.Add(updateChunk); } } } }
private void processFeedback(String feedbackString) { int noLastCC = 10; int feedbackFrequencyInSeconds = 10; int feedbackErrorRateThreshold = 50; int correctCCs = 0; double ratio = 0; double errorRate = 0; List <string> annotationNames = new List <string>(); List <string> annotationValues = new List <string>(); List <int> errorRates = new List <int>(); TimeSpan deltaFeedback; TimeSpan feedbackTimestamp; List <string> feedbackNames = new List <string>(); List <string> feedbackValues = new List <string>(); String worstTargetName = ""; Double worstTargetValue = 0; bool emptyResults = false; int value; try { dynamic jsonFeedback = JsonConvert.DeserializeObject(feedbackString); foreach (var property in jsonFeedback) { if (!targetList.ContainsKey(property.Name)) { targetList.Add(property.Name, new List <int>()); } if (int.TryParse(property.Value.Value.ToString(), out value)) { targetList[property.Name].Add((int)property.Value.Value); emptyResults = false; } else { //targetList[property.Name].Add(""); emptyResults = true; } // save the property names and values in the two lists annotationNames.Add(property.Name); annotationValues.Add((property.Value.Value).ToString()); } //sharpflowOutput.Content = ""; // set the annoation names and values in the annotation object lastCompression.setAnnotations(annotationNames, annotationValues); if (!emptyResults) { foreach (KeyValuePair <string, List <int> > target in targetList) { if (target.Value.Count() > noLastCC) { List <int> lastNCCs = Enumerable.Reverse(target.Value).Take(noLastCC).Reverse().ToList();; correctCCs = (from temp in lastNCCs where temp.Equals(1) select temp).Count(); ratio = (double)(correctCCs) / noLastCC; } else { correctCCs = (from temp in target.Value where temp.Equals(1) select temp).Count(); ratio = (double)(correctCCs) / target.Value.Count(); } errorRate = 100 - Math.Round((ratio * 100), 1); if (errorRate > worstTargetValue) { worstTargetValue = errorRate; worstTargetName = target.Key; } sharpflowOutput.Content += target.Key + " (err. " + (errorRate.ToString()) + "%) ";// + String.Join(", ", target.Value) + "\n"; } if (feedback_activated.IsChecked.HasValue) { if (feedback_activated.IsChecked.Value == true) { // check if feedbackFrequencyInSeconds are passed deltaFeedback = DateTime.Now.Subtract(lastFeedbackPrompted); if (deltaFeedback > TimeSpan.FromSeconds(feedbackFrequencyInSeconds) && worstTargetValue > feedbackErrorRateThreshold && compressionCounter > 5) { Console.WriteLine(feedbackFrequencyInSeconds.ToString() + " seconds are passed: " + deltaFeedback.TotalSeconds.ToString() + " worst target: " + worstTargetName + " target value: " + worstTargetValue.ToString()); feedbackTimestamp = DateTime.Now.Subtract(startRecordingTime); feedbackNames.Add("errorRate"); feedbackValues.Add((worstTargetValue / 100).ToString()); feedbackNames.Add("feedbackDevice"); feedbackValues.Add("audio"); feedbackNames.Add("targetClass"); feedbackValues.Add(worstTargetName); feedbackNames.Add("feedbackMessage"); feedbackValues.Add("feedback_" + worstTargetName + ".wav"); var update = new FrameObject(startRecordingTime, feedbackNames, feedbackValues); feedbackObject.Frames.Add(update); lastFeedbackPrompted = DateTime.Now; promptFeedback(worstTargetName, "audio"); } else { Console.WriteLine("10 seconds are NOT passed"); } } } } } catch { Console.WriteLine("Failed to process the feedback"); } }
public void setKinectValues(Body[] bodies) { if (isRecording) { int counter = 0; List <string> values = new List <string>(); KinectValues = new List <string>(); foreach (Body body in bodies) { try { if (body.IsTracked) { detectCompression(body.Joints[JointType.ShoulderRight].Position.Y); KinectValues.Add(body.Joints[JointType.AnkleRight].Position.X + ""); KinectValues.Add(body.Joints[JointType.AnkleRight].Position.Y + ""); KinectValues.Add(body.Joints[JointType.AnkleRight].Position.Z + ""); KinectValues.Add(body.Joints[JointType.AnkleLeft].Position.X + ""); KinectValues.Add(body.Joints[JointType.AnkleLeft].Position.Y + ""); KinectValues.Add(body.Joints[JointType.AnkleLeft].Position.Z + ""); KinectValues.Add(body.Joints[JointType.ElbowRight].Position.X + ""); KinectValues.Add(body.Joints[JointType.ElbowRight].Position.Y + ""); KinectValues.Add(body.Joints[JointType.ElbowRight].Position.Z + ""); KinectValues.Add(body.Joints[JointType.ElbowLeft].Position.X + ""); KinectValues.Add(body.Joints[JointType.ElbowLeft].Position.Y + ""); KinectValues.Add(body.Joints[JointType.ElbowLeft].Position.Z + ""); KinectValues.Add(body.Joints[JointType.HandRight].Position.X + ""); KinectValues.Add(body.Joints[JointType.HandRight].Position.Y + ""); KinectValues.Add(body.Joints[JointType.HandRight].Position.Z + ""); KinectValues.Add(body.Joints[JointType.HandLeft].Position.X + ""); KinectValues.Add(body.Joints[JointType.HandLeft].Position.Y + ""); KinectValues.Add(body.Joints[JointType.HandLeft].Position.Z + ""); KinectValues.Add(body.Joints[JointType.HandTipRight].Position.X + ""); KinectValues.Add(body.Joints[JointType.HandTipRight].Position.Y + ""); KinectValues.Add(body.Joints[JointType.HandTipRight].Position.Z + ""); KinectValues.Add(body.Joints[JointType.HandTipLeft].Position.X + ""); KinectValues.Add(body.Joints[JointType.HandTipLeft].Position.Y + ""); KinectValues.Add(body.Joints[JointType.HandTipLeft].Position.Z + ""); KinectValues.Add(body.Joints[JointType.Head].Position.X + ""); KinectValues.Add(body.Joints[JointType.Head].Position.Y + ""); KinectValues.Add(body.Joints[JointType.Head].Position.Z + ""); KinectValues.Add(body.Joints[JointType.HipRight].Position.X + ""); KinectValues.Add(body.Joints[JointType.HipRight].Position.Y + ""); KinectValues.Add(body.Joints[JointType.HipRight].Position.Z + ""); KinectValues.Add(body.Joints[JointType.HipLeft].Position.X + ""); KinectValues.Add(body.Joints[JointType.HipLeft].Position.Y + ""); KinectValues.Add(body.Joints[JointType.HipLeft].Position.Z + ""); KinectValues.Add(body.Joints[JointType.ShoulderRight].Position.X + ""); KinectValues.Add(body.Joints[JointType.ShoulderRight].Position.Y + ""); KinectValues.Add(body.Joints[JointType.ShoulderRight].Position.Z + ""); KinectValues.Add(body.Joints[JointType.ShoulderLeft].Position.X + ""); KinectValues.Add(body.Joints[JointType.ShoulderLeft].Position.Y + ""); KinectValues.Add(body.Joints[JointType.ShoulderLeft].Position.Z + ""); KinectValues.Add(body.Joints[JointType.SpineMid].Position.X + ""); KinectValues.Add(body.Joints[JointType.SpineMid].Position.Y + ""); KinectValues.Add(body.Joints[JointType.SpineMid].Position.Z + ""); KinectValues.Add(body.Joints[JointType.SpineShoulder].Position.X + ""); KinectValues.Add(body.Joints[JointType.SpineShoulder].Position.Y + ""); KinectValues.Add(body.Joints[JointType.SpineShoulder].Position.Z + ""); KinectValues.Add(volumeHandler.averageVolume.ToString()); if (body.Joints[JointType.ShoulderRight].Position.X != 0) { int xxx = counter; } var update = new FrameObject(startRecordingTime, kinectNames, KinectValues); myKinectRecordingObject.Frames.Add(update); if (compressionCounter > previousKinectCompressionCounter) { sendingData = true; // NEW LINES of CODE Thread thread = new Thread(new ThreadStart(sendChunk)); thread.Start(); //end of new lines of code //sendChunk(); //I just changed this uncomment this line in case the new solution does not work //String responseData; startChunkTime = DateTime.Now; myoChunk = new RecordingObject { RecordingID = startChunkTime.ToString("yyyy-MM-dd-HH-mm-sss"), ApplicationName = "Myo" }; kinectChunk = new RecordingObject { RecordingID = startChunkTime.ToString("yyyy-MM-dd-HH-mm-sss"), ApplicationName = "Kinect" }; previousKinectCompressionCounter = compressionCounter; //string gaugeImage = @"C:\Users\Daniele-WIN10\Documents\GitHub\SharpFlow\gauge.png"; //if (File.Exists(gaugeImage)) //{ // BitmapImage image = new BitmapImage(); // image.BeginInit(); // image.CacheOption = BitmapCacheOption.OnLoad; // image.CreateOptions = BitmapCreateOptions.IgnoreImageCache; // image.UriSource = new Uri(gaugeImage); // image.EndInit(); // cprGauge.Source = image; // cprGauge.Width = 500; //} } var newKinectChunk = new FrameObject(startChunkTime, kinectNames, KinectValues); kinectChunk.Frames.Add(newKinectChunk); //Console.WriteLine("Addded new kinectChunk: {0}", newKinectChunk.ToString()); } } catch { } counter++; } } }