public void CachedRepository_StoresResultsInCache()
        {
            var result = _sut.Submit(
                queryDate: new DateTime(2018, 6, 4),
                playerSlug: "mlb-francisco-cervelli");

            Assert.IsNotNull(result);
            Assert.AreEqual(40, result.Hits);
        }
Ejemplo n.º 2
0
        public PlayerStatsViewModel Submit(DateTime queryDate, string playerSlug)
        {
            var keyValue = $"{playerSlug}:{Utility.UniversalDate(queryDate)}";

            if (!_cache.TryGet(keyValue, out PlayerStatsViewModel viewModel))
            {
                viewModel = _decoratedComponent.Submit(queryDate, playerSlug);
                _cache.Set(keyValue, viewModel);
            }
            return(viewModel);
        }
Ejemplo n.º 3
0
        public bool GotHit(Batter batter, DateTime gameDate)
        {
            var hit = false;

            if (gameDate < DateTime.Now.AddDays(-2))
            {
                var statsAfterGame = _playerStatsRepository.Submit(
                    queryDate: gameDate.AddDays(1),
                    playerSlug: batter.PlayerSlug);
                var statsBeforeGame = _playerStatsRepository.Submit(
                    queryDate: gameDate,
                    playerSlug: batter.PlayerSlug);
                if (statsAfterGame.Hits > statsBeforeGame.Hits)
                {
                    hit = true;
                }
            }
            else
            {
                Console.WriteLine("Game too fresh");
            }
            return(hit);
        }
Ejemplo n.º 4
0
        private void RecalculateBattingAverage(Batter batter, DateTime gameDate)
        {
            if (!_pickerOptions.OptionOn(Constants.Options.HotBatters))
            {
                return;
            }
            var oldAvg = batter.BattingAverage;
            // calculate BAV for the period
            var queryDate = gameDate.AddDays(-1);
            var statsTo   = _playerStatsRepository.Submit(
                queryDate,
                batter.PlayerSlug);
            var statsFrom = _playerStatsRepository.Submit(
                queryDate.AddDays(-_pickerOptions.IntegerOption(
                                      Constants.Options.HotBattersDaysBack)),
                batter.PlayerSlug);

            batter.BattingAverage = BattingAverage(statsFrom, statsTo);
#if DEBUG
            Console.WriteLine($@"   bavg for {
				batter.PlayerSlug,-25
				} was {oldAvg:#.000} now calculated as {batter.BattingAverage:#.000}"                );
#endif
        }