Exemple #1
0
        public IHttpActionResult GetPeriodDistance(string sport, string type, [FromUri] DateRange dates)
        {
            if (!dates.FromDateTime.HasValue)
            {
                return(BadRequest("Invalid From Date"));
            }

            if (!dates.ToDateTime.HasValue)
            {
                return(BadRequest("Invalid To Date"));
            }

            SportType sportType;

            try
            {
                sportType = EnumConversion.GetEnumFromDescription <SportType>(sport);
            }
            catch (ArgumentException)
            {
                return(BadRequest("Invalid Sport Type"));
            }

            var runData = _periodRepo.ActivityByWeek(this.User.Identity.GetUserId(), sportType, dates.FromDateTime.Value.Date, dates.ToDateTime.Value.Date);

            var chart = new
            {
                Period   = runData.Select(a => a.Label).ToArray(),
                distance = runData.Select(a => type.ToLower() == "total" ? a.TotalDistance.ToString() : a.MaximumDistance.ToString()).ToArray(),
                number   = runData.Select(a => a.Number).ToArray(),
                average  = runData.Select(a => type.ToLower() == "total" ? a.PeriodAverageDistance.ToString() : a.PeriodAverageMaximumDistance.ToString()).ToArray()
            };

            return(Json(chart));
        }
        public void SportTypeExtension_StringToEnumValid()
        {
            Assert.AreEqual(SportType.Ride, EnumConversion.GetEnumFromDescription <SportType>("Ride"));
            Assert.AreEqual(SportType.Run, EnumConversion.GetEnumFromDescription <SportType>("Run"));
            Assert.AreEqual(SportType.Other, EnumConversion.GetEnumFromDescription <SportType>("Other"));
            Assert.AreEqual(SportType.Swim, EnumConversion.GetEnumFromDescription <SportType>("Swim"));
            Assert.AreEqual(SportType.All, EnumConversion.GetEnumFromDescription <SportType>("All"));

            Assert.AreEqual(SportType.Ride, EnumConversion.GetEnumFromDescription <SportType>("ride"));
            Assert.AreEqual(SportType.Ride, EnumConversion.GetEnumFromDescription <SportType>("RIDE"));
            Assert.AreEqual(SportType.Ride, EnumConversion.GetEnumFromDescription <SportType>("RiDe"));
        }
Exemple #3
0
        public ActionResult GetSportSummary([System.Web.Http.FromUri] SportSummaryRequestInformation detail)
        {
            SportType sportType;

            try
            {
                sportType = EnumConversion.GetEnumFromDescription <SportType>(detail.Sport);
            }
            catch (ArgumentException)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SportSummaryDto details = DashboardSportSummary.Create(this.User.Identity.GetUserId(), sportType, detail.FromDateTime.Value, detail.ToDateTime.Value);


            return(PartialView("_sportSummary", details));
        }
Exemple #4
0
        public IHttpActionResult GetTrainingLoad(string type, [FromUri] DateRange dates)
        {
            if (!dates.FromDateTime.HasValue)
            {
                return(BadRequest("Invalid From Date"));
            }

            if (!dates.ToDateTime.HasValue)
            {
                return(BadRequest("Invalid To Date"));
            }

            SportType sport;

            try
            {
                sport = EnumConversion.GetEnumFromDescription <SportType>(type);
            }
            catch (ArgumentException)
            {
                return(BadRequest("Invalid Sport Type"));
            }

            TrainingLoad _trainingLoad;

            _trainingLoad = new TrainingLoad(_activityRepo);
            // need to go back the highest number of days we're interested in plus a yearfor LongTerm training load duration
            // and an extra day to get a seed value.   Add an extra day to the end to hold current form.
            _trainingLoad.Setup(this.User.Identity.GetUserId(), dates.FromDateTime.Value.AddDays(-365), dates.ToDateTime.Value.AddDays(1));
            _trainingLoad.Calculate(sport);

            var requiredDayValues = _trainingLoad.DayValues.Where(d => d.Date >= dates.FromDateTime.Value && d.Date <= dates.ToDateTime.Value).ToList();


            var chart = new
            {
                Date          = requiredDayValues.Select(a => a.Date.ToShortDateString()).ToArray(),
                LongTermLoad  = requiredDayValues.Select(a => a.LongTermLoad.ToString()).ToArray(),
                ShortTermLoad = requiredDayValues.Select(a => a.ShortTermLoad.ToString()).ToArray(),
                TSS           = requiredDayValues.Select(a => a.TSS.ToString()).ToArray()
            };

            return(Json(chart));
        }
Exemple #5
0
        public IHttpActionResult GetPeaksByMonth(string sport, [FromUri] DateRange dates)
        {
            if (!dates.FromDateTime.HasValue)
            {
                return(BadRequest("Invalid From Date"));
            }

            if (!dates.ToDateTime.HasValue)
            {
                return(BadRequest("Invalid To Date"));
            }

            SportType sportType;

            try
            {
                sportType = EnumConversion.GetEnumFromDescription <SportType>(sport);
            }
            catch (ArgumentException)
            {
                return(BadRequest("Invalid Sport Type"));
            }

            var peaksData = _periodRepo.PeaksByMonth(this.User.Identity.GetUserId(), dates.FromDateTime.Value.Date, dates.ToDateTime.Value.Date);

            var chart = new
            {
                Period   = peaksData.Select(a => a.Label).ToArray(),
                Peak5    = peaksData.Select(a => a.Peak5.ToString()).ToArray(),
                Peak30   = peaksData.Select(a => a.Peak30.ToString()).ToArray(),
                Peak60   = peaksData.Select(a => a.Peak60.ToString()).ToArray(),
                Peak300  = peaksData.Select(a => a.Peak300.ToString()).ToArray(),
                Peak1200 = peaksData.Select(a => a.Peak1200.ToString()).ToArray(),
                Peak3600 = peaksData.Select(a => a.Peak3600.ToString()).ToArray()
            };

            return(Json(chart));
        }
 public void SportTypeExtension_StringToEnumInvalid()
 {
     Assert.AreEqual(SportType.Ride, EnumConversion.GetEnumFromDescription <SportType>("InvalidSport"));
 }