public ActionResult Index(StatsFilterModel filterModel) { StatsViewModel vm = new StatsViewModel(); DateTime dateTo; DateTime dateFrom; if (DateTime.TryParseExact(filterModel.S_DateFrom, DATE_PATTERN, null, DateTimeStyles.None, out dateFrom) && DateTime.TryParseExact(filterModel.S_DateTo, DATE_PATTERN, null, DateTimeStyles.None, out dateTo)) { if (dateTo >= dateFrom) { vm = _statsService.GetStats(dateFrom, dateTo); vm.FilterModel = filterModel; } else { AddToastMessage("Błąd", "Data do musi po dacie do", ToastType.Error); } } else { AddToastMessage("Błąd", "Niewłaściwy format daty", ToastType.Error); } return(View(GetIndexViewModel(vm))); }
private async void DoWork(object state) { var count = Interlocked.Increment(ref executionCount); var acount = 0; Stopwatch sw = new Stopwatch(); sw.Start(); using (var scope = _sp.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <sc2dsstatsContext>(); try { var cacheService = scope.ServiceProvider.GetRequiredService <CacheService>(); var memoryCache = scope.ServiceProvider.GetRequiredService <IMemoryCache>(); if (cacheService.Updatesavailable) { var stats = await StatsService.GetStats(context, false); memoryCache.Set("cmdrstats", stats, CacheService.RankingCacheOptions); var plstats = await StatsService.GetStats(context, true); memoryCache.Set("cmdrstatsplayer", plstats, CacheService.RankingCacheOptions); cacheService.Updatesavailable = false; _logger.LogInformation("stats cache rebuild"); } else { if (!memoryCache.TryGetValue("cmdrstats", out _)) { var stats = await StatsService.GetStats(context, false); memoryCache.Set("cmdrstats", stats, CacheService.RankingCacheOptions); _logger.LogInformation("cmdrstats cache refilled"); } if (!memoryCache.TryGetValue("cmdrstatsplayer", out _)) { var plstats = await StatsService.GetStats(context, true); memoryCache.Set("cmdrstatsplayer", plstats, CacheService.RankingCacheOptions); _logger.LogInformation("cmdrstatspl cache refilled"); } } } catch (Exception e) { _logger.LogError($"Update Service failed: {e.Message}"); } } sw.Stop(); _logger.LogInformation( $"Update Service is working ({count}). Count: {acount} in {sw.Elapsed.TotalSeconds} s"); }
private async Task <List <CmdrStats> > GetStats(bool player) { List <CmdrStats> stats; string memkey = player ? "cmdrstatsplayer" : "cmdrstats"; if (!memoryCache.TryGetValue(memkey, out stats)) { stats = await StatsService.GetStats(context, player); memoryCache.Set(memkey, stats, CacheService.RankingCacheOptions); } return(stats); }
public List <StatsData> GetStatus(string token) { _log.Debug("Request for stats"); //validate token if (token != _statsToken) { _log.Error("Token sent (" + token + ") is not valid"); throw new UnauthorizedAccessException(); } var statsService = new StatsService(); return(statsService.GetStats()); }
public void GetStats_ReturnsStats_WhenInvoked() { var mockStatsRepo = new Mock <IStatsRepository>(); var testStat = new StatsModel() { HumanCount = 4, MutantCount = 2, Ratio = 0.5 }; mockStatsRepo.Setup(x => x.GetGenomeStats()).Returns(testStat); var statsService = new StatsService(mockStatsRepo.Object); var result = statsService.GetStats(); Assert.Equal(result, testStat); }
// GET: Stats/Detail/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } List <MatchDTO> stats = await statsService.GetStats(id.Value); if (stats == null) { return(HttpNotFound()); } List <PlayerDTO> players = await playerService.GetPlayersAsync(); List <MatchDTO> matches = await matchesService.GetMatchesAsync(); StatsCompositeViewModel viewmodel = new StatsCompositeViewModel(players, matches); return(View(viewmodel.GetSinglePlayerById(id.Value))); }
public async Task <IHttpActionResult> GetStats(Request request) { var response = await _statsService.GetStats(request); return(new CreateResult(response)); }