コード例 #1
0
        private static BidProcessingResults GetProcessingResults(IEnumerable <PickupBid> successBids, IEnumerable <FailedPickupBid> failedBids, IEnumerable <Publisher> publishers, IClock clock)
        {
            List <Publisher>     updatedPublishers = publishers.ToList();
            List <PublisherGame> gamesToAdd        = new List <PublisherGame>();
            List <LeagueAction>  leagueActions     = new List <LeagueAction>();

            foreach (var successBid in successBids)
            {
                PublisherGame newPublisherGame = new PublisherGame(successBid.Publisher.PublisherID, Guid.NewGuid(), successBid.MasterGame.GameName, clock.GetCurrentInstant(),
                                                                   false, null, null, new MasterGameYear(successBid.MasterGame, successBid.Publisher.LeagueYear.Year), null, null);
                gamesToAdd.Add(newPublisherGame);
                var affectedPublisher = updatedPublishers.Single(x => x.PublisherID == successBid.Publisher.PublisherID);
                affectedPublisher.AcquireGame(newPublisherGame, successBid.BidAmount);

                LeagueAction leagueAction = new LeagueAction(successBid, clock.GetCurrentInstant());
                leagueActions.Add(leagueAction);
            }

            foreach (var failedBid in failedBids)
            {
                LeagueAction leagueAction = new LeagueAction(failedBid, clock.GetCurrentInstant());
                leagueActions.Add(leagueAction);
            }

            var simpleFailedBids = failedBids.Select(x => x.PickupBid);

            BidProcessingResults bidProcessingResults = new BidProcessingResults(successBids, simpleFailedBids, leagueActions, updatedPublishers, gamesToAdd);

            return(bidProcessingResults);
        }
コード例 #2
0
        public async Task <BidProcessingResults> GetBidProcessingDryRun(SystemWideValues systemWideValues, int year)
        {
            IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > leaguesAndBids = await _fantasyCriticRepo.GetActivePickupBids(year);

            IReadOnlyList <Publisher> allPublishers = await _fantasyCriticRepo.GetAllPublishersForYear(year);

            var supportedYears = await _fantasyCriticRepo.GetSupportedYears();

            IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > onlyLeaguesWithBids = leaguesAndBids.Where(x => x.Value.Any()).ToDictionary(x => x.Key, y => y.Value);
            var publishersInLeagues      = allPublishers.Where(x => onlyLeaguesWithBids.ContainsKey(x.LeagueYear));
            BidProcessingResults results = _actionProcessingService.ProcessPickupsIteration(systemWideValues, onlyLeaguesWithBids, publishersInLeagues, _clock, supportedYears);

            return(results);
        }
コード例 #3
0
        public BidProcessingResults ProcessPickupsIteration(SystemWideValues systemWideValues, IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > allActiveBids,
                                                            IEnumerable <Publisher> currentPublisherStates, IClock clock, IEnumerable <SupportedYear> supportedYears)
        {
            if (!allActiveBids.Any())
            {
                return(new BidProcessingResults(new List <PickupBid>(), new List <PickupBid>(), new List <LeagueAction>(), currentPublisherStates, new List <PublisherGame>()));
            }

            IEnumerable <PickupBid> flatAllBids = allActiveBids.SelectMany(x => x.Value);

            var processedBids = new ProcessedBidSet();

            foreach (var leagueYear in allActiveBids)
            {
                if (!leagueYear.Value.Any())
                {
                    continue;
                }

                var processedBidsForLeagueYear = ProcessPickupsForLeagueYear(leagueYear.Key, leagueYear.Value, currentPublisherStates, systemWideValues, supportedYears);
                processedBids = processedBids.AppendSet(processedBidsForLeagueYear);
            }

            BidProcessingResults bidProcessingResults = GetProcessingResults(processedBids.SuccessBids, processedBids.FailedBids, currentPublisherStates, clock);

            var remainingBids = flatAllBids.Except(processedBids.ProcessedBids);

            if (remainingBids.Any())
            {
                Dictionary <LeagueYear, IReadOnlyList <PickupBid> > remainingBidDictionary = remainingBids.GroupBy(x => x.LeagueYear).ToDictionary(x => x.Key, y => (IReadOnlyList <PickupBid>)y.ToList());
                var subProcessingResults             = ProcessPickupsIteration(systemWideValues, remainingBidDictionary, bidProcessingResults.UpdatedPublishers, clock, supportedYears);
                BidProcessingResults combinedResults = bidProcessingResults.Combine(subProcessingResults);
                return(combinedResults);
            }

            return(bidProcessingResults);
        }
コード例 #4
0
 public Task SaveProcessedBidResults(BidProcessingResults bidProcessingResults)
 {
     throw new NotImplementedException();
 }