Ejemplo n.º 1
0
        //Constractor
        public GestureDetector(KinectSensor _sensor, GestureAnalysis _gestureAnalysis, Exercise _currentExercise)
        {
            if (_sensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            if (_gestureAnalysis == null)
            {
                throw new ArgumentNullException("gestureResultView");
            }

            this._sensor = _sensor;
            this._gestureAnalysis = _gestureAnalysis;

            // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
            vgbFrameSource = new VisualGestureBuilderFrameSource(_sensor, 0);
            //vgbFrameSource.TrackingIdLost += Source_TrackingIdLost;

            // open the reader for the vgb frames
            vgbFrameReader = vgbFrameSource.OpenReader();
            if (this.vgbFrameReader != null)
            {
                vgbFrameReader.IsPaused = true;
                vgbFrameReader.FrameArrived += VgbFrameReader_FrameArrived;
            }

            // load all gestures from the gesture database
            if (File.Exists(_currentExercise.DBPath))
            {
                using (var database = new VisualGestureBuilderDatabase(_currentExercise.DBPath))
                {
                    vgbFrameSource.AddGestures(database.AvailableGestures);

                    //setup the continuous gesture
                    foreach (var gesture in database.AvailableGestures)
                    {
                        if (gesture.Name.Equals(_currentExercise.ContinuousGestureName))
                        {
                            ContinuousGestureData = gesture;
                            break;
                        }
                    }
                }

                //todo - implmnt gesture disable
                foreach (var gesutre in this.vgbFrameSource.Gestures)
                {
                    foreach (var notTrackGesture in _currentExercise.VTGestureList)
                    {
                        if (gesutre.Name.Equals(notTrackGesture.GestureName) && !notTrackGesture.IsTrack)
                        {
                            vgbFrameSource.SetIsEnabled(gesutre, false);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public GestureAnalysis(ref Exercise _currentExercise)
        {
            if (_currentExercise == null)
            {
                throw new ArgumentNullException("No exercise");
            }

            this.CurrentExercise = _currentExercise;
        }
        private List<Exercise> createDemoExercises()
        {
            List<Exercise> list = new List<Exercise>();

            for (int i = 1; i < 8; i++)
            {
                Exercise e = new Exercise();
                e.ExerciseName = "Body Posture " + i;
                e.ExerciseNum = i;
                e.Repetitions = 5;
                e.ExerciseThumbs = "../../Images/video1.jpg";

                list.Add(e);
            }

            return list;
        }
Ejemplo n.º 4
0
        ///<summary>
        ///update the exercise current motion score
        ///</summary>
        public static float GetExerciseMotionScore(Exercise CurrentExercise)
        {
            float avg = 0;
            int numOfSucces = 0;
            foreach (var round in CurrentExercise.Rounds)
            {
                if (round.RoundSuccess)
                {
                    avg += round.RoundMotionQuality;
                    numOfSucces++;
                }

            }

            avg /= numOfSucces;

            CurrentExercise.ExerciseMotionScore = Convert.ToInt32(avg);
            return avg;
        }
Ejemplo n.º 5
0
        public Exercise GetNextExercise()
        {
            //check if there are still exercises in the session
            if (!Playlist[currentSessionId].Last().Equals(CurrentExercise))
            {
                int i = Playlist[currentSessionId].IndexOf(CurrentExercise);

                if (i == -1 && SkipDemo)
                {
                    CurrentExercise = Playlist[currentSessionId][i + 2];
                }
                else
                {
                    CurrentExercise = Playlist[currentSessionId][i + 1];
                }
                
                return CurrentExercise;
            }

            //SumUpSession(currentSessionId);
            return GetNextSession();
            
        }
Ejemplo n.º 6
0
        private async void DownloadCurrentGDB(Exercise exercise, int key, Barrier downloadTrainingBarrier)
        {
            Console.WriteLine("S => Exercise id {0}, key = {1},  start at {2}", exercise.ExerciseId, key, DateTime.Now.ToString("hh:MM:ss.fff"));

            string json = await ApiConnection.GetExerciseGesturesApiAsync(exercise.ExerciseId);
            JSONConvertor.GettingExerciseGesture(exercise, json);

            using (DownloadCache dc = new DownloadCache(_currentPatient))
            {
                dc.DownloadGDBfile(exercise);
                exercise.Downloaded = true;
            }

            if (key == FIRST_EXERCISE) //use for the first gdb - that exercise window can be upload (after splash)
            {
                finishFirstGDBSemaphore.Release();
            }

            foreach (var item in _currentTraining.Playlist[key])
            {
                if (!item.isDemo && !item.Equals(exercise))
                {
                    item.DBPath = exercise.DBPath;
                    item.CopyGesturesFromOrigin(exercise);
                    item.Downloaded = true;
                }

            }

            Console.WriteLine("F => Exercise id {0}, key = {1},  finish at {2}", exercise.ExerciseId, key, DateTime.Now.ToString("hh:MM:ss.fff"));
            downloadTrainingBarrier.SignalAndWait();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Parse from json content to current patient training
        /// </summary>
        /// <param name="_JSONcontent">The response json</param>
        /// <param name="_training">The _training object</param>
        public static void GettingPatientTraining2(Training _training, string _JSONcontent)
        {
            dynamic d =
                    (JsonConvert.DeserializeObject<IDictionary<string, object>>(_JSONcontent));

            //checking errors
            bool checkError = checkForErrors((int)d["code"]);
            if (checkError)
            {
                ErrorEvent(null, new ErrorMessege(((ServerCode)d["code"].code).ToString(), (int)d["code"].code));
                return;
            }

            _training.Playlist = new Dictionary<int, List<Exercise>>();
            int numOfExercises = 1;

            //iterat over the exercise session
            foreach (var item in d["data"].sessions)
            {
                //Creating demo exercise
                Exercise demoExercise = new Exercise();
                demoExercise.ExerciseName = item.exerciseLabel;
                demoExercise.ExerciseId = item.exerciseId;
                demoExercise.ExerciseThumbs = item.exerciseThumbnail;
                string tt = item.exerciseVideoDemo;
                demoExercise.VideoPath = new Uri(HttpsReplaceToHttp.ReplaceHttpsToHttp(tt));
                demoExercise.ExerciseNum = numOfExercises;
                demoExercise.isDemo = true;
                demoExercise.SessionId = item.sessionId;
                demoExercise.Mode = Exercise.ExerciseMode.Demo;

                int temp = item.sessionId;
                _training.Playlist[temp] = new List<Exercise>();
                _training.Playlist[temp].Add(demoExercise);

                numOfExercises++;

                //duplicate the exercise if there are repeats for him by therapist
                //sessRepeats - number of duplicates exercise
                int x = item.sessRepeats;
                for (int i = 1; i <= x; i++)
                {
                    Exercise newExercise = new Exercise();

                    newExercise.ExerciseName = item.exerciseLabel;
                    newExercise.ExerciseId = item.exerciseId;
                    newExercise.ExerciseThumbs = item.exerciseThumbnail;
                    tt = item.exerciseVideo;
                    newExercise.VideoPath = new Uri(HttpsReplaceToHttp.ReplaceHttpsToHttp(tt));
                    newExercise.Repetitions = item.exerciseCycles;
                    newExercise.ExerciseNum = numOfExercises;
                    newExercise.SessionId = item.sessionId;
                    newExercise.IsTraceable = item.isTrackable;
                    newExercise.Mode = (bool) item.isTrackable ? Exercise.ExerciseMode.Traceable : Exercise.ExerciseMode.NonTraceable;

                    //todo - should be from server
                    newExercise.VideoComplianceValue = 2;
                    newExercise.SuccessRate = 0.5f;

                    //for future download for not duplicate the same file
                    if (i != 1)
                    {
                        newExercise.Mode = newExercise.Mode == Exercise.ExerciseMode.Traceable ? Exercise.ExerciseMode.TraceableDuplicate : Exercise.ExerciseMode.NonTraceableDuplicate;
                        newExercise.isDuplicate = true;
                    }
                    numOfExercises++;

                    _training.Playlist[temp].Add(newExercise);
                }

            }

            foreach (var exercises in _training.Playlist.Values)
            {
                if (exercises[1].IsTraceable)
                {
                    _training.IsTraceableTraining = true;
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parse from json content to exercise gestures details
        /// </summary>
        /// <param name="_JSONcontent">The response json</param>
        /// <param name="_exercise">The _exercise object</param>
        public static void GettingExerciseGesture(Exercise _exercise, string _JSONcontent)
        {
            dynamic d = (JsonConvert.DeserializeObject<IDictionary<string, object>>(_JSONcontent));

            //check errors
            bool checkError = checkForErrors((int)d["code"]);
            if (checkError)
            {
                ErrorEvent(null, new ErrorMessege(((ServerCode)d["code"].code).ToString(), (int)d["code"].code));
                return;
            }

            _exercise.ContinuousGestureName = d["data"].gesture_progress_name;
            _exercise.DBUrl = d["data"].file;

            _exercise.StartGesutre = new VTGesture();
            _exercise.StartGesutre.GestureName = Convert.ToString(d["data"].start_gesture_name);
            _exercise.StartGesutre.ConfidanceTrshold = 0.2f;

            string json = d["data"]["gesture_list"].ToString();
            List<object> gestureList = JsonConvert.DeserializeObject<List<object>>(json);

            //createing gestures list
            _exercise.VTGestureList = new List<VTGesture>();
            foreach (var item in gestureList)
            {
                VTGesture gesture = new VTGesture();

                json = item.ToString();
                Dictionary<string, object> currentObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);

                gesture.GestureName = currentObj["gestureName"].ToString();
                gesture.MinProgressValue = (float) Double.Parse(currentObj["startGestureValue"].ToString());
                gesture.MaxProgressValue = (float)Double.Parse(currentObj["endGestureValue"].ToString());
                gesture.TrsholdProgressValue = (float)Double.Parse(currentObj["progressThd"].ToString());
                gesture.ConfidanceTrshold = (float)Double.Parse(currentObj["confidenceThd"].ToString());
                gesture.IsTrack = currentObj["isTrackableItem"].ToString().Equals("1") ? true : false;

                _exercise.VTGestureList.Add(gesture);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Download the gdb file for the gesture detection
        /// <param name="_exercise">Current user patient</param>
        /// </summary>
        public void DownloadGDBfile(Exercise _exercise)
        {
            Barrier _barrier = new Barrier(1);

            string newDir = CreateDir(dir, "DB");
            newDir += "\\" + _exercise.ExerciseId + ".gdb";

            if (!File.Exists(newDir))
            {
                DownloadFile(_exercise.DBUrl, newDir);
                _barrier.SignalAndWait();
            }

            _exercise.DBPath = newDir;
        }
Ejemplo n.º 10
0
        public Exercise GetPrevExercise()
        {
            CurrentExercise.ClearAllDataInExercise();

            if (!Playlist[currentSessionId].First().Equals(CurrentExercise))
            {
                int i = Playlist[currentSessionId].IndexOf(CurrentExercise);

                if (i == 1 && SkipDemo)
                {
                    GetPrevSession();
                    CurrentExercise = Playlist[currentSessionId].Last();
                }
                else
                {
                    CurrentExercise = Playlist[currentSessionId][i - 1];
                }

                return CurrentExercise;
            }

            GetPrevSession();
            CurrentExercise = Playlist[currentSessionId].Last();
            return CurrentExercise;
        }
Ejemplo n.º 11
0
        public void ClearTrainingData()
        {
            foreach (var key in Playlist.Keys)
            {
                foreach (Exercise exercise in Playlist[key])
                {
                    if (!exercise.isDemo)
                    {
                        exercise.ClearAllDataInExercise();
                    }
                }
            }

            CurrentExercise = null;
            currentSessionId = 1;
        }
Ejemplo n.º 12
0
        public Exercise GetPrevSession()
        {
            CurrentExercise.ClearAllDataInExercise();

            if (currentSessionId == 1)
            {
                return CurrentExercise;
            }
            else
            {
                currentSessionId--;

                if (SkipDemo)
                {
                    CurrentExercise = Playlist[currentSessionId][1];
                }
                else
                {
                    CurrentExercise = Playlist[currentSessionId].First();
                }
                
                return CurrentExercise;
            }
        }
Ejemplo n.º 13
0
        public void CopyGesturesFromOrigin(Exercise copyFromExercise)
        {
            ContinuousGestureName = copyFromExercise.ContinuousGestureName;
            StartGesutre = new VTGesture(copyFromExercise.StartGesutre);

            VTGestureList = new List<VTGesture>();
            foreach (VTGesture gesture in copyFromExercise.VTGestureList)
            {
                VTGestureList.Add(new VTGesture(gesture));
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 
        /// <param name="_exerciseId">Active instance of the KinectSensor</param>
        /// </summary>
        public static async Task<string> ReportExerciseScoreApiAsync(Exercise exercise, Training training)
        {
            if (!training.CalEventId.Equals(""))
            {
                Dictionary<string, string> _pairs = PairsDictinaryForApi(ApiType.ReportExercise, "exerciseId", exercise.ExerciseId.ToString(), "numRepitionTotal", exercise.ExerciseScore.TotalRepetitions.ToString(),
                                                            "numRepitionDone", exercise.ExerciseScore.TotalRepetitionsDone.ToString(), "motionQuality", exercise.ExerciseScore.MoitionQuality.ToString(),
                                                            "calGuid", training.CalGuid, "calEventId", training.CalEventId);

                return await ConnectingApiAsync(_pairs);
            }

            return null;
        }