Ejemplo n.º 1
0
        public FrequencyStats(Trajectory trajectory, bool useSlope = false)
        {
            var xList = (useSlope) ? trajectory.slopes.Select(p => p.x).ToArray() : trajectory.points.Select(p => p.x).ToArray();
            var zList = (useSlope) ? trajectory.slopes.Select(p => p.z).ToArray() : trajectory.points.Select(p => p.z).ToArray();

            dataXList = DoubleArray.From(xList);
            dataZList = DoubleArray.From(zList);
            signal    = getSignal(dataXList, dataZList);
            getPxxFx(signal, trajectory.samplingRate, out Pxx, out Fx);

            //Discard values before 0.05 Hz (high pass filter)
            highPassFilter(Pxx, Fx, 0.05, out Pxx, out Fx);

            totalPower     = Pxx.Sum();
            F50            = getFn(Pxx, Fx, 0.5);
            F95            = getFn(Pxx, Fx, 0.95);
            centroidFreq   = getCentroidFreq(Pxx, Fx);
            FreqDispersion = getFreqDispersion(Pxx, Fx);
        }
        public override List <Tuple <Trajectory, ESegmentType> > segmentTrajectory(Trajectory trajectory)
        {
            List <Tuple <Trajectory, ESegmentType> > segments = new List <Tuple <Trajectory, ESegmentType> >();
            double closeThreshold = 1.5;
            double farThreshold   = 7.5;

            Double.TryParse(ConfigurationManager.AppSettings["SegmentedGaitFarThreshold"], out farThreshold);
            Double.TryParse(ConfigurationManager.AppSettings["SegmentedGaitCloseThreshold"], out closeThreshold);

            Trajectory t             = null;
            long       lastTimeStamp = -1000;
            int        pointNumber   = -1;

            foreach (var p in trajectory.points)
            {
                pointNumber++;
                if (p.z < closeThreshold)
                {
                    continue;
                }
                if (p.z > farThreshold)
                {
                    continue;
                }
                if (p.timeStamp - lastTimeStamp > 1000)
                {
                    if ((t != null) && (t.duratation() > 1.0))
                    {
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Walking));
                    }
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                t.add(p, trajectory.slopes[pointNumber]);
                lastTimeStamp = p.timeStamp;
            }
            if ((t != null) && (t.duratation() > 1.0))
            {
                segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Walking));
            }

            return(segments);
        }
Ejemplo n.º 3
0
        public Ellipse(Trajectory trajectory)
        {
            Point center = trajectory.mean();

            centerX = center.x;
            centerY = center.z;

            //Calculate area
            DoubleArray covMatrix     = trajectory.covariance();
            Eigen       eigen         = new Eigen(covMatrix);
            double      chisquare_val = 2.4477;
            DoubleArray eigenvalues   = (DoubleArray)eigen.D;

            a = chisquare_val * Math.Sqrt(eigenvalues.Max());
            b = chisquare_val * Math.Sqrt(eigenvalues.Min());
            //Calculate ellipse coordinate points
            DoubleArray eigenvectors        = (DoubleArray)eigen.V;
            DoubleArray largestEigenvector  = eigenvectors.Max(0);
            DoubleArray smallestEigenvector = eigenvectors.Min(0);

            angle = Math.Atan2(largestEigenvector[1], largestEigenvector[0]);
            //This angle is between -pi and pi.
            //Let's shift it such that the angle is between 0 and 2pi
            if (angle < 0)
            {
                angle = angle + 2 * Math.PI;
            }
            area      = Math.PI * a * b;
            perimeter = Math.PI / 2 * Math.Sqrt(2 * a * a + 2 * b * b);
            getEllipseSamplePoints(100);
            covMatrix.Dispose();
            eigenvalues.Dispose();
            eigenvectors.Dispose();
            largestEigenvector.Dispose();
            smallestEigenvector.Dispose();
        }
        public override List <Tuple <Trajectory, ESegmentType> > segmentTrajectory(Trajectory trajectory)
        {
            List <Tuple <Trajectory, ESegmentType> > segments = new List <Tuple <Trajectory, ESegmentType> >();
            var state        = Estate.Square1;
            var histerthesis = 0.1;

            if (!Double.TryParse(ConfigurationManager.AppSettings["FSSThreshold"], out double threshold))
            {
                threshold = 2.0;
            }

            Trajectory t = new Trajectory
            {
                samplingRate = trajectory.samplingRate
            };
            long trajectoryLength = trajectory.points.Count;

            for (int i = 0; i < trajectoryLength; i++)
            {
                var p     = trajectory.points[i];
                var slope = trajectory.slopes[i];

                Estate observedState = state;
                if (p.z > threshold && p.x > 0)
                {
                    observedState = Estate.Square1;
                }
                if (p.z < threshold && p.x > 0)
                {
                    observedState = Estate.Square2;
                }
                if (p.z < threshold && p.x < 0)
                {
                    observedState = Estate.Square3;
                }
                if (p.z > threshold && p.x < 0)
                {
                    observedState = Estate.Square4;
                }

                if (observedState != state)
                {
                    if (Math.Abs(p.x) > histerthesis || (Math.Abs(p.z - threshold) > histerthesis))
                    {
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, GetSegmentType(state)));
                        t = new Trajectory
                        {
                            samplingRate = trajectory.samplingRate
                        };
                        state = observedState;
                    }
                }
                t.add(p, slope);
            }

            if (t.points.Any())
            {
                segments.Add(new Tuple <Trajectory, ESegmentType>(t, GetSegmentType(state)));
                t = new Trajectory
                {
                    samplingRate = trajectory.samplingRate
                };
            }

            return(segments);
        }
