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); }
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); }
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); }
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 }