Exemplo n.º 1
0
        public GameAnalyticStats GetGameAnalyticStats(int gameId)
        {
            WeeksController controller = new WeeksController();
            var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToString());

            var query = NPGGFFLApi.queries.GameAnalyticsQuery;
            query = query.Replace("{{:SeasonWeekFilter}}", string.Format(" sw.SeasonYear = {0} and sw.SeasonTypeId = {1} and sw.WeekNum <= {2}", seasonWeek.SeasonYear, seasonWeek.SeasonTypeId, seasonWeek.WeekNum));
            query = query.Replace("{{:GameFilter}}", string.Format("g.gameid = {0}", gameId));
            return context.ExecuteQuery<GameAnalyticStats>(query).First();
        }
Exemplo n.º 2
0
        private IEnumerable<PlayerPickLine> GetPercentPicked(string position)
        {
            WeeksController controller = new WeeksController();
            var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToString());

            //var playerPickLines = context.OwnerTeams
            //		.Where(ot => ot.SeasonWeeks.SeasonYear == seasonWeek.SeasonYear && ot.SeasonWeeks.SeasonTypeId == seasonWeek.SeasonTypeId && ot.Players.Position.Name.Equals(position))
            //		.Select(ot => new
            //		{
            //			PlayerId = ot.PlayerId,
            //			PlayerName = ot.Players.Name,
            //			PositionName = ot.Players.Position.Name,
            //			LineupPriority = ot.Players.Position.LineupPriority,
            //			SeasonWeekId = ot.SeasonWeekId,
            //			WeekNum = ot.SeasonWeeks.WeekNum
            //		})
            //		.GroupBy(ot => new { ot.PlayerId, ot.PlayerName, ot.PositionName, ot.LineupPriority, ot.WeekNum, ot.SeasonWeekId })
            //		.Select(ot => new { PlayerId = ot.Key.PlayerId, PlayerName = ot.Key.PlayerName, PositionName = ot.Key.PositionName, LineupPriority = ot.Key.LineupPriority, WeekNum = ot.Key.WeekNum, SeasonWeekId = ot.Key.SeasonWeekId, TeamsPicked = ot.Count(), PercentPicked = Convert.ToInt32(Convert.ToDecimal(ot.Count()) / Convert.ToDecimal(context.Owners.Count()) * 100) })
            //		.OrderBy(ot => ot.WeekNum)
            //		.ThenBy(ot => ot.LineupPriority)
            //		.ThenByDescending(ot => ot.TeamsPicked)
            //		.Select(ot => new PlayerPickLine
            //		{
            //			PlayerId = ot.PlayerId,
            //			PlayerName = ot.PlayerName,
            //			PositionName = ot.PositionName,
            //			LineupPriority = ot.LineupPriority,
            //			WeekNum = ot.WeekNum,
            //			SeasonWeekId = ot.SeasonWeekId,
            //			TeamsPicked = ot.TeamsPicked,
            //			PercentPicked = ot.PercentPicked,
            //			PointsScoredThatWeek = GetPointsThatWeek(ot.PlayerId, ot.SeasonWeekId)
            //		});

            var query = NPGGFFLApi.queries.AnalyticsQuery;
            query = query.Replace("{{:SeasonWeekFilter}}", string.Format("and sw.SeasonYear = {0} and sw.SeasonTypeId = {1} and sw.WeekNum = {2}", seasonWeek.SeasonYear, seasonWeek.SeasonTypeId, seasonWeek.WeekNum));
            query = query.Replace("{{:PositionFilter}}", string.Format("and po.Name = '{0}'", position));
            var playerPickLines = context.ExecuteQuery<PlayerPickLine>(query).Select(ppl => new PlayerPickLine {
                PlayerId = ppl.PlayerId,
                PlayerName = ppl.PlayerName,
                PositionName = ppl.PositionName,
                LineupPriority = ppl.LineupPriority,
                WeekNum = ppl.WeekNum,
                SeasonWeekId = ppl.SeasonWeekId,
                LastSeasonWeekId = ppl.LastSeasonWeekId,
                PositionalRanking = ppl.PositionalRanking,
                PercentPickedLastWeek = ppl.PercentPickedLastWeek,
                PercentPickedThisWeek = ppl.PercentPickedThisWeek,
                OpponentRanking = ppl.OpponentRanking,
                PointsScoredLastWeek = GetPointsThatWeek(ppl.PlayerId, ppl.LastSeasonWeekId)
            });

            return playerPickLines;
        }