Ejemplo n.º 5
0
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics       = new List <Metric>();
            double        totalDuration = 0.0;

            foreach (var segment in segments)
            {
                var duration = segment.Item1.duratation();
                totalDuration += duration;
                switch (segment.Item2)
                {
                case ESegmentType.StandingUp: metrics.Add(new Metric {
                        name = "Time to stand", value = duration
                    }); break;

                case ESegmentType.WalkingToSensor: metrics.Add(new Metric {
                        name = "Time to walk before turning", value = duration
                    }); break;

                case ESegmentType.Turning: metrics.Add(new Metric {
                        name = "Time to turn", value = duration
                    }); break;

                case ESegmentType.WalkingAwayFromSensor: metrics.Add(new Metric {
                        name = "Time to walk after turning", value = duration
                    }); break;

                case ESegmentType.SittingDown: metrics.Add(new Metric {
                        name = "Time to sit", value = duration
                    }); break;

                default: throw new Exception("unexpected segment type " + Enum.GetName(typeof(ESegmentType), segment.Item2));
                }
            }
            metrics.Add(new Metric
            {
                name  = "Total",
                value = totalDuration
            });

            return(metrics);
        }
Ejemplo n.º 6
0
        public override List <Tuple <Trajectory, ESegmentType> > segmentTrajectory(Trajectory trajectory)
        {
            var segments = new List <Tuple <Trajectory, ESegmentType> >();

            var closeThreshold = 2.5;
            var farThreshold   = 4.5;
            var hysteresis     = 0.05;
            var sittingZSlope  = 0.4;

            Double.TryParse(ConfigurationManager.AppSettings["TUGcloseThreshold"], out closeThreshold);
            Double.TryParse(ConfigurationManager.AppSettings["TUGfarThreshold"], out farThreshold);
            Double.TryParse(ConfigurationManager.AppSettings["TUGhysteresis"], out hysteresis);
            double sittingZAngle;

            if (Double.TryParse(ConfigurationManager.AppSettings["TUGsittingZAngle"], out sittingZAngle))
            {
                sittingZSlope = Math.Sin(sittingZAngle * Math.PI / 180);
            }
            Estate     state = Estate.Stand;
            Trajectory t     = new Trajectory();

            t.samplingRate = trajectory.samplingRate;
            long trajectoryLength = trajectory.points.Count;

            for (int i = 0; i < trajectoryLength; i++)
            {
                var p     = trajectory.points[i];
                var slope = trajectory.slopes[i];

                if (p.z < farThreshold && state == Estate.Stand)
                {
                    state = Estate.GettingCloser;
                    segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.StandingUp));
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                if (p.z < closeThreshold - hysteresis && state == Estate.GettingCloser)
                {
                    state = Estate.Turning;
                    segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.WalkingToSensor));
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                if (p.z > closeThreshold + hysteresis && state == Estate.Turning)
                {
                    state = Estate.GoingAway;
                    segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Turning));
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                if (p.z > farThreshold && state == Estate.GoingAway)
                {
                    state = Estate.Sitting;
                    segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.WalkingAwayFromSensor));
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                if (state == Estate.Sitting)
                {
                    if (slope.z > sittingZSlope)
                    {
                        state = Estate.Done;
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.SittingDown));
                        t = new Trajectory();
                        t.samplingRate = trajectory.samplingRate;
                    }
                }

                t.add(p, slope);
            }
            if (state == Estate.Sitting)
            {
                segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.SittingDown));
                t = new Trajectory();
                t.samplingRate = trajectory.samplingRate;
            }
            return(segments);
        }
