Exemplo n.º 1
0
        public void AvgMtrPerSecondRnd_ShouldCalculate(double distance, DateTime startTime, DateTime endTime, double expected)
        {
            //Act
            Speed  speed  = new Speed(distance, startTime, endTime);
            double actual = speed.AvgMtrPerSecondRnd();

            //Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to populate form elements with activity statistics
        /// </summary>
        private void PopulateActivityStats()
        {
            int playerID = Convert.ToInt16(playerCombo.SelectedValue.ToString());
            int gameID   = Convert.ToInt16(dateCombo.SelectedValue.ToString());

            List <TimeLine> matchedTimeLineRecords = Search.Instance.FindMatchingTimeLines(gameID, playerID);

            if (matchedTimeLineRecords.Count() != 0)
            {
                using (DataClassesDataContext dbContext = new DataClassesDataContext())
                {
                    Option options = dbContext.Options.Where(o => o.Id.Equals(4)).SingleOrDefault();

                    //calculate total distance and display
                    double totalDistance = Calculations.Instance.CalcTotalDistance(matchedTimeLineRecords);
                    distanceLbl.Text = string.Format("{0} m", Math.Round(totalDistance, 2));

                    //calculate velocity and display
                    Speed  speed = new Speed(totalDistance, matchedTimeLineRecords[0].ReadingTime, matchedTimeLineRecords[matchedTimeLineRecords.Count - 1].ReadingTime);
                    double v     = speed.AvgMtrPerSecondRnd();
                    paceLbl.Text = string.Format("{0} m/s", v);

                    //calculate sprints and display
                    double minSpeed = options.EffortZone6Min; //the minimum threshold for classifying movement in m/s
                    double maxSpeed = options.EffortZone6Max; //the maximum threshold for classifying movement in m/s
                    double sprints  = Calculations.Instance.CalcSprints(matchedTimeLineRecords, minSpeed, maxSpeed);
                    sprintsLbl.Text = string.Format("{0}", sprints);

                    SeriesData seriesData     = new SeriesData();
                    double     seriesInterval = options.BreakdownInterval; //interval for series, set here, could be dynamically set in future
                    PopulateChartWithDistance(seriesData.GenerateSeriesData(matchedTimeLineRecords, seriesInterval));

                    //Create list of xy coordinates from timeline events for the graphical display
                    xy = Calculations.Instance.CalcXYFromGeolocationCoords(matchedTimeLineRecords, Width, Height);
                    List <XY> minMax = Calculations.Instance.CalcMinMaxCoords(xy);

                    XYCount     = xy.Count();
                    XYCountdown = xy.Count();

                    //populate effortzone chart
                    List <EffortZones> effortZones = new List <EffortZones>();
                    effortZones.Add(new EffortZones("Zone 1", options.EffortZone1Min, options.EffortZone1Max));
                    effortZones.Add(new EffortZones("Zone 2", options.EffortZone2Min, options.EffortZone2Max));
                    effortZones.Add(new EffortZones("Zone 3", options.EffortZone3Min, options.EffortZone3Max));
                    effortZones.Add(new EffortZones("Zone 4", options.EffortZone4Min, options.EffortZone4Max));
                    effortZones.Add(new EffortZones("Zone 5", options.EffortZone5Min, options.EffortZone5Max));
                    effortZones.Add(new EffortZones("Zone 6", options.EffortZone6Min, options.EffortZone6Max));
                    List <double> effortResults = new List <double>();
                    foreach (var zone in effortZones)
                    {
                        double s = Calculations.Instance.CalcSprints(matchedTimeLineRecords, zone.Min, zone.Max);
                        effortResults.Add(s);
                    }
                    effortZonesChart.DataSource = effortResults;
                    effortZonesChart.DataBind();
                }
            }
            else
            {
                ClearData();
            }
        }