Exemplo n.º 1
0
        /// <summary />
        public Item(NFLPlayer p)
        {
            this.PlayerData = p;

            Messenger.Default.Register<MarkedPlayerChanged>(this,
                (m) =>
                {
                    if (m.Name == this.PlayerData.Name)
                    {
                        this.RaisePropertyChanged("IsHighlighted");
                    }
                });
        }
Exemplo n.º 2
0
        /// <summary />
        public PlayerViewModel(NFLPlayer p)
        {
            this.PlayerData = p;

            // cache the name+injury status here.
            this.Name = this.PlayerData.Name + GetInjuryStatus();

            Messenger.Default.Register <MarkedPlayerChanged>(this,
                                                             (m) =>
            {
                if (m.Name == this.PlayerData.Name)
                {
                    this.RaisePropertyChanged("IsHighlighted");
                }
            });
        }
Exemplo n.º 3
0
        private void AssignTeam(NFLPlayer player, XElement element)
        {
            // if the player has played for multiple teams, we
            // only want the most recent team that they have
            // played for.
            var    fields   = element.Elements().ToList();
            string teamcode = fields[1].Value;

            NFLTeam team = this.context.GetTeam(teamcode);

            if (player.Team != team)
            {
                // if team has changed, we will update -- we only need to track the most recent
                // team.  This is all that matters.
                player.Team = team;
            }
        }
Exemplo n.º 4
0
        public NFLPlayer GetPlayer(string uuid, Action <NFLPlayer> initializer = null)
        {
            NFLPlayer player;

            bool exists = this.playerCache.TryGetValue(uuid, out player);

            if (!exists)
            {
                // create the player and update the cache
                player = new NFLPlayer(uuid);
                this.playerCache.Add(uuid, player);
                if (initializer != null)
                {
                    initializer(player);
                }
            }

            return(player);
        }
Exemplo n.º 5
0
        private NFLPlayer ExtractPlayerInfo(XElement element, string baseUri)
        {
            var    fields   = element.Elements().ToList();
            string playerid = fields[0].Attribute("data-append-csv").Value;
            string name     = fields[0].Value;

            // the player must have an id and name, but position is optional
            if (playerid == null || string.IsNullOrEmpty(name))
            {
                throw new InvalidOperationException();
            }

            NFLPlayer player = this.context.GetPlayer(playerid, p =>
            {
                p.PlayerPageUri = fields[0].Element("a")?.Attribute("href")?.Value;
                p.Name          = name;
                UpdatePlayerMetadata(p, element, baseUri);
            });

            return(player);
        }
Exemplo n.º 6
0
        /// <summary />
        public static int TotalBonuses(this NFLPlayer player)
        {
            int bonuses = 0;

            foreach (Game game in player.GameLog)
            {
                Passing p = game.Passing;
                if (p != null)
                {
                    bonuses += CountBonuses(p.YDS, 300, 100);
                }

                Rushing r = game.Rushing;
                if (r != null)
                {
                    bonuses += CountBonuses(r.YDS, 100, 50);
                }

                Receiving c = game.Receiving;
                if (c != null)
                {
                    bonuses += CountBonuses(c.YDS, 100, 50);
                }

                Kicking k = game.Kicking;
                if (k != null)
                {
                    // unable to determine bonuses for kicking yet
                }

                Defense dst = game.Defense;
                if (dst != null)
                {
                    // unable to determine bonuses for defense yet
                }
            }

            return(bonuses);
        }
Exemplo n.º 7
0
        /// <summary />
        public static int FanastyPointsInRecentGames(this NFLPlayer p, int gameCount)
        {
            int points = 0;

            IEnumerable <Game> games = (from g in p.GameLog
                                        orderby g.Week descending
                                        select g);

            int i = 0;

            foreach (Game game in games)
            {
                i      += 1;
                points += game.GetFanastyPoints();

                if (i >= gameCount)
                {
                    // once we have process the requested games, we will bail out.
                    break;
                }
            }

            return(points);
        }
Exemplo n.º 8
0
 /// <summary />
 private QB(NFLPlayer p)
     : base(p)
 {
 }
Exemplo n.º 9
0
        /// <summary />
        public NFLPlayer GetPlayer(int uuid)
        {
            NFLPlayer player;

            bool exists = this.playerCache.TryGetValue(uuid, out player);
            if (!exists)
            {
                // create the player and update the cache
                player = new NFLPlayer(uuid);
                this.playerCache.Add(uuid, player);
            }

            return player;
        }
Exemplo n.º 10
0
Arquivo: K.cs Projeto: adamwyss/waffle
 public K(NFLPlayer p)
     : base(p)
 {
 }
Exemplo n.º 11
0
        private void UpdatePlayerMetadata(NFLPlayer player, string playerPageUri, string baseUri)
        {
            string playerUri = new Uri(new Uri(baseUri), playerPageUri).AbsoluteUri;
            string xhtml     = this.httpClient.DownloadString(playerUri);

            const string start = "</div><!-- div.media-item --><div itemscope itemtype=\"https://schema.org/Person\" >";
            const string end   = "  <strong>Born:</strong> ";

            string[] exclude       = { };
            XElement parsedElement = ExtractRawData(xhtml, start, end, exclude, true, s => s + "</p></div>");

            if (parsedElement != null)
            {
                foreach (var p in parsedElement.Elements("p"))
                {
                    string value = p.Element("strong")?.Value;
                    switch (value)
                    {
                    case "Position":
                    {
                        var position = p.FirstNode.NextNode.ToString().TrimStart(new char[] { ':' }).Trim();
                        switch (position)
                        {
                        case "QB":
                            player.Position = FanastyPosition.QB;
                            break;

                        case "RB":
                        case "FB":
                            player.Position = FanastyPosition.RB;
                            break;

                        case "WR":
                        case "TE":
                            player.Position = FanastyPosition.WR;
                            break;

                        case "K":
                            player.Position = FanastyPosition.K;
                            break;

                        default:
                            player.Position = FanastyPosition.UNKNOWN;
                            break;
                        }
                    }
                    break;

                    case "Team":
                    {
                        var statusNode = p.Element("span").FirstNode.NextNode;
                        if (statusNode != null)
                        {
                            // data source no longer provides injury status
                            string status = statusNode.ToString().Trim();
                            player.Status = new InjuryStatus()
                            {
                                Reason = status, Status = PlayerInjuryStatus.Out
                            };
                        }
                        else
                        {
                            player.Status = null;
                        }
                    }
                    break;
                    }
                }
            }
        }
Exemplo n.º 12
0
 /// <summary />
 public static int GamesPlayed(this NFLPlayer p)
 {
     // count all games that the player played in
     return(p.GameLog.Count(g => !g.IsDNP()));
 }
Exemplo n.º 13
0
 /// <summary />
 public WR(NFLPlayer p)
     : base(p)
 {
 }