Ejemplo n.º 7
0
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics             = new List <Metric>();
            var           turningTrajectories = segments.Where(s => s.Item2 == ESegmentType.Turning).Select(s => s.Item1).ToList();
            var           walkingTrajectories = segments.Where(s => s.Item2 == ESegmentType.Walking).Select(s => s.Item1).ToList();

            metrics.Add(new Metric
            {
                name  = "Turns",
                value = turningTrajectories.Count
            });
            metrics.Add(new Metric
            {
                name  = "Turn time",
                value = turningTrajectories.Select(trj => trj.duratation()).Median()
            });

            metrics.Add(new Metric
            {
                name  = "Walks",
                value = walkingTrajectories.Count
            });
            metrics.Add(new Metric
            {
                name  = "Walk time",
                value = walkingTrajectories.Select(trj => trj.duratation()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "COM distance",
                value = trajectory.pathLength()
            });
            if (!walkingTrajectories.Any())
            {
                return(metrics);
            }
            metrics.Add(new Metric
            {
                name  = "Velocity",
                value = walkingTrajectories.Select(segment => segment.pathLength() / segment.duratation()).Median()
            });

            metrics.Add(new Metric
            {
                name  = "Walking efficiency",
                value = walkingTrajectories.Select(trj => trj.efficiency()).Median()
            });

            var normalizedWalkingTrajectories = walkingTrajectories.Select(trj => normalizeTrajectory(trj, ESegmentType.Walking)).ToList();

            metrics.Add(new Metric
            {
                name  = "Lateral sway",
                value = normalizedWalkingTrajectories.Select(trj => trj.lateralDeviation()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "Temporal sway",
                value = normalizedWalkingTrajectories.Select(trj => trj.ventralDeviation()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "Total sway",
                value = normalizedWalkingTrajectories.Select(trj => trj.totalDeviation()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "RMS",
                value = normalizedWalkingTrajectories.Select(trj => trj.RMS()).Median()
            });
            var ellipses = normalizedWalkingTrajectories.Select(trj => new Ellipse(trj)).ToList();

            metrics.Add(new Metric
            {
                name  = "Area",
                value = ellipses.Select(e => e.area).Median()
            });
            metrics.Add(new Metric
            {
                name  = "Range A",
                value = ellipses.Select(e => e.a * 2).Median()
            });
            metrics.Add(new Metric
            {
                name  = "Range B",
                value = ellipses.Select(e => e.b * 2).Median()
            });
            var fftStats = walkingTrajectories.Select(trj => new FFTStats(trj, FFTStats.EDirection.Z, true)).ToList();

            metrics.Add(new Metric
            {
                name  = "step duration",
                value = fftStats.Select(stat => 1.0 / stat.GetPeekFrequency()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "step length",
                value = fftStats.Zip(walkingTrajectories, (stat, trj) => trj.progressLength() / (stat.GetPeekFrequency() * trj.duratation())).Median()
            });


            //var freqMetrics = normalizedWalkingTrajectories.Select(trj => new FrequencyStats(trj)).ToList();
            //metrics.Add(new Metric
            //{
            //    name = "PWR",
            //    value = freqMetrics.Select(f => f.totalPower).Median()
            //});

            //metrics.Add(new Metric
            //{
            //    name = "F50",
            //    value = freqMetrics.Select(f => f.F50).Median()
            //});

            //metrics.Add(new Metric
            //{
            //    name = "F95",
            //    value = freqMetrics.Select(f => f.F95).Median()
            //});

            //metrics.Add(new Metric
            //{
            //    name = "Centroid Freq",
            //    value = freqMetrics.Select(f => f.centroidFreq).Median()
            //});

            //metrics.Add(new Metric
            //{
            //    name = "Freq Dispersion",
            //    value = freqMetrics.Select(f => f.FreqDispersion).Median()
            //});
            //double freq = metrics.Where(m => m.name == "Centroid Freq").First().value;
            //double velocity = metrics.Where(m => m.name == "Velocity").First().value;

            //metrics.Add(new Metric
            //{
            //    name = "Stirde Length",
            //    value = velocity / freq
            //});
            return(metrics);
        }
Ejemplo n.º 8
0
        public override List <Tuple <Trajectory, ESegmentType> > segmentTrajectory(Trajectory trajectory)
        {
            List <Tuple <Trajectory, ESegmentType> > segments = new List <Tuple <Trajectory, ESegmentType> >();
            var state          = Estate.GoingAway;
            var closeThreshold = 2.5;
            var farThreshold   = 6.5;
            var hysteresis     = 0.05;

            Double.TryParse(ConfigurationManager.AppSettings["closeThreshold"], out closeThreshold);
            Double.TryParse(ConfigurationManager.AppSettings["farThreshold"], out farThreshold);
            Double.TryParse(ConfigurationManager.AppSettings["hysteresis"], out hysteresis);
            string initialState = ConfigurationManager.AppSettings["initialState"];

            switch (initialState)
            {
            case "GettingCloser": state = Estate.GettingCloser; break;

            case "GoingAway": state = Estate.GoingAway; break;

            case "TurningClose": state = Estate.TurningClose; break;

            case "TurningFar": state = Estate.TurningFar; break;
            }
            Trajectory t = new Trajectory();

            t.samplingRate = trajectory.samplingRate;
            int pointNumber = -1;

            foreach (var p in trajectory.points)
            {
                pointNumber++;
                if (p.z < closeThreshold - hysteresis && state == Estate.GettingCloser)
                {
                    state = Estate.TurningClose;
                    if (t.duratation() > 0)
                    {
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Walking));
                    }
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                else if (p.z > farThreshold + hysteresis && state == Estate.GoingAway)
                {
                    state = Estate.TurningFar;
                    if (t.duratation() > 0)
                    {
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Walking));
                    }
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                else if (p.z > closeThreshold + hysteresis && state == Estate.TurningClose)
                {
                    state = Estate.GoingAway;
                    if (t.duratation() > 0)
                    {
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Turning));
                    }
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                else if (p.z < farThreshold - hysteresis && state == Estate.TurningFar)
                {
                    state = Estate.GettingCloser;
                    if (t.duratation() > 0)
                    {
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Turning));
                    }
                    t = new Trajectory();
                    t.samplingRate = trajectory.samplingRate;
                }
                t.add(p, trajectory.slopes[pointNumber]);
            }
            return(segments);
        }
