Beispiel #1
0
        public DataSet LoadData(
            ArrayList plyrList,
            IRatePlayers scorer)
        {
            var ds   = new DataSet();
            var dt   = new DataTable();
            var cols = dt.Columns;

            cols.Add("Name", typeof(String));
            cols.Add("Pos", typeof(String));
            cols.Add("Role", typeof(String));
            cols.Add("RookieYr", typeof(String));
            cols.Add("Age", typeof(String));
            cols.Add("Currteam", typeof(String));
            cols.Add("FT", typeof(String));

            if (LongStats)
            {
                cols.Add("CurScores", typeof(Int32));
                cols.Add("Scores", typeof(Int32));
                cols.Add("Avg", typeof(Decimal));
                cols.Add("Injury", typeof(Int32));
                cols.Add("Tdp", typeof(Int32));
                cols.Add("YDp", typeof(Int32));
                cols.Add("Tdr", typeof(Int32));
                cols.Add("TDc", typeof(Int32));
                cols.Add("YDr", typeof(Int32));
                cols.Add("YDc", typeof(Int32));
                cols.Add("Fg", typeof(Int32));
            }

            cols.Add("Points", typeof(Decimal));
            cols.Add("AgeRate", typeof(Decimal));
            cols.Add("ADP", typeof(Int32));

            if (Season == null)
            {
                Season = Utility.CurrentSeason();
            }

            foreach (NFLPlayer p in plyrList)
            {
                if (p.TotStats == null)
                {
                    p.LoadPerformances(
                        allGames: false,
                        currSeasonOnly: true,
                        whichSeason: Season);                         //  to get the stats
                }
                //  rate the last whatevr weeks
                var theWeek = WeekMaster != null?
                              WeekMaster.GetWeek(Season, Week)
                                  : new NFLWeek(
                                      Int32.Parse(Season),
                                      Week,
                                      loadGames: true);

                var totPoints = 0M;
                for (var w = WeeksToGoBack; w > 0; w--)
                {
                    if (scorer != null)
                    {
                        scorer.RatePlayer(
                            p,
                            theWeek);
                    }
                    totPoints += p.Points;
                    theWeek    = WeekMaster != null
                                                ? WeekMaster.PreviousWeek(theWeek)
                                           : theWeek.PreviousWeek(
                        theWeek: theWeek,
                        loadgames: false,
                        regularSeasonGamesOnly: false);
                }

                if (totPoints <= 0 && SupressZeros)
                {
                    continue;
                }

                DataRow dr = PopulatePlayerRow(dt, p, totPoints);
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);

            return(ds);
        }
        public DataSet LoadData(ArrayList plyrList, NFLWeek startWeek)
        {
            var ds   = new DataSet();
            var dt   = new DataTable();
            var cols = dt.Columns;

            cols.Add("Name", typeof(String));
            cols.Add("Currteam", typeof(String));
            cols.Add("ROLE", typeof(String));
            cols.Add("FT", typeof(String));
            cols.Add("tot", typeof(Int32));

            var currentWeek = new NFLWeek(
                Int32.Parse(TimeKeeper.Season),
                Int32.Parse(TimeKeeper.Week),
                loadGames: false);

            for (var w = Constants.K_WEEKS_IN_A_SEASON; w > 0; w--)
            {
                var fieldName = string.Format(
                    FieldFormat,
                    currentWeek.WeekNo);
                //Utility.Announce(
                //    string.Format( "Adding field: {0}", fieldName ) );
                cols.Add(
                    fieldName,
                    typeof(String));
                currentWeek = currentWeek.PreviousWeek(
                    currentWeek, loadgames: false,
                    regularSeasonGamesOnly: false);
            }
            foreach (NFLPlayer p in plyrList)
            {
                decimal nTot = 0;
                var     dr   = dt.NewRow();
                dr["Name"]     = p.ProjectionLink(TimeKeeper.Season);
                dr["CurrTeam"] = p.TeamCode;
                dr["ROLE"]     = p.PlayerRole;
                dr["FT"]       = p.Owner;

                var weekCounter = Constants.K_WEEKS_IN_A_SEASON;
                var weeksDone   = 0;
                var scoreWeek   = WeekMaster != null
                    ? WeekMaster.GetWeek(startWeek.Season, 17)
                    : new NFLWeek(
                    startWeek.Season,
                    Constants.K_WEEKS_IN_REGULAR_SEASON);

                do
                {
                    var game   = scoreWeek.GameFor(p.TeamCode);
                    var cOp    = game == null ? string.Empty : game.OpponentOut(p.TeamCode);
                    var nScore = 0M;
                    if (game != null)
                    {
                        if (game.Played())
                        {
                            nScore = _scorer.RatePlayer(p, scoreWeek);
                            nTot  += nScore;
                            weeksDone++;
                        }
                    }
                    if (game != null && game.Played())
                    {
                        dr[string.Format(FieldFormat, scoreWeek.WeekNo)]
                            = string.Format("{0:0}:{1}", nScore, cOp) + "<br>"
                              + OpponentDefence(p, game);
                    }
                    else
                    {
                        dr[string.Format(FieldFormat, scoreWeek.WeekNo)]
                            = string.Format("{0:#}:{1}", nScore, cOp) + "<br>"
                              + OpponentDefence(p, game);
                    }

                    scoreWeek = WeekMaster != null?WeekMaster.PreviousWeek(scoreWeek) : scoreWeek.PreviousWeek(scoreWeek, false, false);

                    if (CurrentSeasonOnly)
                    {
                        if (scoreWeek.Season != Utility.CurrentSeason())
                        {
                            weekCounter = 0; //  breaks you out of the loop
                        }
                    }
                    if (weeksDone >= WeeksToGoBack)
                    {
                        break;
                    }

                    weekCounter--;
                } while (weekCounter > 0);

                dr["tot"] = nTot;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            return(ds);
        }
Beispiel #3
0
        public DataSet LoadData(ArrayList plyrList, IRatePlayers scorer)
        {
            var ds   = new DataSet();
            var dt   = new DataTable();
            var cols = dt.Columns;

            cols.Add("Name", typeof(String));
            cols.Add("Pos", typeof(String));
            cols.Add("Role", typeof(String));
            cols.Add("RookieYr", typeof(String));
            cols.Add("Age", typeof(String));
            cols.Add("Currteam", typeof(String));
            cols.Add("FT", typeof(String));

            if (LongStats)
            {
                cols.Add("CurScores", typeof(Int32));
                cols.Add("Scores", typeof(Int32));
                cols.Add("Avg", typeof(Decimal));
                cols.Add("Injury", typeof(Int32));
                cols.Add("Tdp", typeof(Int32));
                cols.Add("YDp", typeof(Int32));
                cols.Add("Tdr", typeof(Int32));
                cols.Add("TDc", typeof(Int32));
                cols.Add("YDr", typeof(Int32));
                cols.Add("YDc", typeof(Int32));
                cols.Add("Fg", typeof(Int32));
            }

            cols.Add("Points", typeof(Decimal));
            cols.Add("PFP", typeof(Decimal));
            cols.Add("ADP", typeof(Int32));

            if (Season == null)
            {
                Season = Utility.CurrentSeason();
            }

            foreach (NFLPlayer p in plyrList)
            {
                if (p.TotStats == null)
                {
                    p.LoadPerformances(false, true, Season);                                         //  to get the stats
                }
                //  rate the last whatevr weeks
                var theWeek = WeekMaster != null?
                              WeekMaster.GetWeek(Season, Week) : new NFLWeek(Int32.Parse(Season), Week, loadGames: true);

                var totPoints = 0M;
                for (var w = WeeksToGoBack; w > 0; w--)
                {
                    if (scorer != null)
                    {
                        scorer.RatePlayer(p, theWeek);
                    }
                    totPoints += p.Points;
                    theWeek    = WeekMaster != null?WeekMaster.PreviousWeek(theWeek)
                                     : theWeek.PreviousWeek(theWeek, false, false);
                }

                if (totPoints <= 0 && SupressZeros)
                {
                    continue;
                }

                var dr = dt.NewRow();
                if (RenderToCsv)
                {
                    dr["Name"] = p.PlayerName;
                }
                else
                {
                    dr["Name"] = p.ProjectionLink(Season);
                }

                dr["Pos"]      = p.PlayerPos;
                dr["Role"]     = p.RoleOut();
                dr["RookieYr"] = p.RookieYear + "-" + p.Drafted;
                dr["CurrTeam"] = p.TeamCode;
                dr["FT"]       = p.Owner;
                dr["Age"]      = p.PlayerAge();

                if (LongStats)
                {
                    dr["CurSCORES"] = p.CurrScores;
                    dr["SCORES"]    = p.Scores;
                    dr["Avg"]       = p.ScoresPerYear();
                    dr["INJURY"]    = p.Injuries();
                    dr["Tdp"]       = p.TotStats.Tdp;
                    dr["YDp"]       = p.TotStats.YDp;
                    dr["Tdr"]       = p.TotStats.Tdr;
                    dr["TDc"]       = p.TotStats.Tdc;
                    dr["YDr"]       = p.TotStats.YDr;
                    dr["YDc"]       = p.TotStats.YDc;
                    dr["Fg"]        = p.TotStats.Fg;
                }

                dr["Points"] = totPoints;
                dr["PFP"]    = p.Rating;
                dr["ADP"]    = p.Adp;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);

            return(ds);
        }