Пример #1
0
 public YahooScorer(NFLWeek week)
 {
     Name             = "Yahoo Scorer";
     Week             = week;
     PgmDao           = new DbfPlayerGameMetricsDao();    //   should be injected
     YahooStatService = new YahooStatService();
     Logger           = LogManager.GetCurrentClassLogger();
     UseProjections   = true;
 }
Пример #2
0
        public Decimal RatePlayer(
            NFLPlayer plyr,
            NFLWeek week,
            bool takeCache = true)
        {
            // Points for Scores and points for stats
            if (week.WeekNo.Equals(0))
            {
                return(0);
            }

            //TODO:  factor in known suspensions
            //if (IsSuspended(plyr, week))
            //	return 0;

            if (takeCache)
            {
                //  Check the stats service first
                if (YahooStatService.IsStat(
                        plyr.PlayerCode,
                        week.Season,
                        week.Week))
                {
                    return(YahooStatService.GetStat(
                               plyr.PlayerCode,
                               week.Season,
                               week.Week));
                }
            }

            if (plyr.TeamCode == null)
            {
                Logger.Error("{0} has a null teamcode", plyr);
                return(0);
            }
            GameKey = Week.GameCodeFor(plyr.TeamCode);                //  slow?
            if (string.IsNullOrEmpty(GameKey))
            {
                return(0);
            }

            Game          = new NFLGame(GameKey);
            WeekHasPassed = Game.Played(addDay: false);
            if (!WeekHasPassed)
            {
                return(plyr.Points);
            }

            Week        = week;       //  set the global week, other wise u will get the same week all the time
            plyr.Points = 0;          //  start from scratch

            #region Passing

            //  4 pts for a Tdp
            var tdpPts = PointsFor(plyr, 4, Constants.K_SCORE_TD_PASS, id: "2");
            plyr.Points += tdpPts;

            Announce($"{plyr.PlayerName} has {tdpPts} points for Tdp");

            //  2 pts for a PAT pass
            var ptsForPATpasses = PointsFor(plyr, 2, Constants.K_SCORE_PAT_PASS, id: "2");
            plyr.Points += ptsForPATpasses;

            Announce($"{plyr.PlayerName} has {ptsForPATpasses} points for PAT passes");

            //  1 pt / 25 YDp
            var ptsForYDp = PointsForStats(plyr: plyr, increment: 1, forStatType: Constants.K_STATCODE_PASSING_YARDS, divisor: 25.0M);
            plyr.Points += ptsForYDp;

            Announce($"{plyr.PlayerName} has {ptsForYDp} points for {plyr.ProjectedYDp} YDp");

            //  -2 pts for an Interception
            var ptsForInts = PointsForStats(
                plyr: plyr, increment: -1, forStatType: Constants.K_STATCODE_INTERCEPTIONS_THROWN, divisor: 1.0M);
            plyr.Points += ptsForInts;

            Announce($"{plyr.PlayerName} has {ptsForInts} points for Interceptions");

            #endregion Passing

            #region Catching

            //  6 pts for a TD catch
            var ptsForTDcatches = PointsFor(
                plyr: plyr,
                increment: 6,
                forScoreType: Constants.K_SCORE_TD_PASS,
                id: "1");
            plyr.Points += ptsForTDcatches;
            //  2 points for a 2 point conversion
            var ptsForPATcatches = PointsFor(
                plyr: plyr,
                increment: 2,
                forScoreType: Constants.K_SCORE_PAT_PASS,
                id: "1");
            plyr.Points += ptsForPATcatches;

            Announce($@"{
				plyr.PlayerName
				} has {
				ptsForPATcatches
				} points for PAT catches"                );

            //  1 pt / 10 yds
            var ptsForYDs = PointsForStats(
                plyr: plyr,
                increment: 1,
                forStatType: Constants.K_STATCODE_RECEPTION_YARDS,
                divisor: 10.0M);

            plyr.Points += ptsForYDs;

            Announce($"{plyr.PlayerName} has {ptsForYDs} points for YDc");

            //  1/2 pt / 10 yds
            var ptsForRecs = PointsForStats(
                plyr: plyr,
                increment: 1,
                forStatType: Constants.K_STATCODE_PASSES_CAUGHT,
                divisor: 2.0M);

            plyr.Points += ptsForRecs;

            Announce($"{plyr.PlayerName} has {ptsForRecs} points for REC");

            #endregion Catching

            #region Running

            //  6 points for TD run
            var ptsForTDruns = PointsFor(plyr, 6, Constants.K_SCORE_TD_RUN, id: "1");
            plyr.Points += ptsForTDruns;

            Announce($"{plyr.PlayerName} has {ptsForTDruns} points for TD runs");

            var ptsForPaTruns = PointsFor(plyr, 2, Constants.K_SCORE_PAT_RUN, id: "1");
            plyr.Points += ptsForPaTruns;

            Announce($"{plyr.PlayerName} has {ptsForPaTruns} points for PAT runs");

            //  1 pt / 10 yds
            var ptsForYDr = PointsForStats(
                plyr: plyr, increment: 1, forStatType: Constants.K_STATCODE_RUSHING_YARDS, divisor: 10.0M);
            plyr.Points += ptsForYDr;

            Announce($"{plyr.PlayerName} has {ptsForYDr} points for YDr");

            #endregion Running

            #region Kicking

            plyr.Points += PointsFor(plyr, 3, Constants.K_SCORE_FIELD_GOAL, "1");

            plyr.Points += PointsFor(plyr, 1, Constants.K_SCORE_PAT, "1");

            #endregion Kicking

            Announce($@"{
				plyr.PlayerName
				} has {
				plyr.Points
				} in week {
				week.Season
				}:{
				week.Week
				}"                );
            return(plyr.Points);
        }