public async Task <IActionResult> ProcessPickups() { var systemWideSettings = await _interLeagueService.GetSystemWideSettings(); if (!systemWideSettings.BidProcessingMode) { return(BadRequest("Turn on bid processing mode first.")); } SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var supportedYears = await _interLeagueService.GetSupportedYears(); foreach (var supportedYear in supportedYears) { if (supportedYear.Finished || !supportedYear.OpenForPlay) { continue; } await _fantasyCriticService.ProcessPickups(systemWideValues, supportedYear.Year); } return(Ok()); }
public SucceededPickupBid(PickupBid pickupBid, int slotNumber, string outcome, SystemWideValues systemWideValues, LocalDate currentDate) { PickupBid = pickupBid; SlotNumber = slotNumber; Outcome = outcome; ProjectedPointsAtTimeOfBid = PickupBid.Publisher.GetProjectedFantasyPoints(pickupBid.LeagueYear, systemWideValues, currentDate); }
private ActionProcessingResults ProcessPickupsIteration(SystemWideValues systemWideValues, IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > allActiveBids, ActionProcessingResults existingResults, Instant processingTime, IReadOnlyDictionary <Guid, MasterGameYear> masterGameYearDictionary) { IEnumerable <PickupBid> flatAllBids = allActiveBids.SelectMany(x => x.Value); var publisherStateSet = existingResults.PublisherStateSet; var processedBids = new ProcessedBidSet(); foreach (var leagueYear in allActiveBids) { if (!leagueYear.Value.Any()) { continue; } var processedBidsForLeagueYear = ProcessPickupsForLeagueYear(leagueYear.Key, leagueYear.Value, publisherStateSet, systemWideValues, processingTime); processedBids = processedBids.AppendSet(processedBidsForLeagueYear); } ActionProcessingResults bidResults = GetBidProcessingResults(processedBids.SuccessBids, processedBids.FailedBids, publisherStateSet, processingTime, masterGameYearDictionary); var newResults = existingResults.Combine(bidResults); var remainingBids = flatAllBids.Except(processedBids.ProcessedBids); if (remainingBids.Any()) { IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > remainingBidDictionary = remainingBids.GroupToDictionary(x => x.LeagueYear); var subProcessingResults = ProcessPickupsIteration(systemWideValues, remainingBidDictionary, newResults, processingTime, masterGameYearDictionary); ActionProcessingResults combinedResults = newResults.Combine(subProcessingResults); return(combinedResults); } return(newResults); }
public FinalizedActionProcessingResults ProcessActions(SystemWideValues systemWideValues, IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > allActiveBids, IReadOnlyDictionary <LeagueYear, IReadOnlyList <DropRequest> > allActiveDrops, IEnumerable <Publisher> publishers, Instant processingTime, IReadOnlyDictionary <Guid, MasterGameYear> masterGameYearDictionary) { var publisherStateSet = new PublisherStateSet(publishers); var flatBids = allActiveBids.SelectMany(x => x.Value); var invalidBids = flatBids.Where(x => x.CounterPick && x.ConditionalDropPublisherGame is not null); if (invalidBids.Any()) { throw new Exception("There are counter pick bids with conditional drops."); } string processName = $"Drop/Bid Processing ({processingTime.ToEasternDate()})"; Guid processSetID = Guid.NewGuid(); if (!allActiveBids.Any() && !allActiveDrops.Any()) { var emptyResults = ActionProcessingResults.GetEmptyResultsSet(publisherStateSet); return(new FinalizedActionProcessingResults(processSetID, processingTime, processName, emptyResults)); } ActionProcessingResults dropResults = ProcessDrops(allActiveDrops, publisherStateSet, processingTime); if (!allActiveBids.Any()) { return(new FinalizedActionProcessingResults(processSetID, processingTime, processName, dropResults)); } ActionProcessingResults bidResults = ProcessPickupsIteration(systemWideValues, allActiveBids, dropResults, processingTime, masterGameYearDictionary); return(new FinalizedActionProcessingResults(processSetID, processingTime, processName, bidResults)); }
public async Task <IActionResult> ProcessPickups() { var systemWideSettings = await _interLeagueService.GetSystemWideSettings(); if (!systemWideSettings.BidProcessingMode) { return(BadRequest("Turn on bid processing mode first.")); } var today = _clock.GetCurrentInstant().ToEasternDate(); if (today.DayOfWeek != IsoDayOfWeek.Monday) { return(BadRequest($"You probably didn't mean to process pickups on a {today.DayOfWeek}")); } SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var supportedYears = await _interLeagueService.GetSupportedYears(); foreach (var supportedYear in supportedYears) { if (supportedYear.Finished || !supportedYear.OpenForPlay) { continue; } await _fantasyCriticService.ProcessPickups(systemWideValues, supportedYear.Year); } return(Ok()); }
public async Task ProcessActions(SystemWideValues systemWideValues, int year) { var now = _clock.GetCurrentInstant(); IReadOnlyList <LeagueYear> allLeagueYears = await GetLeagueYears(year); var results = await GetActionProcessingDryRun(systemWideValues, year, now, allLeagueYears); await _fantasyCriticRepo.SaveProcessedActionResults(results); }
public PublisherViewModel(Publisher publisher, IClock clock, Maybe <Publisher> nextDraftPublisher, bool userIsInLeague, bool outstandingInvite, SystemWideValues systemWideValues, bool yearFinished) { PublisherID = publisher.PublisherID; LeagueID = publisher.LeagueYear.League.LeagueID; PublisherName = publisher.PublisherName; LeagueName = publisher.LeagueYear.League.LeagueName; PlayerName = publisher.User.DisplayName; Year = publisher.LeagueYear.Year; DraftPosition = publisher.DraftPosition; AutoDraft = publisher.AutoDraft; Games = publisher.PublisherGames .OrderBy(x => x.Timestamp) .Select(x => new PublisherGameViewModel(x, clock, publisher.LeagueYear.Options.ScoringSystem, systemWideValues)) .ToList(); AverageCriticScore = publisher.AverageCriticScore; TotalFantasyPoints = publisher.TotalFantasyPoints; TotalProjectedPoints = publisher.GetProjectedFantasyPoints(publisher.LeagueYear.Options, systemWideValues, yearFinished, false, clock); Budget = publisher.Budget; if (nextDraftPublisher.HasValue && nextDraftPublisher.Value.PublisherID == publisher.PublisherID) { NextToDraft = true; } UserIsInLeague = userIsInLeague; PublicLeague = publisher.LeagueYear.Options.PublicLeague; OutstandingInvite = outstandingInvite; var timeToCheck = clock.GetCurrentInstant(); if (yearFinished) { //Just before midnight on New Year's timeToCheck = new LocalDate(Year + 1, 1, 1).AtMidnight().InUtc().Minus(Duration.FromMinutes(1)).ToInstant(); } GamesReleased = publisher.PublisherGames .Where(x => !x.CounterPick) .Where(x => x.MasterGame.HasValue) .Count(x => x.MasterGame.Value.MasterGame.IsReleased(timeToCheck)); var allWillRelease = publisher.PublisherGames .Where(x => !x.CounterPick) .Where(x => x.MasterGame.HasValue) .Count(x => x.WillRelease()); GamesWillRelease = allWillRelease - GamesReleased; FreeGamesDropped = publisher.FreeGamesDropped; WillNotReleaseGamesDropped = publisher.WillNotReleaseGamesDropped; WillReleaseGamesDropped = publisher.WillReleaseGamesDropped; FreeDroppableGames = publisher.LeagueYear.Options.FreeDroppableGames; WillNotReleaseDroppableGames = publisher.LeagueYear.Options.WillNotReleaseDroppableGames; WillReleaseDroppableGames = publisher.LeagueYear.Options.WillReleaseDroppableGames; }
public PlayerWithPublisherViewModel(LeagueYear leagueYear, FantasyCriticUser user, Publisher publisher, IClock clock, LeagueOptions options, SystemWideValues systemWideValues, bool userIsInLeague, bool userIsInvitedToLeague, SupportedYear supportedYear, bool removable) { User = new PlayerViewModel(leagueYear.League, user, removable); Publisher = new PublisherViewModel(publisher, clock, userIsInLeague, userIsInvitedToLeague, systemWideValues, supportedYear.Finished); TotalFantasyPoints = publisher.TotalFantasyPoints; SimpleProjectedFantasyPoints = publisher.GetProjectedFantasyPoints(options, systemWideValues, supportedYear.Finished, true, clock); AdvancedProjectedFantasyPoints = publisher.GetProjectedFantasyPoints(options, systemWideValues, supportedYear.Finished, false, clock); }
public PlayerWithPublisherViewModel(LeagueYear leagueYear, FantasyCriticUser user, Publisher publisher, LocalDate currentDate, SystemWideValues systemWideValues, bool userIsInLeague, bool userIsInvitedToLeague, bool removable, bool previousYearWinner) { User = new PlayerViewModel(leagueYear.League, user, removable); Publisher = new MinimalPublisherViewModel(leagueYear, publisher, currentDate, userIsInLeague, userIsInvitedToLeague, systemWideValues); TotalFantasyPoints = publisher.GetTotalFantasyPoints(leagueYear.SupportedYear, leagueYear.Options); ProjectedFantasyPoints = publisher.GetProjectedFantasyPoints(leagueYear, systemWideValues, currentDate); PreviousYearWinner = previousYearWinner; }
private async Task UpdateSystemWideValues() { _logger.Info("Updating system wide values"); List <PublisherGame> allGamesWithPoints = new List <PublisherGame>(); var supportedYears = await _interLeagueService.GetSupportedYears(); var allLeagueYears = new List <LeagueYear>(); foreach (var supportedYear in supportedYears) { var leagueYears = await _fantasyCriticRepo.GetLeagueYears(supportedYear.Year); var leaguesToCount = leagueYears.Where(x => !x.League.TestLeague && x.PlayStatus.DraftFinished).ToList(); allLeagueYears.AddRange(leaguesToCount); var publishers = leaguesToCount.SelectMany(x => x.Publishers).ToList(); var publisherGames = publishers.SelectMany(x => x.PublisherGames); var gamesWithPoints = publisherGames.Where(x => x.FantasyPoints.HasValue && !x.ManualCriticScore.HasValue).ToList(); allGamesWithPoints.AddRange(gamesWithPoints); } var allStandardGamesWithPoints = allGamesWithPoints.Where(x => !x.CounterPick).ToList(); var allCounterPicksWithPoints = allGamesWithPoints.Where(x => x.CounterPick).ToList(); var averageStandardPoints = allStandardGamesWithPoints.Select(x => x.FantasyPoints !.Value).DefaultIfEmpty(0m).Average(); var averagePickupOnlyStandardPoints = allStandardGamesWithPoints.Where(x => !x.OverallDraftPosition.HasValue).Select(x => x.FantasyPoints !.Value).DefaultIfEmpty(0m).Average(); var averageCounterPickPoints = allCounterPicksWithPoints.Select(x => x.FantasyPoints !.Value).DefaultIfEmpty(0m).Average(); Dictionary <int, List <decimal> > pointsForPosition = new Dictionary <int, List <decimal> >(); foreach (var leagueYear in allLeagueYears) { var publishers = leagueYear.Publishers; var orderedGames = publishers.SelectMany(x => x.PublisherGames).Where(x => !x.CounterPick & x.FantasyPoints.HasValue && !x.ManualCriticScore.HasValue).OrderBy(x => x.Timestamp).ToList(); for (var index = 0; index < orderedGames.Count; index++) { var game = orderedGames[index]; var pickPosition = index + 1; if (!pointsForPosition.ContainsKey(pickPosition)) { pointsForPosition[pickPosition] = new List <decimal>(); } pointsForPosition[pickPosition].Add(game.FantasyPoints !.Value); } } var averageStandardGamePointsByPickPosition = pointsForPosition.Select(position => new AveragePickPositionPoints(position.Key, position.Value.Count, position.Value.Average())).ToList(); var systemWideValues = new SystemWideValues(averageStandardPoints, averagePickupOnlyStandardPoints, averageCounterPickPoints, averageStandardGamePointsByPickPosition); await _fantasyCriticRepo.UpdateSystemWideValues(systemWideValues); }
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); }
public MinimalPublisherViewModel(LeagueYear leagueYear, Publisher publisher, LocalDate currentDate, bool userIsInLeague, bool outstandingInvite, SystemWideValues systemWideValues) { PublisherID = publisher.PublisherID; LeagueID = leagueYear.League.LeagueID; UserID = publisher.User.Id; PublisherName = publisher.PublisherName; PublisherIcon = publisher.PublisherIcon; LeagueName = leagueYear.League.LeagueName; PlayerName = publisher.User.UserName; Year = leagueYear.Year; DraftPosition = publisher.DraftPosition; AutoDraft = publisher.AutoDraft; AverageCriticScore = publisher.AverageCriticScore; TotalFantasyPoints = publisher.GetTotalFantasyPoints(leagueYear.SupportedYear, leagueYear.Options); TotalProjectedPoints = publisher.GetProjectedFantasyPoints(leagueYear, systemWideValues, currentDate); Budget = publisher.Budget; UserIsInLeague = userIsInLeague; PublicLeague = leagueYear.Options.PublicLeague; OutstandingInvite = outstandingInvite; var dateToCheck = currentDate; if (leagueYear.SupportedYear.Finished) { dateToCheck = new LocalDate(Year, 12, 31); } GamesReleased = publisher.PublisherGames .Where(x => !x.CounterPick) .Where(x => x.MasterGame is not null) .Count(x => x.MasterGame !.MasterGame.IsReleased(dateToCheck)); var allWillRelease = publisher.PublisherGames .Where(x => !x.CounterPick) .Where(x => x.MasterGame is not null) .Count(x => x.WillRelease()); GamesWillRelease = allWillRelease - GamesReleased; FreeGamesDropped = publisher.FreeGamesDropped; WillNotReleaseGamesDropped = publisher.WillNotReleaseGamesDropped; WillReleaseGamesDropped = publisher.WillReleaseGamesDropped; FreeDroppableGames = leagueYear.Options.FreeDroppableGames; WillNotReleaseDroppableGames = leagueYear.Options.WillNotReleaseDroppableGames; WillReleaseDroppableGames = leagueYear.Options.WillReleaseDroppableGames; }
public decimal GetProjectedFantasyPoints(LeagueYear leagueYear, SystemWideValues systemWideValues, LocalDate currentDate) { var leagueOptions = leagueYear.Options; bool ineligiblePointsShouldCount = leagueYear.Options.HasSpecialSlots; var slots = GetPublisherSlots(leagueOptions); decimal projectedScore = 0; foreach (var slot in slots) { bool countSlotAsValid = ineligiblePointsShouldCount || slot.SlotIsValid(leagueYear); var slotScore = slot.GetProjectedOrRealFantasyPoints(countSlotAsValid, leagueOptions.ScoringSystem, systemWideValues, leagueYear.StandardGamesTaken, leagueYear.TotalNumberOfStandardGames, currentDate); projectedScore += slotScore; } return(projectedScore); }
public async Task <ActionResult <ActionedGameSetViewModel> > ActionProcessingDryRun() { var supportedYears = await _interLeagueService.GetSupportedYears(); SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay); IReadOnlyList <LeagueYear> allLeagueYears = await _adminService.GetLeagueYears(currentYear.Year); var nextBidTime = _clock.GetNextBidTime(); var actionResults = await _adminService.GetActionProcessingDryRun(systemWideValues, currentYear.Year, nextBidTime, allLeagueYears); IEnumerable <LeagueAction> failingActions = actionResults.Results.LeagueActions.Where(x => x.IsFailed); var failingActionGames = failingActions.Select(x => x.MasterGameName).Distinct(); var currentDate = _clock.GetToday(); var allBids = await _gameAcquisitionService.GetActiveAcquisitionBids(currentYear, allLeagueYears); var distinctBids = allBids.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame); List <MasterGameViewModel> pickupGames = distinctBids .Select(x => new MasterGameViewModel(x.MasterGame, currentDate, failingActionGames.Contains(x.MasterGame.GameName))) .ToList(); var allDrops = await _gameAcquisitionService.GetActiveDropRequests(currentYear, allLeagueYears); var distinctDrops = allDrops.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame); List <MasterGameViewModel> dropGames = distinctDrops .Select(x => new MasterGameViewModel(x.MasterGame, currentDate, failingActionGames.Contains(x.MasterGame.GameName))) .ToList(); pickupGames = pickupGames.OrderByDescending(x => x.Error).ThenBy(x => x.MaximumReleaseDate).ToList(); dropGames = dropGames.OrderByDescending(x => x.Error).ThenBy(x => x.MaximumReleaseDate).ToList(); var leagueYearDictionary = allLeagueYears.ToDictionary(x => x.Key); var leagueActionViewModels = actionResults.Results.LeagueActions.Select(x => new LeagueActionViewModel(leagueYearDictionary[x.Publisher.LeagueYearKey], x)).ToList(); var leagueActionSets = actionResults.GetLeagueActionSets(true); var leagueActionSetViewModels = leagueActionSets.Select(x => new LeagueActionProcessingSetViewModel(x, currentDate)); ActionedGameSetViewModel fullSet = new ActionedGameSetViewModel(pickupGames, dropGames, leagueActionViewModels, leagueActionSetViewModels); return(Ok(fullSet)); }
public async Task <ActionResult <ActionedGameSet> > GetCurrentActionedGames() { var supportedYears = await _interLeagueService.GetSupportedYears(); SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay); var bidResults = await _fantasyCriticService.GetBidProcessingDryRun(systemWideValues, currentYear.Year); IEnumerable <LeagueAction> failingBids = bidResults.LeagueActions.Where(x => x.IsFailed); var failingBidGames = failingBids.Select(x => x.MasterGameName).Distinct(); var dropResults = await _fantasyCriticService.GetDropProcessingDryRun(currentYear.Year); IEnumerable <LeagueAction> failingDrops = dropResults.LeagueActions.Where(x => x.IsFailed); var failingDropGames = failingDrops.Select(x => x.MasterGameName).Distinct(); List <MasterGameViewModel> pickupGames = new List <MasterGameViewModel>(); List <MasterGameViewModel> bidGames = new List <MasterGameViewModel>(); foreach (var supportedYear in supportedYears) { var allBids = await _gameAcquisitionService.GetActiveAcquistitionBids(supportedYear); var distinctBids = allBids.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame); var bidVMs = distinctBids.Select(x => new MasterGameViewModel(x.MasterGame, _clock, failingBidGames.Contains(x.MasterGame.GameName))); pickupGames.AddRange(bidVMs); var allDrops = await _gameAcquisitionService.GetActiveDropRequests(supportedYear); var distinctDrops = allDrops.SelectMany(x => x.Value).DistinctBy(x => x.MasterGame); var dropVMs = distinctDrops.Select(x => new MasterGameViewModel(x.MasterGame, _clock, failingDropGames.Contains(x.MasterGame.GameName))); bidGames.AddRange(dropVMs); } pickupGames = pickupGames.OrderByDescending(x => x.Error).ThenBy(x => x.SortableEstimatedReleaseDate).ToList(); bidGames = bidGames.OrderByDescending(x => x.Error).ThenBy(x => x.SortableEstimatedReleaseDate).ToList(); ActionedGameSet fullSet = new ActionedGameSet(pickupGames, bidGames); return(Ok(fullSet)); }
public decimal GetProjectedFantasyPoints(ScoringSystem scoringSystem, SystemWideValues systemWideValues, int standardGamesTaken, int numberOfStandardGames) { if (PublisherGame is null) { return(systemWideValues.GetEmptySlotAveragePoints(CounterPick, standardGamesTaken + 1, numberOfStandardGames)); } if (PublisherGame.MasterGame is null) { if (PublisherGame.ManualCriticScore.HasValue) { return(PublisherGame.ManualCriticScore.Value); } return(systemWideValues.GetEmptySlotAveragePoints(CounterPick, standardGamesTaken + 1, numberOfStandardGames)); } return(PublisherGame.MasterGame.GetProjectedFantasyPoints(scoringSystem, CounterPick)); }
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).Average(x => x.FantasyPoints.Value); var averageCounterPickPoints = allGamesWithPoints.Where(x => x.CounterPick).Average(x => x.FantasyPoints.Value); var systemWideValues = new SystemWideValues(averageStandardPoints, averageCounterPickPoints); await _interLeagueService.UpdateSystemWideValues(systemWideValues); }
public async Task <FinalizedActionProcessingResults> GetActionProcessingDryRun(SystemWideValues systemWideValues, int year, Instant processingTime, IReadOnlyList <LeagueYear> allLeagueYears) { IReadOnlyDictionary <LeagueYear, IReadOnlyList <PickupBid> > leaguesAndBids = await _fantasyCriticRepo.GetActivePickupBids(year, allLeagueYears); IReadOnlyDictionary <LeagueYear, IReadOnlyList <DropRequest> > leaguesAndDropRequests = await _fantasyCriticRepo.GetActiveDropRequests(year, allLeagueYears); var onlyLeaguesWithActions = leaguesAndBids .Where(x => x.Value.Any()).Select(x => x.Key) .Concat(leaguesAndDropRequests.Where(x => x.Value.Any()).Select(x => x.Key)) .Distinct().Select(x => x.Key).ToHashSet(); var publishersInLeagues = allLeagueYears.SelectMany(x => x.Publishers).Where(x => onlyLeaguesWithActions.Contains(x.LeagueYearKey)); var masterGameYears = await _interLeagueService.GetMasterGameYears(year); var masterGameYearDictionary = masterGameYears.ToDictionary(x => x.MasterGame.MasterGameID); FinalizedActionProcessingResults results = _actionProcessingService.ProcessActions(systemWideValues, leaguesAndBids, leaguesAndDropRequests, publishersInLeagues, processingTime, masterGameYearDictionary); return(results); }
public async Task <IActionResult> ProcessActions() { var systemWideSettings = await _interLeagueService.GetSystemWideSettings(); if (!systemWideSettings.ActionProcessingMode) { return(BadRequest("Turn on action processing mode first.")); } var isProduction = string.Equals(_webHostEnvironment.EnvironmentName, "PRODUCTION", StringComparison.OrdinalIgnoreCase); var today = _clock.GetCurrentInstant().ToEasternDate(); var acceptableDays = new List <IsoDayOfWeek> { IsoDayOfWeek.Saturday, IsoDayOfWeek.Sunday }; if (!acceptableDays.Contains(today.DayOfWeek) && isProduction) { return(BadRequest($"You probably didn't mean to process pickups on a {today.DayOfWeek}")); } SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var supportedYears = await _interLeagueService.GetSupportedYears(); foreach (var supportedYear in supportedYears) { if (supportedYear.Finished || !supportedYear.OpenForPlay) { continue; } await _adminService.ProcessActions(systemWideValues, supportedYear.Year); } return(Ok()); }
public async Task <FileStreamResult> ComparableActionProcessingDryRun() { var supportedYears = await _interLeagueService.GetSupportedYears(); SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay); IReadOnlyList <LeagueYear> allLeagueYears = await _adminService.GetLeagueYears(currentYear.Year); var nextBidTime = _clock.GetNextBidTime(); var actionResults = await _adminService.GetActionProcessingDryRun(systemWideValues, currentYear.Year, nextBidTime, allLeagueYears); var viewModels = actionResults.Results.LeagueActions.Select(x => new ComparableLeagueActionViewModel(x)) .OrderBy(x => x.LeagueID).ThenBy(x => x.PublisherID).ToList(); var csvStream = CSVUtilities.GetCSVStream(viewModels); return(new FileStreamResult(csvStream, "text/csv") { FileDownloadName = $"ComparableActions_{nextBidTime.ToEasternDate().ToISOString()}.csv" }); }
public PublisherSlotViewModel(PublisherSlot slot, LocalDate currentDate, LeagueYear leagueYear, SystemWideValues systemWideValues, IReadOnlySet <Guid> counterPickedPublisherGameIDs) { SlotNumber = slot.SlotNumber; OverallSlotNumber = slot.OverallSlotNumber; CounterPick = slot.CounterPick; if (slot.SpecialGameSlot is not null) { SpecialSlot = new SpecialGameSlotViewModel(slot.SpecialGameSlot); } if (slot.PublisherGame is not null) { PublisherGame = new PublisherGameViewModel(slot.PublisherGame, currentDate, counterPickedPublisherGameIDs.Contains(slot.PublisherGame.PublisherGameID), leagueYear.Options.CounterPicksBlockDrops); } EligibilityErrors = slot.GetClaimErrorsForSlot(leagueYear).Select(x => x.Error).ToList(); GameMeetsSlotCriteria = !EligibilityErrors.Any(); ProjectedFantasyPoints = slot.GetProjectedFantasyPoints(leagueYear.Options.ScoringSystem, systemWideValues, leagueYear.StandardGamesTaken, leagueYear.TotalNumberOfStandardGames); }
public PublisherViewModel(Publisher publisher, IClock clock, Maybe <Publisher> nextDraftPublisher, bool userIsInLeague, bool outstandingInvite, SystemWideValues systemWideValues, bool yearFinished) { PublisherID = publisher.PublisherID; LeagueID = publisher.LeagueYear.League.LeagueID; PublisherName = publisher.PublisherName; LeagueName = publisher.LeagueYear.League.LeagueName; PlayerName = publisher.User.DisplayName; Year = publisher.LeagueYear.Year; DraftPosition = publisher.DraftPosition; AutoDraft = publisher.AutoDraft; Games = publisher.PublisherGames .OrderBy(x => x.Timestamp) .Select(x => new PublisherGameViewModel(x, clock, publisher.LeagueYear.Options.ScoringSystem, systemWideValues)) .ToList(); AverageCriticScore = publisher.AverageCriticScore; TotalFantasyPoints = publisher.TotalFantasyPoints; TotalProjectedPoints = publisher.GetProjectedFantasyPoints(publisher.LeagueYear.Options, systemWideValues, yearFinished, false, clock); Budget = publisher.Budget; if (nextDraftPublisher.HasValue && nextDraftPublisher.Value.PublisherID == publisher.PublisherID) { NextToDraft = true; } UserIsInLeague = userIsInLeague; PublicLeague = publisher.LeagueYear.Options.PublicLeague; OutstandingInvite = outstandingInvite; FreeGamesDropped = publisher.FreeGamesDropped; WillNotReleaseGamesDropped = publisher.WillNotReleaseGamesDropped; WillReleaseGamesDropped = publisher.WillReleaseGamesDropped; FreeDroppableGames = publisher.LeagueYear.Options.FreeDroppableGames; WillNotReleaseDroppableGames = publisher.LeagueYear.Options.WillNotReleaseDroppableGames; WillReleaseDroppableGames = publisher.LeagueYear.Options.WillReleaseDroppableGames; }
public async Task <ActionResult <List <LeagueActionViewModel> > > GetCurrentActionedGames() { var supportedYears = await _interLeagueService.GetSupportedYears(); SystemWideValues systemWideValues = await _interLeagueService.GetSystemWideValues(); var currentYear = supportedYears.First(x => !x.Finished && x.OpenForPlay); var bidResults = await _fantasyCriticService.GetBidProcessingDryRun(systemWideValues, currentYear.Year); IEnumerable <LeagueAction> failingBids = bidResults.LeagueActions.Where(x => x.IsFailed); var failingBidGames = failingBids.Select(x => x.MasterGameName).Distinct(); var dropResults = await _fantasyCriticService.GetDropProcessingDryRun(currentYear.Year); IEnumerable <LeagueAction> failingDrops = dropResults.LeagueActions.Where(x => x.IsFailed); var failingDropGames = failingDrops.Select(x => x.MasterGameName).Distinct(); List <MasterGame> masterGames = new List <MasterGame>(); foreach (var supportedYear in supportedYears) { var allBids = await _gameAcquisitionService.GetActiveAcquistitionBids(supportedYear); var allDrops = await _gameAcquisitionService.GetActiveDropRequests(supportedYear); masterGames.AddRange(allBids.SelectMany(x => x.Value.Select(y => y.MasterGame))); masterGames.AddRange(allDrops.SelectMany(x => x.Value.Select(y => y.MasterGame))); } masterGames = masterGames.Distinct().ToList(); var failingGames = failingBidGames.Concat(failingDropGames); var vms = masterGames.Distinct().Select(x => new MasterGameViewModel(x, _clock, failingGames.Contains(x.GameName))); return(Ok(vms)); }
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); }
public decimal GetProjectedOrRealFantasyPoints(bool gameIsValidInSlot, ScoringSystem scoringSystem, SystemWideValues systemWideValues, int standardGamesTaken, int numberOfStandardGames, LocalDate currentDate) { var realFantasyPoints = GetFantasyPoints(gameIsValidInSlot, scoringSystem, currentDate); if (realFantasyPoints.HasValue) { return(realFantasyPoints.Value); } return(GetProjectedFantasyPoints(scoringSystem, systemWideValues, standardGamesTaken, numberOfStandardGames)); }
public PublisherViewModel(LeagueYear leagueYear, Publisher publisher, LocalDate currentDate, bool userIsInLeague, bool outstandingInvite, SystemWideValues systemWideValues, IReadOnlySet <Guid> counterPickedPublisherGameIDs) : this(leagueYear, publisher, currentDate, null, userIsInLeague, outstandingInvite, systemWideValues, counterPickedPublisherGameIDs) { }
public PublisherViewModel(LeagueYear leagueYear, Publisher publisher, LocalDate currentDate, Publisher?nextDraftPublisher, bool userIsInLeague, bool outstandingInvite, SystemWideValues systemWideValues, IReadOnlySet <Guid> counterPickedPublisherGameIDs) { PublisherID = publisher.PublisherID; LeagueID = leagueYear.League.LeagueID; UserID = publisher.User.Id; PublisherName = publisher.PublisherName; PublisherIcon = publisher.PublisherIcon; LeagueName = leagueYear.League.LeagueName; PlayerName = publisher.User.UserName; Year = leagueYear.Year; DraftPosition = publisher.DraftPosition; AutoDraft = publisher.AutoDraft; Games = publisher.PublisherGames .OrderBy(x => x.Timestamp) .Select(x => new PublisherGameViewModel(x, currentDate, counterPickedPublisherGameIDs.Contains(x.PublisherGameID), leagueYear.Options.CounterPicksBlockDrops)) .ToList(); FormerGames = publisher.FormerPublisherGames .OrderBy(x => x.PublisherGame.Timestamp) .Select(x => new PublisherGameViewModel(x, currentDate)) .ToList(); GameSlots = publisher.GetPublisherSlots(leagueYear.Options) .Select(x => new PublisherSlotViewModel(x, currentDate, leagueYear, systemWideValues, counterPickedPublisherGameIDs)) .ToList(); AverageCriticScore = publisher.AverageCriticScore; TotalFantasyPoints = publisher.GetTotalFantasyPoints(leagueYear.SupportedYear, leagueYear.Options); TotalProjectedPoints = publisher.GetProjectedFantasyPoints(leagueYear, systemWideValues, currentDate); Budget = publisher.Budget; if (nextDraftPublisher is not null && nextDraftPublisher.PublisherID == publisher.PublisherID) { NextToDraft = true; } UserIsInLeague = userIsInLeague; PublicLeague = leagueYear.Options.PublicLeague; OutstandingInvite = outstandingInvite; var dateToCheck = currentDate; if (leagueYear.SupportedYear.Finished) { dateToCheck = new LocalDate(Year, 12, 31); } GamesReleased = publisher.PublisherGames .Where(x => !x.CounterPick) .Where(x => x.MasterGame is not null) .Count(x => x.MasterGame !.MasterGame.IsReleased(dateToCheck)); var allWillRelease = publisher.PublisherGames .Where(x => !x.CounterPick) .Where(x => x.MasterGame is not null) .Count(x => x.WillRelease()); GamesWillRelease = allWillRelease - GamesReleased; FreeGamesDropped = publisher.FreeGamesDropped; WillNotReleaseGamesDropped = publisher.WillNotReleaseGamesDropped; WillReleaseGamesDropped = publisher.WillReleaseGamesDropped; FreeDroppableGames = leagueYear.Options.FreeDroppableGames; WillNotReleaseDroppableGames = leagueYear.Options.WillNotReleaseDroppableGames; WillReleaseDroppableGames = leagueYear.Options.WillReleaseDroppableGames; }
public PublisherViewModel(Publisher publisher, IClock clock, bool userIsInLeague, bool outstandingInvite, SystemWideValues systemWideValues, bool yearFinished) : this(publisher, clock, Maybe <Publisher> .None, userIsInLeague, outstandingInvite, systemWideValues, yearFinished) { }
public async Task ProcessPickups(SystemWideValues systemWideValues, int year) { var results = await GetBidProcessingDryRun(systemWideValues, year); await _fantasyCriticRepo.SaveProcessedBidResults(results); }
public SystemWideValuesEntity(SystemWideValues domain) { AverageStandardGamePoints = domain.AverageStandardGamePoints; AverageCounterPickPoints = domain.AverageCounterPickPoints; }