Пример #1
0
        /// <summary />
        public static IEnumerable<QB> ConvertAndInitialize(FanastySeason season)
        {
            Collection<QB> results = new Collection<QB>();

            foreach (NFLPlayer player in season.GetAll(FanastyPosition.QB))
            {
                QB qb = new QB(player);

                int points = player.FanastyPoints();
                int games = player.GamesPlayed();

                if (games > 0)
                {
                    qb.PointsOverReplacement = (points / games) - season.ReplacementValue.QB;
                    qb.PointsOverReplacement3G = (player.FanastyPointsInRecentGames(3) / 3) - season.ReplacementValue.QB;
                }

                qb.FanastyPoints = points;
                qb.TotalBonuses = player.TotalBonuses();

                results.Add(qb);
            }

            return results;
        }
Пример #2
0
        /// <summary />
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            bool success = WaFFLPersister.TryLoadSeason(out this.season);

            if (!success)
            {
                // if we were unable to load the season from disk, we will
                // scrape the data from the web agian.
                Thread thread = new Thread(this.refreshDelegate);
                thread.Start();
            }
            else
            {
                this.CurrentSeason = this.season;
            }


            List <string> markedPlayers = null;

            success = MarkedPlayerPersister.TryLoadPlayers(out markedPlayers);
            if (!success)
            {
                markedPlayers = new List <string>();
            }
            MarkedPlayers.Players = markedPlayers;
        }
Пример #3
0
        /// <summary />
        public static IEnumerable<K> ConvertAndInitialize(FanastySeason season)
        {
            Collection<K> results = new Collection<K>();

            foreach (NFLPlayer player in season.GetAll(FanastyPosition.K))
            {
                K k = new K(player);

                int points = player.FanastyPoints();
                int games = player.GamesPlayed();

                if (games > 0)
                {
                    k.PointsOverReplacement = (points / games) - season.ReplacementValue.K;
                    k.PointsOverReplacement3G = (player.FanastyPointsInRecentGames(3) / 3) - season.ReplacementValue.K;
                }

                k.FanastyPoints = points;
                k.TotalBonuses = player.TotalBonuses();

                results.Add(k);
            }

            return results;
        }
Пример #4
0
        /// <summary />
        private void SetIsRefreshingData(bool value)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                // re-execute this method on the ui thread.
                this.Dispatcher.BeginInvoke(new Action <bool>(this.SetIsRefreshingData), value);
            }
            else if (value)
            {
                this.refreshTimeStamp = DateTime.Now;
                this.IsRefreshingData = true;
            }
            else
            {
                this.CurrentSeason = this.season;

                // if the loading indicator has been displayed for more than the minimum amount
                // of time, we will stop refreshing our data.
                TimeSpan duration = DateTime.Now - this.refreshTimeStamp;
                if (duration < MinimumRefreshDuration)
                {
                    TimeSpan remaining = MinimumRefreshDuration.Subtract(duration);
                    new DispatcherTimer(remaining, DispatcherPriority.Normal, delegate { this.IsRefreshingData = false; }, this.Dispatcher).Start();
                }
                else
                {
                    this.IsRefreshingData = false;
                }
            }
        }
Пример #5
0
        /// <summary />
        public void ParseSeason(int year, ref FanastySeason season)
        {
            if (this.context != null)
            {
                throw new InvalidOperationException("parsing action in progress");
            }

            if (season == null)
            {
                season      = new FanastySeason();
                season.Year = year;
            }

            this.context = season;

            try
            {
                this.context.ClearAllPlayerGameLogs();
                string uri = string.Format(SeasonScheduleUri, year);
                ParseGames(uri);
            }
            finally
            {
                this.context.LastUpdated = DateTime.Now;
                season = this.context;

                this.context = null;
            }
        }
Пример #6
0
        /// <summary />
        public static IEnumerable<WR> ConvertAndInitialize(FanastySeason season)
        {
            Collection<WR> results = new Collection<WR>();

            foreach (NFLPlayer player in season.GetAll(FanastyPosition.WR))
            {
                WR wr = new WR(player);

                int points = player.FanastyPoints();
                int games = player.GamesPlayed();

                if (games > 0)
                {
                    wr.PointsOverReplacement = (points / games) - season.ReplacementValue.WR;
                    wr.PointsOverReplacement3G = (player.FanastyPointsInRecentGames(3) / 3) - season.ReplacementValue.WR;
                }

                wr.FanastyPoints = points;
                wr.TotalBonuses = player.TotalBonuses();

                results.Add(wr);
            }

            return results;
        }
Пример #7
0
        public void UpdatePlayerInjuryStatus(int year, ref FanastySeason season, Func <NFLPlayer, bool> update)
        {
            string uri = string.Format(SeasonScheduleUri, year);

            foreach (var player in season.GetAllPlayers())
            {
                if (update(player))
                {
                    UpdatePlayerMetadata(player, player.PlayerPageUri, uri);
                }
            }
        }
