private static void GetPayloadOwners(Payload payload, PlayerStatsController playerStatsController, OwnersController ownerController, OwnerTeamsController ownerTeamsController, PlayersController playersController, SeasonWeeks seasonWeek) { var leaguePoints = ownerTeamsController.GetLeaguePoints(seasonWeek.SeasonWeekId); payload.PayloadOwners = new List<PayloadOwner>(); foreach (var owner in ownerController.GetOwners()) { payload.PayloadOwners.Add(new PayloadOwner { Owner = owner, OwnerPoints = leaguePoints.Where(lp => lp.UniqueId == owner.UniqueId).First(), OwnerPlayerStats = playerStatsController.GetPlayerStatsForOwnerWeek(owner.UniqueId, seasonWeek.SeasonWeekId), OwnerTeam = playersController.GetOwnersTeamSimulatedWeek(owner.UniqueId, seasonWeek.SeasonWeekId) }); } }
private static void GetPayloadCurrentOwner(Payload payload, PlayerStatsController playerStatsController, OwnersController ownerController, OwnerTeamsController ownerTeamsController, PlayersController playersController, SeasonWeeks seasonWeek, string uniqueId) { payload.CurrentOwner = ownerController.GetOwnerByUniqueId(uniqueId); payload.CurrentTeam = playersController.GetOwnersTeamSimulatedWeek(uniqueId, seasonWeek.SeasonWeekId); payload.CurrentOwnerPlayerStats = playerStatsController.GetPlayerStatsForOwnerWeek(uniqueId, seasonWeek.SeasonWeekId); payload.Owners = ownerController.GetOwners(); }
public string GetOwnerPayload(string uniqueId, int seasonWeekId, string owners) { var payload = new Payload(); PlayerStatsController playerStatsController = new PlayerStatsController(); OwnersController ownerController = new OwnersController(); OwnerTeamsController ownerTeamsController = new OwnerTeamsController(); WeeksController weeksController = new WeeksController(); PlayersController playersController = new PlayersController(); var ownerExists = context.Owners.Where(o => o.UniqueId == uniqueId).First(); var seasonWeek = new SeasonWeeks(); if (seasonWeekId == -1) { seasonWeek = weeksController.GetSeasonWeek(DateTime.Now.ToShortDateString()); } else { seasonWeek = weeksController.GetSeasonWeek(seasonWeekId); } GetPayloadOwners(payload, playerStatsController, ownerController, ownerTeamsController, playersController, seasonWeek); return Compression.Compress(JsonConvert.SerializeObject(payload)); }
public string GetUpdatePayload(string uniqueId, int seasonWeekId, string update) { var payload = new Payload(); PlayerStatsController playerStatsController = new PlayerStatsController(); PositionLimitsController positionLimitsController = new PositionLimitsController(); OwnersController ownerController = new OwnersController(); OwnerTeamsController ownerTeamsController = new OwnerTeamsController(); WeeksController weeksController = new WeeksController(); GamesController gamesController = new GamesController(); PlayersController playersController = new PlayersController(); RanksController ranksController = new RanksController(); var ownerExists = context.Owners.Where(o => o.UniqueId == uniqueId).First(); var seasonWeek = new SeasonWeeks(); if (seasonWeekId == -1) { seasonWeek = weeksController.GetSeasonWeek(DateTime.Now.ToShortDateString()); } else { seasonWeek = weeksController.GetSeasonWeek(seasonWeekId); } GetPayloadCurrentOwner(payload, playerStatsController, ownerController, ownerTeamsController, playersController, seasonWeek, uniqueId); GetPayloadOwners(payload, playerStatsController, ownerController, ownerTeamsController, playersController, seasonWeek); //GetPayloadPositionLimits(payload, positionLimitsController); //GetPayloadWeeks(payload, weeksController); GetPayloadGames(payload, gamesController, seasonWeek); //GetPayloadPlayers(payload, playersController, ownerExists); GetPayloadRanks(payload, ranksController, seasonWeek); return Compression.Compress(JsonConvert.SerializeObject(payload)); }
/// <summary> /// Get the owner rankings for the current week. /// </summary> public IEnumerable<Ranks> GetRanks(int seasonWeekId) { List<Ranks> ranks = new List<Ranks>(); WeeksController controller = new WeeksController(); OwnerTeamsController otController = new OwnerTeamsController(); var seasonWeek = controller.GetSeasonWeek(seasonWeekId); int seasonTypeId = seasonWeek.SeasonTypeId; int seasonYear = seasonWeek.SeasonYear; int currentWeekNum = seasonWeek.WeekNum; foreach (var owner in context.Owners) { Ranks rankThisWeek = new Ranks { OwnerId = owner.OwnerId, TeamName = owner.TeamName, OwnerName = owner.OwnerName, DollarsMade = 0, WeeksWon = new List<WeekWon>(), TotalPoints = 0, PayoutDollars = 0, WeeksWonDollars = 0 }; ranks.Add(rankThisWeek); } var dollarsPayout = 50; var query = NPGGFFLApi.queries.RanksWeeksWonQuery; query = query.Replace("{{:PlayerPointsQuery}}", NPGGFFLApi.queries.PlayerPointsQuery); query = query.Replace("{{:GameFilter}}", string.Empty); query = query.Replace("{{:PlayerFilter}}", string.Empty); query = query.Replace("{{:SeasonYearFilter}}", string.Format("and pp.SeasonYear = {0}", seasonYear)); query = query.Replace("{{:SeasonTypeFilter}}", string.Format("and pp.SeasonTypeId = {0}", seasonTypeId)); query = query.Replace("{{:SeasonWeekFilter}}", string.Format("and pp.SeasonEndDtm <= '{0}' and pp.WeekNum <= {1}", DateTime.Now, currentWeekNum)); var winningOwners = context.ExecuteQuery<WinningOwners>(query); foreach (var wo in winningOwners) { var rankExists = ranks.Where(r => r.OwnerId == wo.OwnerId).FirstOrDefault(); if (rankExists != null) { rankExists.DollarsMade += dollarsPayout; rankExists.WeeksWonDollars += dollarsPayout; rankExists.WeeksWon.Add(new WeekWon { WeekNum = wo.WeekNum }); } } var rankQuery = NPGGFFLApi.queries.RanksQuery; rankQuery = rankQuery.Replace("{{:PlayerPointsQuery}}", NPGGFFLApi.queries.PlayerPointsQuery); rankQuery = rankQuery.Replace("{{:GameFilter}}", string.Empty); rankQuery = rankQuery.Replace("{{:PlayerFilter}}", string.Empty); rankQuery = rankQuery.Replace("{{:SeasonYearFilter}}", string.Format("and pp.SeasonYear = {0}", seasonYear)); rankQuery = rankQuery.Replace("{{:SeasonTypeFilter}}", string.Format("and pp.SeasonTypeId = {0}", seasonTypeId)); rankQuery = rankQuery.Replace("{{:SeasonWeekFilter}}", string.Format("and pp.SeasonEndDtm <= '{0}' and pp.WeekNum <= {1}", DateTime.Now, currentWeekNum)); var ranksOwners = context.ExecuteQuery<RanksOwners>(rankQuery); foreach (var ro in ranksOwners) { var rankExists = ranks.Where(r => r.OwnerId == ro.OwnerId).FirstOrDefault(); if (rankExists != null) { rankExists.TotalPoints = ro.TotalPoints; } } int rankNum = 1; foreach (var rank in ranks.OrderByDescending(r => r.TotalPoints)) { var payoutForPosition = context.LeaguePayouts.Where(lp => lp.RankNum == rankNum).FirstOrDefault(); if (payoutForPosition != null) { rank.DollarsMade += payoutForPosition.DollarAmount; rank.PayoutDollars += payoutForPosition.DollarAmount; } rankNum++; } return ranks.OrderByDescending(r => r.TotalPoints).ThenBy(r => r.OwnerName); }