Exemplo n.º 1
0
        private HistogramViewModel CreateHistogramViewModel(RaceFilterViewModel filter)
        {
            var viewModel = new HistogramViewModel();

            viewModel.Filter = filter;
            var athletes = GetFilteredAthletes(GetAllAthletesForRaces(filter), filter);

            var calculator = new TriStatsCalculator(athletes);

            viewModel.SwimMedian   = calculator.TimeSpanMedian("Swim");
            viewModel.BikeMedian   = calculator.TimeSpanMedian("Bike");
            viewModel.RunMedian    = calculator.TimeSpanMedian("Run");
            viewModel.FinishMedian = calculator.TimeSpanMedian("Finish");

            viewModel.Triathletes = athletes;
            return(viewModel);
        }
        private ActionResult DisplayResultsView(RaceFilterViewModel filter, string viewName)
        {
            var viewModel = new CompareBikeRunViewModel();

            viewModel.Filter = filter;

            var athletes = GetFilteredAthletes(GetAllAthletesForRaces(filter), filter);

            var calc = new TriStatsCalculator(athletes);

            viewModel.BikeMedian  = calc.TimeSpanMedian("Bike");
            viewModel.RunMedian   = calc.TimeSpanMedian("Run");
            viewModel.Triathletes = athletes;

            PartitionAthletes(viewModel);

            viewModel.Stats.Add(GetStats(athletes));


            return(View(viewName, viewModel));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get Stats for athletes associated with single race
        /// </summary>
        /// <param name="athletes"></param>
        /// <param name="race"></param>
        /// <returns></returns>
        protected TriStats GetStats(List <Triathlete> athletes, Race race)
        {
            TriStats stats = new TriStats(athletes, race);

            TriStatsCalculator calc = new TriStatsCalculator(athletes);

            //median
            stats.Swim.Median   = calc.TimeSpanMedian("Swim");
            stats.Bike.Median   = calc.TimeSpanMedian("Bike");
            stats.Run.Median    = calc.TimeSpanMedian("Run");
            stats.Finish.Median = calc.TimeSpanMedian("Finish");


            stats.DivRank.Median     = Math.Floor(calc.IntMedian("DivRank"));
            stats.GenderRank.Median  = Math.Floor(calc.IntMedian("GenderRank"));
            stats.OverallRank.Median = Math.Floor(calc.IntMedian("OverallRank"));
            stats.Points.Median      = Math.Floor(calc.IntMedian("Points"));

            //avg
            stats.Swim.Average   = calc.TimeSpanAverage("Swim");
            stats.Bike.Average   = calc.TimeSpanAverage("Bike");
            stats.Run.Average    = calc.TimeSpanAverage("Run");
            stats.Finish.Average = calc.TimeSpanAverage("Finish");


            stats.DivRank.Average     = Math.Floor(calc.IntAverage("DivRank"));
            stats.GenderRank.Average  = Math.Floor(calc.IntAverage("GenderRank"));
            stats.OverallRank.Average = Math.Floor(calc.IntAverage("OverallRank"));
            stats.Points.Average      = Math.Floor(calc.IntAverage("Points"));

            //min
            stats.Swim.Min   = calc.TimeSpanMin("Swim");
            stats.Bike.Min   = calc.TimeSpanMin("Bike");
            stats.Run.Min    = calc.TimeSpanMin("Run");
            stats.Finish.Min = calc.TimeSpanMin("Finish");


            stats.DivRank.Min     = calc.IntMin("DivRank");
            stats.GenderRank.Min  = calc.IntMin("GenderRank");
            stats.OverallRank.Min = calc.IntMin("OverallRank");
            stats.Points.Min      = calc.IntMin("Points");

            //max
            stats.Swim.Max   = calc.TimeSpanMax("Swim");
            stats.Bike.Max   = calc.TimeSpanMax("Bike");
            stats.Run.Max    = calc.TimeSpanMax("Run");
            stats.Finish.Max = calc.TimeSpanMax("Finish");


            stats.DivRank.Max     = calc.IntMax("DivRank");
            stats.GenderRank.Max  = calc.IntMax("GenderRank");
            stats.OverallRank.Max = calc.IntMax("OverallRank");
            stats.Points.Max      = calc.IntMax("Points");


            //standard deviation
            stats.Swim.StandDev   = calc.TimeSpanStandardDeviation("Swim");
            stats.Bike.StandDev   = calc.TimeSpanStandardDeviation("Bike");
            stats.Run.StandDev    = calc.TimeSpanStandardDeviation("Run");
            stats.Finish.StandDev = calc.TimeSpanStandardDeviation("Finish");


            var swimSplit = TriStatsCalculator.Split(athletes, "Swim");

            stats.Swim.FastestHalf = TriStatsCalculator.Split(swimSplit.Item1, "Swim");
            stats.Swim.SlowestHalf = TriStatsCalculator.Split(swimSplit.Item2, "Swim");

            var bikeSplit = TriStatsCalculator.Split(athletes, "Bike");

            stats.Bike.FastestHalf = TriStatsCalculator.Split(bikeSplit.Item1, "Bike");
            stats.Bike.SlowestHalf = TriStatsCalculator.Split(bikeSplit.Item2, "Bike");

            var runSplit = TriStatsCalculator.Split(athletes, "Run");

            stats.Run.FastestHalf = TriStatsCalculator.Split(runSplit.Item1, "Run");
            stats.Run.SlowestHalf = TriStatsCalculator.Split(runSplit.Item2, "Run");

            var finishSplit = TriStatsCalculator.Split(athletes, "Finish");

            stats.Finish.FastestHalf = TriStatsCalculator.Split(finishSplit.Item1, "Finish");
            stats.Finish.SlowestHalf = TriStatsCalculator.Split(finishSplit.Item2, "Finish");



            stats.Swim.Data   = athletes.OrderBy(a => a.Swim).Select(a => a.Swim.ToString("hh\\:mm\\:ss")).ToArray();
            stats.Bike.Data   = athletes.OrderBy(a => a.Bike).Select(a => a.Bike.ToString("hh\\:mm\\:ss")).ToArray();
            stats.Run.Data    = athletes.OrderBy(a => a.Run).Select(a => a.Run.ToString("hh\\:mm\\:ss")).ToArray();
            stats.Finish.Data = athletes.OrderBy(a => a.Finish).Select(a => a.Finish.ToString("hh\\:mm\\:ss")).ToArray();

            stats.DNFCount = calc.NumberDNFs();

            return(stats);
        }