コード例 #1
0
        public void TrainingLoad_TSSValueLoadTest()
        {
            Mock <IActivityDtoRepository> mock = Constant100TSSDaily();

            TrainingLoad pmc = new TrainingLoad(mock.Object);

            pmc.Setup(USER_ID, _startContantValues, _endConstantValues);
            pmc.Calculate(SportType.Ride);

            // check TSS values are populated correctly.
            foreach (TrainingLoadDay day in pmc.DayValues)
            {
                Assert.AreEqual(100, day.TSS);
            }
        }
コード例 #2
0
        public void TrainingLoad_CreateAndInitialiseValidDates()
        {
            TrainingLoad pmc = new TrainingLoad();

            pmc.Setup(USER_ID, _startContantValues, _endConstantValues);

            // test start and end dates exist.
            Assert.IsNotNull(pmc.DayValues.Where(d => d.Date == _startContantValues).FirstOrDefault());
            Assert.IsNotNull(pmc.DayValues.Where(d => d.Date == _endConstantValues).FirstOrDefault());

            // check each date exists in collection
            for (DateTime date = _startContantValues; date <= _endConstantValues; date = date.AddDays(1))
            {
                Assert.IsNotNull(pmc.DayValues.Where(d => d.Date == date).FirstOrDefault());
            }
        }
コード例 #3
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));
        }
