コード例 #1
0
        private void RecordPlayerStats(string baseUri, string week, XElement element)
        {
            NFLPlayer player = ExtractPlayerInfo(element, baseUri);

            AssignTeam(player, element);

            var  values = element.Elements().ToList();
            Game game   = new Game();

            game.Week = int.Parse(week);
            //game2.Opponent = this.context.GetTeam(values[1].Value);

            int attempts = int.Parse(values[3].Value);

            if (attempts > 0)
            {
                Passing p = game.Passing = new Passing();
                p.CMP  = int.Parse(values[2].Value);
                p.ATT  = attempts;
                p.YDS  = int.Parse(values[4].Value);
                p.LONG = int.Parse(values[9].Value);
                p.TD   = int.Parse(values[5].Value);
                p.INT  = int.Parse(values[6].Value);
            }

            int carries = int.Parse(values[11].Value);

            if (carries > 0)
            {
                Rushing r = game.Rushing = new Rushing();
                r.CAR  = carries;
                r.YDS  = int.Parse(values[12].Value);
                r.LONG = int.Parse(values[14].Value);
                r.TD   = int.Parse(values[13].Value);
            }

            int targets = int.Parse(values[15].Value);

            if (targets > 0)
            {
                Receiving c = game.Receiving = new Receiving();
                c.REC  = int.Parse(values[16].Value);
                c.YDS  = int.Parse(values[17].Value);
                c.LONG = int.Parse(values[19].Value);
                c.TD   = int.Parse(values[18].Value);
            }

            Fumbles f = game.Fumbles = new Fumbles();

            f.FUM  = int.Parse(values[20].Value);
            f.LOST = int.Parse(values[21].Value);

            player.GameLog.Add(game);
        }
コード例 #2
0
        /// <summary />
        public static int GetFanastyPoints(this Game game)
        {
            int points = 0;

            Passing p = game.Passing;

            if (p != null)
            {
                points += p.YDS;
                points += 50 * CountBonuses(p.YDS, 300, 100);
                points -= p.INT * 50;

                // estimate 10 yards per passing TD on average
                points += p.TD * 10;
            }

            Rushing r = game.Rushing;

            if (r != null)
            {
                points += r.YDS;
                points += 50 * CountBonuses(r.YDS, 100, 50);

                // estimate 3 yards per rushing TD on average
                points += r.TD * 3;
            }

            Receiving c = game.Receiving;

            if (c != null)
            {
                points += c.YDS;
                points += 50 * CountBonuses(c.YDS, 100, 50);

                // estimate 10 yards per receiving TD on average
                points += c.TD * 10;
            }

            Fumbles f = game.Fumbles;

            if (f != null)
            {
                points -= f.FUM * 25;
            }

            Kicking k = game.Kicking;

            if (k != null)
            {
                // calculate the points for all field goals awarding
                // points per yard of a field goal and subtracting the
                // points of a missed fieldgoal.

                // In 2016, the average kick was from 37.7 yards away; the average
                // successful kick was from 36.2 yards out - while the average miss was from 46.2 yards away.

                points += k.FGM * 38;
                points -= (k.FGA - k.FGM) * 46;

                // calculate 20 points for each extra point made and
                // subtract 20 points for each point missed
                points += k.XPM * 33;
                points -= (k.XPA - k.XPM) * 33;
            }

            Defense defense = game.Defense;

            if (defense != null)
            {
                //calculate points for interceptions
                points += defense.INT * 50;
                points += defense.YDS_INT;
                if (defense.TD_INT > 0)
                {
                    // if we have a touchdown, one point per yard avaraged
                    points += (defense.YDS_INT / defense.TD_INT) * defense.TD_INT;
                }

                // calculate points for fumble recoveries
                points += defense.FUM * 25;
                if (defense.TD_FUM > 0)
                {
                    // if we have a touchdown, one point per yard averaged
                    points += (defense.YDS_FUM / defense.TD_FUM) * defense.TD_FUM;
                }

                // calculate points for sacks
                points += defense.SACK * 10;
            }

            return(points);
        }