示例#1
0
        public void ReadJsonDeserialize(string fileName, IPlayer _players, DateTime date)
        {
            SaveStats playerStats = new SaveStats();
            int       i           = 0;

            try
            {
                Rootobject rootObject = JsonConvert.DeserializeObject <Rootobject>(File.ReadAllText(fileName));
                foreach (var p in rootObject.dailyplayerstats.playerstatsentry)
                {
                    System.Diagnostics.Debug.WriteLine("#: " + i++ + "Id: " + p.player.ID + " " + p.player.LastName);
                    if (p.player.Position == "P")
                    {
                        PitcherStats stats = playerStats.BuildPitcherStatModel(Convert.ToInt32(p.player.ID), p.stats, date);
                        _players.AddPitcherStats(stats);
                    }
                    else
                    {
                        HitterStats stats = playerStats.BuildHitterMStatModel(Convert.ToInt32(p.player.ID), p.stats, date);
                        _players.AddHitterStats(stats);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error reading Json file: " + ex);
            }
            System.Diagnostics.Debug.WriteLine(i + " Daily Stats Records Read. ");
        }
示例#2
0
 public void BuildPitcherStatModel(int id, Stats stats, IPlayer _context, DateTime date)
 {
     try
     {
         PitcherStats playerStats = new PitcherStats
         {
             PlayerId          = id,
             EarnedRunsAllowed = Convert.ToInt32(stats.EarnedRunsAllowed.text),
             HitsAllowed       = Convert.ToInt32(stats.HitsAllowed.text),
             CompleteGames     = Convert.ToInt32(stats.CompletedGames.text),
             Holds             = Convert.ToInt32(stats.Holds.text),
             InningsPitched    = (float)Convert.ToDouble(stats.InningsPitched.text),
             Loses             = Convert.ToInt32(stats.Losses.text),
             Saves             = Convert.ToInt32(stats.Saves.text),
             PitcherWalks      = Convert.ToInt32(stats.PitcherWalks.text),
             Wins          = Convert.ToInt32(stats.Wins.text),
             Strikeouts    = Convert.ToInt32(stats.PitcherStrikeouts.text),
             GamesFinished = Convert.ToInt32(stats.GamesFinished.text),
             WHIP          = (float)Convert.ToDouble(stats.WalksAndHitsPerInningPitched.text),
             ERA           = (float)Convert.ToDouble(stats.EarnedRunAvg.text),
             IsCumulative  = true,
             Date          = DateTime.Today
         };
         _context.AddPitcherStats(playerStats);
     }
     catch (Exception ex)
     {
         string errorMessage = string.Format("Error saving player stats: " + ex);
         System.Diagnostics.Debug.WriteLine(errorMessage);
         log.Info(errorMessage);
     }
 }
示例#3
0
 public void AddPitcherStats(PitcherStats stats)
 {
     try
     {
         _context.PitcherStats.Add(stats);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Error Adding Hitter Stat:" + ex);
     }
 }
示例#4
0
        public PitcherStats BuildPitcherStatModel(int id, Stats stats, DateTime date)
        {
            PitcherStats playerStats = new PitcherStats
            {
                PlayerId          = id,
                EarnedRunsAllowed = Convert.ToInt32(stats.EarnedRunsAllowed.text),
                HitsAllowed       = Convert.ToInt32(stats.HitsAllowed.text),
                CompleteGames     = Convert.ToInt32(stats.CompletedGames.text),
                Holds             = Convert.ToInt32(stats.Holds.text),
                InningsPitched    = (float)Convert.ToDouble(stats.InningsPitched.text),
                Loses             = Convert.ToInt32(stats.Losses.text),
                Saves             = Convert.ToInt32(stats.Saves.text),
                PitcherWalks      = Convert.ToInt32(stats.PitcherWalks.text),
                Wins          = Convert.ToInt32(stats.Wins.text),
                Strikeouts    = Convert.ToInt32(stats.PitcherStrikeouts.text),
                GamesFinished = Convert.ToInt32(stats.GamesFinished.text),
                IsCumulative  = false,
                WHIP          = (float)Convert.ToDouble(stats.WalksAndHitsPerInningPitched.text),
                Date          = DateTime.Parse(date.ToShortDateString())
            };

            return(playerStats);
        }