Пример #8
0
        /// <summary />
        public static bool TryLoadSeason(out FanastySeason data)
        {
            string root       = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string folderpath = Path.Combine(root, DataFolder);

            if (Directory.Exists(folderpath))
            {
                string filepathToDelete = Path.Combine(folderpath, OldDataFile);
                try
                {
                    File.Delete(filepathToDelete);
                }
                catch (IOException)
                {
                    // eat any delete exception -- if we can't delete it, then that's fine; we will move on
                }

                string filepath = Path.Combine(folderpath, DataFile);
                try
                {
                    using (FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                    {
                        IFormatter formatter = new BinaryFormatter();
                        try
                        {
                            data = (FanastySeason)formatter.Deserialize(stream);
                            return(true);
                        }
                        catch (SerializationException)
                        {
                            // we failed to deserialize the data.  We will assume it is
                            // corrupt and delete the storage file and rebuild it.
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (IOException)
                            {
                                // we failed to delete the file, nothing else to do.
                            }
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    // nothign was found, we will return false
                }
            }

            data = null;
            return(false);
        }
Пример #9
0
        /// <summary />
        private void RefreshCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            bool forceFullRefresh = System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftShift);

            if (forceFullRefresh)
            {
                // if shift is pressed, we will wipe out our data.
                this.season = null;
            }

            Thread thread = new Thread(this.refreshDelegate);

            thread.Start();
        }
Пример #10
0
        /// <summary />
        public static void SaveSeason(FanastySeason data)
        {
            string root = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string folderpath = Path.Combine(root, DataFolder);

            if (!Directory.Exists(folderpath))
            {
                Directory.CreateDirectory(folderpath);
            }

            string filepath = Path.Combine(folderpath, DataFile);

            using (FileStream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write))
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, data);
            }
        }
Пример #11
0
        /// <summary />
        public static void SaveSeason(FanastySeason data)
        {
            string root       = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string folderpath = Path.Combine(root, DataFolder);

            if (!Directory.Exists(folderpath))
            {
                Directory.CreateDirectory(folderpath);
            }

            string filepath = Path.Combine(folderpath, DataFile);

            using (FileStream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write))
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, data);
            }
        }
Пример #12
0
        /// <summary />
        public static bool TryLoadSeason(out FanastySeason data)
        {
            string root = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string folderpath = Path.Combine(root, DataFolder);

            if (Directory.Exists(folderpath))
            {
                string filepath = Path.Combine(folderpath, DataFile);
                try
                {
                    using (FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                    {
                        IFormatter formatter = new BinaryFormatter();
                        try
                        {
                            data = (FanastySeason)formatter.Deserialize(stream);
                            return true;
                        }
                        catch (SerializationException)
                        {
                            // we failed to deserialize the data.  We will assume it is
                            // corrupt and delete the storage file and rebuild it.
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (IOException)
                            {
                                // we failed to delete the file, nothing else to do.
                            }
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    // nothign was found, we will return false
                }
            }

            data = null;
            return false;
        }
Пример #13
0
        public void Calculate(FanastySeason season)
        {
            NFLPlayer[] players = season.GetAllPlayers().ToArray();

            int count  = players.Length;
            int middle = count / 2;

            Reference <NFLPlayer>[] tally = new Reference <NFLPlayer> [count];

            for (int i = 0; i < count; i++)
            {
                int p = players[i].FanastyPoints();
                int g = players[i].GamesPlayed();

                tally[i] = new Reference <NFLPlayer>();
                if (g > 0)
                {
                    tally[i].Average = p / g;
                }

                tally[i].Context = players[i];
            }

            var qb = from p in tally
                     where p.Context.Position == FanastyPosition.QB
                     orderby p.Average descending
                     select p;

            var rb = from p in tally
                     where p.Context.Position == FanastyPosition.RB
                     orderby p.Average descending
                     select p;

            var wr = from p in tally
                     where p.Context.Position == FanastyPosition.WR
                     orderby p.Average descending
                     select p;

            var k = from p in tally
                    where p.Context.Position == FanastyPosition.K
                    orderby p.Average descending
                    select p;

            var dst = from p in tally
                      where p.Context.Position == FanastyPosition.DST
                      orderby p.Average descending
                      select p;

            PositionBaseline baseline = season.ReplacementValue = new PositionBaseline();

            // to calculate the replacement point value, we stack rank the players, then
            // pick the player at the postion that a replacment could be easily gotten off of wavers.

            // example:  16 QB roster spots + 16 Flex positions / 3 positions that will likely filled a flex position (QB, K, or DST)
            // example:  3 RB roster spots * 16 teams, assume very few (1) flex positions will contain a RB.

            baseline.QB  = CalculateReplacementValue(qb, 21);
            baseline.RB  = CalculateReplacementValue(rb, 48);
            baseline.WR  = CalculateReplacementValue(wr, 48);
            baseline.K   = CalculateReplacementValue(k, 21);
            baseline.DST = CalculateReplacementValue(dst, 21);
        }
Пример #14
0
 public ScoringPlayParser(FanastySeason season, int week)
 {
     _season = season;
     _week   = week;
 }