Exemplo n.º 3
0
        public PlayerInjury GetLatestInjury(int playerId, int seasonWeekId)
        {
            WeeksController controller = new WeeksController();
            var seasonWeek = controller.GetSeasonWeek(seasonWeekId);

            var query = NPGGFFLApi.queries.PlayerInjuryQuery;
            query = query.Replace("{{:SeasonYearFilter}}", string.Format("and sw.SeasonYear = {0} and sw.SeasonTypeId = {1}", seasonWeek.SeasonYear, seasonWeek.SeasonTypeId));
            query = query.Replace("{{:PlayerFilter}}", string.Format("pih.playerid = {0}", playerId));
            query = query.Replace("{{:SeasonWeekFilter}}", string.Format("and sw.seasonweekid = {0}", seasonWeek.SeasonWeekId));
            return context.ExecuteQuery<PlayerInjury>(query).FirstOrDefault();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Get the list of games occuring in a specified week
 /// </summary>
 /// <param name="simulatedDate">The simulated date to get games that week (mm/dd/yyyy format)</param>
 public IEnumerable<ApiGame> GetGamesThisWeek(string simulatedDate)
 {
     WeeksController controller = new WeeksController();
     var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToString());
     return GetGamesThisWeek(seasonWeek.SeasonWeekId);
 }
Exemplo n.º 5
0
 public IEnumerable<ByeGame> GetByes(string bye, int seasonWeekId)
 {
     WeeksController controller = new WeeksController();
     var query = NPGGFFLApi.queries.ByeTeamsQuery;
     query = query.Replace("{{:SeasonWeekId}}", seasonWeekId.ToString());
     return context.ExecuteQuery<ByeGame>(query);
 }
Exemplo n.º 6
0
 private static void GetPayloadWeeks(Payload payload, WeeksController weeksController)
 {
     payload.SeasonWeeks = weeksController.GetSeasonWeeks();
 }
Exemplo n.º 7
0
        public string GetWeeksPayload(string uniqueId, int seasonWeekId, string weeks)
        {
            var payload = new Payload();

            WeeksController weeksController = new WeeksController();

            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);
            }

            GetPayloadWeeks(payload, weeksController);

            return Compression.Compress(JsonConvert.SerializeObject(payload));
        }
Exemplo n.º 8
0
 public IEnumerable<Player> GetAllPlayersSort(string sort, string position, int startNum, int take)
 {
     WeeksController controller = new WeeksController();
     var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToShortDateString());
     return GetAllPlayersSort(sort, position, startNum, take, seasonWeek.SeasonWeekId);
 }
Exemplo n.º 9
0
        public string GetCurrentOwnerPayload(string uniqueId, int seasonWeekId, string owner)
        {
            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);
            }

            GetPayloadCurrentOwner(payload, playerStatsController, ownerController, ownerTeamsController, playersController, seasonWeek, uniqueId);

            return Compression.Compress(JsonConvert.SerializeObject(payload));
        }
