Beispiel #1
0
        private async Task UpdateSystemWideValues()
        {
            List <PublisherGame> allGamesWithPoints = new List <PublisherGame>();
            var supportedYears = await _interLeagueService.GetSupportedYears();

            foreach (var supportedYear in supportedYears)
            {
                var publishers = await _fantasyCriticRepo.GetAllPublishersForYear(supportedYear.Year);

                var publisherGames  = publishers.SelectMany(x => x.PublisherGames);
                var gamesWithPoints = publisherGames.Where(x => x.FantasyPoints.HasValue).ToList();
                allGamesWithPoints.AddRange(gamesWithPoints);
            }

            var averageStandardPoints    = allGamesWithPoints.Where(x => !x.CounterPick).Select(x => x.FantasyPoints.Value).DefaultIfEmpty(0m).Average();
            var averageCounterPickPoints = allGamesWithPoints.Where(x => x.CounterPick).Select(x => x.FantasyPoints.Value).DefaultIfEmpty(0m).Average();

            var systemWideValues = new SystemWideValues(averageStandardPoints, averageCounterPickPoints);
            await _interLeagueService.UpdateSystemWideValues(systemWideValues);
        }
Beispiel #2
0
        public async Task UpdateFantasyPoints(int year)
        {
            Dictionary <Guid, decimal?> publisherGameScores = new Dictionary <Guid, decimal?>();

            IReadOnlyList <LeagueYear> activeLeagueYears = await GetLeagueYears(year);

            Dictionary <LeagueYearKey, LeagueYear> leagueYearDictionary = activeLeagueYears.ToDictionary(x => x.Key, y => y);
            IReadOnlyList <Publisher> allPublishersForYear = await _fantasyCriticRepo.GetAllPublishersForYear(year);

            foreach (var publisher in allPublishersForYear)
            {
                var key = new LeagueYearKey(publisher.LeagueYear.League.LeagueID, publisher.LeagueYear.Year);
                foreach (var publisherGame in publisher.PublisherGames)
                {
                    var     leagueYear    = leagueYearDictionary[key];
                    decimal?fantasyPoints = publisherGame.CalculateFantasyPoints(leagueYear.Options.ScoringSystem, _clock);
                    publisherGameScores.Add(publisherGame.PublisherGameID, fantasyPoints);
                }
            }

            await _fantasyCriticRepo.UpdateFantasyPoints(publisherGameScores);
        }