Ejemplo n.º 9
0
 public abstract List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory);
Ejemplo n.º 10
0
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics = new List <Metric>();

            Ellipse ellipse = new Ellipse(trajectory);


            //Time domain stats
            metrics.Add(new Metric
            {
                name  = "Lateral sway",
                value = trajectory.lateralDeviation()
            });
            metrics.Add(new Metric
            {
                name  = "Ventral sway",
                value = trajectory.ventralDeviation()
            });

            metrics.Add(new Metric
            {
                name  = "Median Dist",
                value = trajectory.totalDeviation()
            });

            metrics.Add(new Metric
            {
                name  = "RMS",
                value = trajectory.RMS()
            });

            metrics.Add(new Metric
            {
                name  = "Area",
                value = ellipse.area
            });

            metrics.Add(new Metric
            {
                name  = "Range A",
                value = ellipse.a * 2
            });

            metrics.Add(new Metric
            {
                name  = "Range B",
                value = ellipse.b * 2
            });

            metrics.Add(new Metric
            {
                name  = "Median Lateral Angle",
                value = (Math.Asin(trajectory.slopes.Select(p => p.x).Median()) * 180 / Math.PI)
            });

            metrics.Add(new Metric
            {
                name  = "Median Ventral Angle",
                value = (Math.Asin(trajectory.slopes.Select(p => p.z).Median()) * 180 / Math.PI)
            });

            //Frequency domain stats
            var freqMetrics = new FrequencyStats(trajectory);

            metrics.Add(new Metric
            {
                name  = "PWR",
                value = freqMetrics.totalPower
            });

            metrics.Add(new Metric
            {
                name  = "F50",
                value = freqMetrics.F50
            });

            metrics.Add(new Metric
            {
                name  = "F95",
                value = freqMetrics.F95
            });

            metrics.Add(new Metric
            {
                name  = "Centroid Freq",
                value = freqMetrics.centroidFreq
            });

            metrics.Add(new Metric
            {
                name  = "Freq Dispersion",
                value = freqMetrics.FreqDispersion
            });
            return(metrics);
        }
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > anotatedSegments, Trajectory trajectory)
        {
            List <Metric>     metrics  = new List <Metric>();
            List <Trajectory> segments = anotatedSegments.Select(s => s.Item1).ToList();

            metrics.Add(new Metric
            {
                name  = "Segments",
                value = segments.Count
            });
            int segmentCounter = 0;

            foreach (var segment in segments)
            {
                segmentCounter++;
                string segmentString = String.Format("#{0,5}", segmentCounter);
                metrics.Add(new Metric
                {
                    name  = "Walk time" + segmentString,
                    value = segment.duratation()
                });
                metrics.Add(new Metric
                {
                    name  = "COM distance" + segmentString,
                    value = segment.pathLength()
                });

                metrics.Add(new Metric
                {
                    name  = "Velocity" + segmentString,
                    value = segment.pathLength() / segment.duratation()
                });
                metrics.Add(new Metric
                {
                    name  = "Walking efficiency" + segmentString,
                    value = segment.efficiency()
                });

                var normalizedWalkingTrajectorie = normalizeTrajectory(segment, ESegmentType.Walking);
                metrics.Add(new Metric
                {
                    name  = "Lateral sway" + segmentString,
                    value = normalizedWalkingTrajectorie.lateralDeviation()
                });
                metrics.Add(new Metric
                {
                    name  = "Temporal sway" + segmentString,
                    value = normalizedWalkingTrajectorie.ventralDeviation()
                });
                metrics.Add(new Metric
                {
                    name  = "Total sway" + segmentString,
                    value = normalizedWalkingTrajectorie.totalDeviation()
                });
                metrics.Add(new Metric
                {
                    name  = "RMS" + segmentString,
                    value = normalizedWalkingTrajectorie.RMS()
                });
                var ellipse = new Ellipse(segment);
                metrics.Add(new Metric
                {
                    name  = "Area" + segmentString,
                    value = ellipse.area
                });
                metrics.Add(new Metric
                {
                    name  = "Range A" + segmentString,
                    value = ellipse.a * 2
                });
                metrics.Add(new Metric
                {
                    name  = "Range B" + segmentString,
                    value = ellipse.b * 2
                });
                //var freqMetric = new FrequencyStats(segment, true);
                ////var freqMetric = new FrequencyStats(normalizedWalkingTrajectorie);
                //metrics.Add(new Metric
                //{
                //    name = "PWR" + segmentString,
                //    value = freqMetric.totalPower
                //});
                //metrics.Add(new Metric
                //{
                //    name = "F50" + segmentString,
                //    value = freqMetric.F50
                //});

                //metrics.Add(new Metric
                //{
                //    name = "F95" + segmentString,
                //    value = freqMetric.F95
                //});

                //metrics.Add(new Metric
                //{
                //    name = "Centroid Freq" + segmentString,
                //    value = freqMetric.centroidFreq
                //});

                //metrics.Add(new Metric
                //{
                //    name = "Freq Dispersion" + segmentString,
                //    value = freqMetric.FreqDispersion
                //});
                var fftStats = new FFTStats(segment, FFTStats.EDirection.Z, true);
                var stepFreq = fftStats.GetPeekFrequency();
                metrics.Add(new Metric
                {
                    name  = "step duration" + segmentString,
                    value = 1 / stepFreq
                });
                metrics.Add(new Metric
                {
                    name  = "step length" + segmentString,
                    value = segment.progressLength() / (stepFreq * segment.duratation())
                });
            }
            return(metrics);
        }