Exemplo n.º 10
0
        private StringBuilder ExportRanks()
        {
            WeeksController weeksController = new WeeksController();
            RanksController ranksController = new RanksController();
            var seasonWeek = weeksController.GetSeasonWeek(DateTime.Now.ToString());

            StringBuilder fileContents = new StringBuilder();

            #region Write Header
            fileContents.Append(string.Join(",", new[] {
                    "OwnerId",
                    "TeamName",
                    "OwnerName",
                    "DollarsMade",
                    "WeeksWon",
                    "TotalPoints",
                    "PayoutDollars",
                    "WeeksWonDollars",
                    "\r\n"
                }));
            #endregion

            #region Write File Contents
            ranksController.GetRanks(seasonWeek.SeasonWeekId).Select(os => string.Join(",", new string[] {
                os.OwnerId.ToString(),
                os.TeamName.ToString(),
                os.OwnerName.ToString(),
                os.DollarsMade.ToString(),
                string.Join(",", os.WeeksWon.OrderBy(ww => ww.WeekNum).Select(ww => ww.WeekNum)),
                os.TotalPoints.ToString(),
                os.PayoutDollars.ToString(),
                os.WeeksWonDollars.ToString(),
                "\r\n"
            }))
            .ToList()
            .ForEach(line => fileContents.Append(line));;
            #endregion

            return fileContents;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Get Leage Scoring Breakdown for the current week
 /// </summary>
 public IEnumerable<OwnerPoints> GetLeaguePoints()
 {
     WeeksController controller = new WeeksController();
     var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToString());
     return GetLeaguePoints(seasonWeek.SeasonWeekId);
 }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Gets if a player is locked or not.
 /// </summary>
 /// <param name="playerId">The ID of the player.</param>
 public bool IsPlayerLocked(int playerId)
 {
     WeeksController controller = new WeeksController();
     var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToShortDateString());
     return GetPlayerGameThisWeek(playerId, seasonWeek.SeasonWeekId).GameDtm.AddHours(-1) <= DateTime.Now;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Get the owner's roster for the current week.
        /// </summary>
        /// <param name="uniqueId">The owner code (uniqueId) for the owner.</param>
        public IEnumerable<Player> GetOwnersTeamThisWeek(string uniqueId)
        {
            WeeksController controller = new WeeksController();
            var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToString());

            var query = NPGGFFLApi.queries.PlayerQuery;
            query = query.Replace("{{:SeasonYearFilter}}", string.Format("and sw.SeasonYear = {0} and sw.SeasonTypeId = {1}", seasonWeek.SeasonYear, seasonWeek.SeasonTypeId));
            query = query.Replace("{{:SeasonWeekFilter}}", seasonWeek.SeasonWeekId.ToString());
            query = query.Replace("{{:AdditionalFilters}}", string.Format("and p.playerid in (select distinct ot.playerid from ownerteams ot, owners o where o.ownerid = ot.ownerid and o.uniqueid = '{0}' and seasonweekid = {1})", uniqueId, seasonWeek.SeasonWeekId.ToString() ));
            query = query.Replace("{{:OrderBy}}", "order by po.lineuppriority, p.name");
            return context.ExecuteQuery<Player>(query);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Get the list of games by season week id
        /// </summary>
        /// <param name="seasonWeekId">The season week id representing the season week.</param>
        public IEnumerable<ApiGame> GetGamesThisWeek(int seasonWeekId)
        {
            WeeksController controller = new WeeksController();
            var seasonWeek = controller.GetSeasonWeek(seasonWeekId);

            AnalyticsController analytics = new AnalyticsController();

            return context.Games
                    .Where(g => g.SeasonWeekId == seasonWeek.SeasonWeekId)
                    .OrderBy(g => g.IsFinal).ThenBy(g => g.GameDtm)
                    .Select(g => new ApiGame
                    {
                        GameId = g.GameId,
                        GameDtm = g.GameDtm,
                        GameDtmUTC = g.GameDtm.ToUniversalTime(),
                        GameTimeRemaining = (g.GameTimeRemaining == null ? string.Empty : g.GameTimeRemaining),
                        HomeTeamId = g.HomeTeamId,
                        HomeAbbreviation = g.HomeTeam.Abbreviation,
                        HomeTeamName = g.HomeTeam.Name,
                        HomePictureUrl = string.Format(GAMEPICTUREROOT_URL, g.HomeTeam.Abbreviation),
                        HomeTeamUrl = string.Format(TEAMROOT_URL, g.HomeTeam.Abbreviation),
                        HomePointsScored = g.HomePointsScored,
                        HomeRecord = GetWinsLosses(context, g.HomeTeamId, seasonWeek.SeasonWeekId),
                        AwayTeamId = g.AwayTeamId,
                        AwayAbbreviation = g.AwayTeam.Abbreviation,
                        AwayTeamName = g.AwayTeam.Name,
                        AwayPictureUrl = string.Format(GAMEPICTUREROOT_URL, g.AwayTeam.Abbreviation),
                        AwayTeamUrl = string.Format(TEAMROOT_URL, g.AwayTeam.Abbreviation),
                        AwayPointsScored = g.AwayPointsScored,
                        AwayRecord = GetWinsLosses(context, g.AwayTeamId, seasonWeek.SeasonWeekId),
                        BoxScoreUrl = string.Format(BOXSCOREROOT_URL, g.GameId),
                        IsFinal = g.IsFinal,
                        GameAnalytics = analytics.GetGameAnalyticStats(g.GameId)
                    });
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        public bool SaveLineup(string fromAddress, string body)
        {
            try
            {
                WeeksController controller = new WeeksController();
                var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToShortDateString());
                var ownerExists = context.Owners.Where(o => o.EmailAddress.Contains(fromAddress)).FirstOrDefault();
                if (ownerExists == null)
                {
                    return false;
                }
                else
                {
                    var lineupText = body.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

                    List<NPGGFFL.Data.Players> lineup = new List<NPGGFFL.Data.Players>();
                    foreach (var line in lineupText)
                    {
                        if (!line.Trim().Equals(string.Empty))
                        {
                            Dictionary<int, int> playerMatches = new Dictionary<int, int>();
                            var words = line.Split(' ');
                            foreach (var word in words)
                            {
                                var playerFound = context.Players.Where(p => (p.Name.ToUpper().Contains(word.ToUpper()) || p.Alias.Contains(word.ToUpper())));
                                foreach (var player in playerFound)
                                {
                                    if (playerMatches.ContainsKey(player.PlayerId))
                                    {
                                        playerMatches[player.PlayerId]++;
                                    }
                                    else
                                    {
                                        playerMatches.Add(player.PlayerId, 1);
                                    }
                                }
                            }

                            if (playerMatches.Count() > 0)
                            {
                                var highestMatchCount = playerMatches.OrderByDescending(m => m.Value).First().Value;
                                if (playerMatches.Where(m => m.Value == highestMatchCount).Count() == 1)
                                {
                                    lineup.Add(context.Players.Where(p => p.PlayerId == playerMatches.Where(m => m.Value == highestMatchCount).First().Key).First());
                                }
                                else
                                {
                                    var distanceMatches = playerMatches.Where(m => m.Value == highestMatchCount).Select(m => new
                                    {
                                        PlayerId = m.Key
                                        ,
                                        Distance = LevenshteinDistance.Compute((context.Players.Where(p => p.PlayerId == m.Key).First().Alias == null ? context.Players.Where(p => p.PlayerId == m.Key).First().Name : context.Players.Where(p => p.PlayerId == m.Key).First().Alias).ToUpper(), line.ToUpper())
                                    }).OrderBy(m => m.Distance);

                                    var bestMatch = distanceMatches.First();
                                    lineup.Add(context.Players.Where(p => p.PlayerId == bestMatch.PlayerId).First());
                                }
                            }
                        }
                    }

                    //load lineup
                    if (lineup.Count > 0)
                    {
                        var ownerTeam = context.OwnerTeams.Where(ot => ot.OwnerId == ownerExists.OwnerId && ot.SeasonWeekId == seasonWeek.SeasonWeekId);
                        foreach (var ot in ownerTeam)
                        {
                            context.OwnerTeams.DeleteOnSubmit(ot);
                        }
                        context.SubmitChanges();

                        foreach (var player in lineup)
                        {
                            var ot = new NPGGFFL.Data.OwnerTeams
                            {
                                OwnerId = ownerExists.OwnerId,
                                PlayerId = player.PlayerId,
                                SeasonWeekId = seasonWeek.SeasonWeekId,
                                IsLocked = false
                            };
                            context.OwnerTeams.InsertOnSubmit(ot);
                        }
                        context.SubmitChanges();
                    }

                    return true;
                }
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Get all Players.
        /// </summary>
        public IEnumerable<Player> GetAllPlayers()
        {
            WeeksController controller = new WeeksController();
            var seasonWeek = controller.GetSeasonWeek(DateTime.Now.ToShortDateString());

            var query = NPGGFFLApi.queries.PlayerQuery;
            query = query.Replace("{{:SeasonYearFilter}}", string.Format("and sw.SeasonYear = {0} and sw.SeasonTypeId = {1}", seasonWeek.SeasonYear, seasonWeek.SeasonTypeId));
            query = query.Replace("{{:SeasonWeekFilter}}", seasonWeek.SeasonWeekId.ToString());
            query = query.Replace("{{:AdditionalFilters}}", string.Empty);
            query = query.Replace("{{:OrderBy}}", "order by po.lineuppriority, p.name");
            return context.ExecuteQuery<Player>(query);
        }