예제 #1
0
 private static void WriteStatNode(XmlWriter writer, HillenPowerRating stat)
 {
     writer.WriteStartElement("stat");
     writer.WriteAttributeString("season", stat.Season);
     writer.WriteAttributeString("week", stat.Week);
     writer.WriteAttributeString("team", stat.TeamCode);
     writer.WriteAttributeString("qty", stat.Quantity.ToString());
     writer.WriteEndElement();
 }
예제 #2
0
        public void Calculate(string season, string week)
        {
            if (week.Equals("01"))
            {
                SetupSeason(season);
                Dump2Xml();
                return;
            }

            var hp = new HillinPredictor();

            var theSeason = new NflSeason(season);

            foreach (var team in theSeason.TeamList)
            {
                //  get teams game for the week
                Utility.Announce(string.Format("  Doing {0}", team.TeamCode));
                var upcomingWeek   = new NFLWeek(season, week);
                var previousWeek   = upcomingWeek.PreviousWeek(upcomingWeek, loadgames: false, regularSeasonGamesOnly: true);
                var prevWeek       = string.Format("{0:0#}", previousWeek.WeekNo);
                var oldPowerRating = team.GetPowerRating(prevWeek);

                if (oldPowerRating == 0)
                {
                    return;
                }
                var newRating = new HillenPowerRating
                {
                    Season   = season,
                    TeamCode = team.TeamCode,
                    Week     = week,
                    Quantity = oldPowerRating
                };

                var game = Utility.GetGameFor(season, prevWeek, team.TeamCode);

                if (game.GameDate != new DateTime(1, 1, 1))
                {
                    var predictedResult        = hp.PredictGame(game, null, game.GameDate);
                    var predictedMarginForTeam = predictedResult.MarginForTeam(team.TeamCode);
                    //Utility.Announce( string.Format( "Predicted Margin for {0} is {1}", TeamCode, predictedMarginForTeam ) );
                    var actualMarginForTeam = game.Result.MarginForTeam(team.TeamCode);
                    //Utility.Announce( string.Format( "   Result of {2} means Actual Margin for {0} is {1}",
                    var newPowerRating = AdjustedPower(oldPowerRating, predictedMarginForTeam, actualMarginForTeam);
                    newRating.Quantity = newPowerRating;
                }
                PutRating(newRating);
            }
            Dump2Xml();
        }
예제 #3
0
        public void PutRating(HillenPowerRating stat)
        {
            if (stat.Quantity == 0.0M)
            {
                return;
            }

            IsDirty = true;
            if (TheHt.ContainsKey(stat.FormatKey()))
            {
                TheHt[stat.FormatKey()] = stat;
#if DEBUG
                //Utility.Announce( string.Format( "HillenMaster:Putting Stat {0}", stat.FormatKey() ) );
#endif
                return;
            }
            TheHt.Add(stat.FormatKey(), stat);
#if DEBUG
            //Utility.Announce( string.Format( "HillenMaster:Adding Stat {0}", stat.FormatKey() ) );
#endif
        }
예제 #4
0
        public override decimal GetStat(string theKey)
        {
            var season   = theKey.Substring(0, 4);
            var week     = theKey.Substring(5, 2);
            var teamCode = theKey.Substring(8, 2);

            var stat = new HillenPowerRating
            {
                Season   = season,
                Week     = week,
                TeamCode = teamCode,
                Quantity = 0.0M
            };

#if DEBUG
            Utility.Announce(string.Format("HillenMaster:Getting Stat {0}", stat.FormatKey()));
#endif

            var key = stat.FormatKey();
            if (TheHt.ContainsKey(key))
            {
                stat = (HillenPowerRating)TheHt[key];
                CacheHits++;
            }
            else
            {
                //  new it up
#if DEBUG
                Utility.Announce(string.Format("HillenMaster:Instantiating Stat {0}", stat.FormatKey()));
#endif
                PutRating(stat);
                IsDirty = true;
                CacheMisses++;
            }
            return(stat.Quantity);
        }