Ejemplo n.º 12
0
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics              = new List <Metric>();
            List <double> timeToStandDuration  = new List <double>();
            List <double> timeStandingDuration = new List <double>();
            List <double> timeToSitDuration    = new List <double>();
            List <double> timeSittingDuration  = new List <double>();
            List <double> timeTotalDuration    = new List <double>();

            List <double> minSlopeZList = new List <double>();
            List <double> maxSlopeZList = new List <double>();


            double totalDuration = 0.0;


            foreach (var segment in segments)
            {
                var duration = segment.Item1.duratation();
                totalDuration += duration;
                var minSlopeZ = 0.0;
                var maxSlopeZ = 0.0;

                switch (segment.Item2)
                {
                case ESegmentType.StandingUp: timeToStandDuration.Add(duration);
                    foreach (var slope in segment.Item1.leans)
                    {
                        if (maxSlopeZ < slope.z)
                        {
                            maxSlopeZ = slope.z;
                        }
                    }
                    maxSlopeZList.Add(maxSlopeZ);
                    break;

                case ESegmentType.Sitting: timeSittingDuration.Add(duration);
                    foreach (var slope in segment.Item1.leans)
                    {
                        if (minSlopeZ < slope.z)
                        {
                            minSlopeZ = slope.z;
                        }
                    }
                    minSlopeZList.Add(minSlopeZ);
                    break;

                case ESegmentType.Standing: timeStandingDuration.Add(duration); break;

                case ESegmentType.SittingDown: timeToSitDuration.Add(duration); break;

                default: throw new Exception("unexpected segment type " + Enum.GetName(typeof(ESegmentType), segment.Item2));
                }
            }


            metrics.Add(new Metric {
                name = "MedianTimeToStand", value = timeToStandDuration.Median()
            });
            metrics.Add(new Metric {
                name = "MedianTimeStanding", value = timeStandingDuration.Median()
            });
            metrics.Add(new Metric {
                name = "MedianTimeToSit", value = timeToSitDuration.Median()
            });
            metrics.Add(new Metric {
                name = "MedianTimeSitting", value = timeSittingDuration.Median()
            });

            metrics.Add(new Metric {
                name = "MedianMinSlope", value = minSlopeZList.Median()
            });
            metrics.Add(new Metric {
                name = "MedianMaxSlope", value = maxSlopeZList.Median()
            });

            metrics.Add(new Metric {
                name = "NumberOfTimes", value = timeToSitDuration.Count
            });

            double totalDurationAvg = (totalDuration / timeStandingDuration.Count);

            metrics.Add(new Metric
            {
                name  = "Total",
                value = totalDurationAvg
            });

            return(metrics);
        }