コード例 #4
0
        public void TrainingLoad_ConstantTSSTest()
        {
            Mock <IActivityDtoRepository> mock = Constant100TSSDaily();

            TrainingLoad pmc = new TrainingLoad(mock.Object);

            pmc.Setup(USER_ID, _startContantValues, _endConstantValues);
            pmc.Calculate(SportType.Ride);

            Assert.AreEqual(13.31M, pmc.DayValues.Where(d => d.Date == _startContantValues).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(24.85M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(1)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(34.86M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(2)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(43.53M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(3)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(51.05M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(4)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(57.56M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(5)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(63.21M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(6)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(68.11M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(7)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(72.35M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(8)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(76.03M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(9)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(79.23M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(10)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(81.99M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(11)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(84.39M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(12)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(86.47M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(13)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(88.27M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(14)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(89.83M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(15)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(91.18M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(16)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(92.36M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(17)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(93.37M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(18)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(94.26M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(19)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(95.02M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(20)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(95.68M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(21)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(96.26M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(22)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(96.76M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(23)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(97.19M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(24)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(97.56M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(25)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(97.89M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(26)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(98.17M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(27)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(98.41M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(28)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(98.62M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(29)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(98.81M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(30)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(98.97M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(31)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.10M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(32)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.22M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(33)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.33M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(34)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.42M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(35)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.49M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(36)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.56M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(37)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.62M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(38)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.67M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(39)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.71M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(40)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.75M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(41)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.79M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(42)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.81M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(43)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.84M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(44)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.86M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(45)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.88M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(46)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.89M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(47)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.91M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(48)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.92M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(49)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.93M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(50)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.94M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(51)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.95M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(52)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.96M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(53)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.96M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(54)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.97M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(55)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.97M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(56)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.97M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(57)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.98M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(58)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.98M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(59)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(99.98M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(60)).Select(d => d.ShortTermLoad).FirstOrDefault());



            Assert.AreEqual(2.35M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(0)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(4.65M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(1)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(6.89M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(2)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(9.08M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(3)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(11.22M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(4)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(13.31M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(5)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(15.35M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(6)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(17.34M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(7)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(19.29M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(8)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(21.19M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(9)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(23.04M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(10)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(24.85M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(11)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(26.62M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(12)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(28.35M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(13)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(30.03M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(14)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(31.68M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(15)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(33.29M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(16)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(34.86M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(17)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(36.39M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(18)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(37.89M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(19)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(39.35M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(20)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(40.77M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(21)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(42.17M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(22)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(43.53M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(23)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(44.86M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(24)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(46.15M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(25)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(47.42M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(26)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(48.66M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(27)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(49.87M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(28)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(51.05M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(29)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(52.20M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(30)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(53.32M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(31)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(54.42M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(32)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(55.49M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(33)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(56.54M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(34)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(57.56M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(35)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(58.56M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(36)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(59.54M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(37)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(60.49M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(38)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(61.42M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(39)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(62.33M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(40)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(63.21M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(41)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(64.08M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(42)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(64.92M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(43)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(65.75M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(44)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(66.55M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(45)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(67.34M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(46)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(68.11M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(47)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(68.86M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(48)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(69.59M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(49)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(70.31M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(50)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(71.01M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(51)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(71.69M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(52)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(72.35M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(53)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(73.01M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(54)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(73.64M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(55)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(74.26M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(56)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(74.87M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(57)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(75.46M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(58)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(76.03M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(59)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(76.60M, pmc.DayValues.Where(d => d.Date == _startContantValues.AddDays(60)).Select(d => d.LongTermLoad).FirstOrDefault());
        }
コード例 #5
0
        public void TrainingLoad_CTLDayConstantTest()
        {
            TrainingLoad pmc = new TrainingLoad();

            pmc.LongTermDays = -1;
        }
コード例 #6
0
        public void TrainingLoad_CreateAndInitialiseInvalidDates()
        {
            TrainingLoad pmc = new TrainingLoad();

            pmc.Setup(USER_ID, DateTime.Now, DateTime.Now.AddDays(-1));
        }
コード例 #7
0
        public void TrainingLoad_ATLDayConstantTest()
        {
            TrainingLoad pmc = new TrainingLoad();

            pmc.ShortTermDays = -1;
        }
コード例 #8
0
        public void TrainingLoad_SeedCTLTest()
        {
            TrainingLoad pmc = new TrainingLoad();

            pmc.LongTermSeed = -1;
        }
コード例 #9
0
        public void TrainingLoad_SeedATLTest()
        {
            TrainingLoad pmc = new TrainingLoad();

            pmc.ShortTermSeed = -1;
        }
コード例 #10
0
        public void TrainingLoad_ActualTSSTest()
        {
            Mock <IActivityDtoRepository> mock = ActualTSS();

            TrainingLoad pmc = new TrainingLoad(mock.Object);

            pmc.Setup(USER_ID, _startActualValues, _endActualValues);
            pmc.ShortTermSeed = 47.2M;
            pmc.LongTermSeed  = 46.7M;
            pmc.ShortTermDays = 6.5;

            pmc.Calculate(SportType.Ride);

            Assert.AreEqual(40.47M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 3)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(45.60M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 3)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(58.10M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 4)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(48.39M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 4)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(49.81M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 5)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(47.25M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 5)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(48.56M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 6)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(47.10M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 6)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(46.80M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 7)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(46.85M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 7)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(40.12M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 8)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(45.74M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 8)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(40.86M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 9)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(45.73M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 9)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(35.03M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 10)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.66M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 10)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(30.04M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 11)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(43.61M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 11)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(25.75M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 12)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(42.58M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 12)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(37.41M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 13)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.11M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 13)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(39.71M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 14)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.33M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 14)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(43.21M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 15)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.80M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 15)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(41.37M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 16)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.46M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 16)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(35.47M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 17)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(43.41M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 17)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(40.55M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 18)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.06M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 18)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(43.28M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 19)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.43M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 19)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(51.43M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 20)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(45.75M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 20)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(46.60M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 21)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(45.09M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 21)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(47.30M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 22)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(45.24M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 22)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(45.21M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 23)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(44.94M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 23)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(38.76M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 24)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(43.88M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 24)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(33.23M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 25)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(42.85M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 25)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(28.49M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 26)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(41.84M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 26)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(24.43M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 27)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(40.86M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 27)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(20.95M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 28)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(39.90M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 28)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(17.96M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 29)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(38.96M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 29)).Select(d => d.LongTermLoad).FirstOrDefault());
            Assert.AreEqual(15.40M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 30)).Select(d => d.ShortTermLoad).FirstOrDefault());
            Assert.AreEqual(38.04M, pmc.DayValues.Where(d => d.Date == new DateTime(2016, 9, 30)).Select(d => d.LongTermLoad).FirstOrDefault());
        }
コード例 #11
0
ファイル: Analyser.cs プロジェクト: Cycli/Cycli
        public static TrainingLoad[] GetTrainingLoad(string userId)
        {
            List<TrainingLoad> tls = new List<TrainingLoad>();
            // Because we look over the past year, we need data for 3 * chronic training load time constant
            DateTime now = DateTime.UtcNow.Date.AddDays(1);
            DateTime yearAgo = now.AddYears(-1);
            long secsYearAgo = Utilities.DbTime.ToDbSecs(yearAgo);
            long secsNow = Utilities.DbTime.ToDbSecs(now);
            DateTime startCalcTime = yearAgo.AddDays(-3 * CTL_TIME_CONSTANT);
            long startms = Utilities.DbTime.ToDbSecs(startCalcTime);
            DataTable dtTSS = null;
            string sql = @"select (r.startdatetime - r.startdatetime % 86400) as startdatetime, " +
                         "sum(rr.TSS) as TSS " +
                        "from cycli_race_riders rr, cycli_races r " +
                        "where rr.raceid = r.raceid " +
                        "and rr.userid = @u1 " +
                        "and r.startdatetime >= @st " +
                        "group by r.startdatetime - r.startdatetime % 86400 " +
                        "order by startdatetime";

            SQLiteDatabase db = new SQLiteDatabase();
            try
            {
                dtTSS = db.GetDataTable(sql, "@u1", userId, "@st", startms);
                float lastAtl = 0f;
                float lastCtl = 0f;

                if (dtTSS.Rows.Count > 0)
                {

                    DateTime d = startCalcTime;
                    while (d < now)
                    {

                        long s = Utilities.DbTime.ToDbSecs(d);
                        long e = Utilities.DbTime.ToDbSecs(d.AddDays(1));

                        DataRow[] dr = dtTSS.Select("startdatetime >= " + s + " and startdatetime < " + e);

                        TrainingLoad tl = new TrainingLoad() { DeltaDate = s - secsNow };
                        int t = 0;
                        if (dr.Length > 0)
                        {
                            tl.Tss = (int)dr[0].Field<long>("TSS");
                            t = tl.Tss;
                        }
                        else
                        {
                            tl.Tss = int.MinValue;   // Will hide it on the chart
                            t = 0;
                        }
                        tl.Atl = lastAtl + (float)(t - lastAtl) / ATL_TIME_CONSTANT;
                        tl.Ctl = lastCtl + (float)(t - lastCtl) / CTL_TIME_CONSTANT;
                        tl.Tsb = tl.Ctl - tl.Atl;

                        // Only add to the list if we're in the last year
                        if (d >= yearAgo)
                        {
                            tls.Add(tl);
                        }
                        lastAtl = tl.Atl;
                        lastCtl = tl.Ctl;
                        d = d.AddDays(1);
                    }
                }
            }
            finally
            {
                db.Close();
            }
            return tls.ToArray();
        }