Ejemplo n.º 13
0
        public override List <Tuple <Trajectory, ESegmentType> > segmentTrajectory(Trajectory trajectory)
        {
            var segments = new List <Tuple <Trajectory, ESegmentType> >();



            Double.TryParse(ConfigurationManager.AppSettings["CHAIRSTANDhysteresis"], out double hysteresis);

            Double.TryParse(ConfigurationManager.AppSettings["CHAIRSTANDsittingZAngle"], out double sittingZAngle);

            Double.TryParse(ConfigurationManager.AppSettings["CHAIRSTANDstandingZAngle"], out double standingZAngle);

            Double.TryParse(ConfigurationManager.AppSettings["CHAIRSTANDsittingDownZAngle"], out double sittingDownZAngle);

            Double.TryParse(ConfigurationManager.AppSettings["CHAIRSTANDstandingUpZAngle"], out double standingUpZAngle);

            Estate     state = Estate.Sitting;
            Trajectory t     = new Trajectory
            {
                samplingRate = trajectory.samplingRate
            };
            long trajectoryLength = trajectory.points.Count;

            for (int i = 0; i < trajectoryLength; i++)
            {
                var p      = trajectory.points[i];
                var slope  = trajectory.slopes[i];
                var lean   = trajectory.leans[i];
                var slopeZ = Math.Asin(slope.z) * 180 / Math.PI;

                switch (state)
                {
                case Estate.Standing:
                    if (slopeZ > sittingDownZAngle)
                    {
                        state = Estate.SittingDown;
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Standing));
                        t = new Trajectory
                        {
                            samplingRate = trajectory.samplingRate
                        };
                    }
                    break;

                case Estate.SittingDown:
                    if (slopeZ > sittingZAngle)
                    {
                        state = Estate.Sitting;
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.SittingDown));
                        t = new Trajectory
                        {
                            samplingRate = trajectory.samplingRate
                        };
                    }
                    break;

                case Estate.Sitting:
                    if (slopeZ < standingUpZAngle)
                    {
                        state = Estate.StandingUp;
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.Sitting));
                        t = new Trajectory
                        {
                            samplingRate = trajectory.samplingRate
                        };
                    }
                    break;

                case Estate.StandingUp:
                    if (slopeZ < standingZAngle)
                    {
                        state = Estate.Standing;
                        segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.StandingUp));
                        t = new Trajectory
                        {
                            samplingRate = trajectory.samplingRate
                        };
                    }
                    break;
                }

                t.add(p, slope, lean);
            }
            if (state == Estate.SittingDown)
            {
                segments.Add(new Tuple <Trajectory, ESegmentType>(t, ESegmentType.SittingDown));
                t = new Trajectory
                {
                    samplingRate = trajectory.samplingRate
                };
            }
            return(segments);
        }
Ejemplo n.º 14
0
 public abstract List <Tuple <Trajectory, ESegmentType> > segmentTrajectory(Trajectory trajectory);
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics             = new List <Metric>();
            double        totalDuration       = 0.0;
            var           walkingTrajectories = segments.Where(s => s.Item2 == ESegmentType.Square1 ||
                                                               s.Item2 == ESegmentType.Square2 ||
                                                               s.Item2 == ESegmentType.Square3 ||
                                                               s.Item2 == ESegmentType.Square4
                                                               ).Select(s => s.Item1).ToList();

            metrics.Add(new Metric {
                name = "Time walking forward to square 2", value = segments[0].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking right to square 3", value = segments[1].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking backwards to square 4", value = segments[2].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking left to square 1", value = segments[3].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking right to square 4", value = segments[4].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking forward to square 3", value = segments[5].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking left to square 2", value = segments[6].Item1.duratation()
            });
            metrics.Add(new Metric {
                name = "Time walking backwards to square 1", value = segments[7].Item1.duratation()
            });

            for (int i = 0; i < 8; i++)
            {
                totalDuration += segments[i].Item1.duratation();
            }

            metrics.Add(new Metric
            {
                name  = "Total",
                value = totalDuration
            });

            var normalizedWalkingTrajectories = walkingTrajectories.Select(trj => normalizeTrajectory(trj, ESegmentType.Walking)).ToList();

            metrics.Add(new Metric
            {
                name  = "Lateral sway",
                value = normalizedWalkingTrajectories.Select(trj => trj.lateralDeviation()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "Temporal sway",
                value = normalizedWalkingTrajectories.Select(trj => trj.ventralDeviation()).Median()
            });
            metrics.Add(new Metric
            {
                name  = "Total sway",
                value = normalizedWalkingTrajectories.Select(trj => trj.totalDeviation()).Median()
            });

            return(metrics);
        }
Ejemplo n.º 16
0
        public override List <Metric> getMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics = new List <Metric>();

            Ellipse ellipse = new Ellipse(trajectory);

            var startValueExtreamZ = trajectory.extreams.Take(10).Min(p => p.minZ);
            var reachValueExtreamZ = trajectory.extreams.Min(p => p.minZ);

            //Time domain stats
            metrics.Add(new Metric
            {
                name  = "Reach distance",
                value = startValueExtreamZ - reachValueExtreamZ
            });

            metrics.Add(new Metric
            {
                name  = "Ventral sway",
                value = trajectory.ventralDeviation()
            });

            return(metrics);
        }
Ejemplo n.º 17
0
        private List <Metric> analyzeSharedMetrics(List <Tuple <Trajectory, ESegmentType> > segments, Trajectory trajectory)
        {
            List <Metric> metrics = new List <Metric>();

            //Time domain stats
            metrics.Add(new Metric
            {
                name  = "Duration",
                value = trajectory.duratation()
            });

            metrics.Add(new Metric
            {
                name  = "Frames Per Second",
                value = segments.Sum(s => s.Item1.points.Count) / segments.Sum(s => s.Item1.duratation())
            });

            return(metrics);
        }