Пример #1
0
        public override void Parse( XDocument doc, Season season, DateTime date, string url )
        {
            _sequence = 0;
            _inning = 1;
            _half = _top;
            ResetInning();

            var innings = doc.Root.Elements( "inning" );

            foreach(var inning in innings)
            {
                _inning = Convert.ToInt16(inning.Attribute( "num" ).Value);

                var topOfInning = inning.Element( "top" );
                _half = _top;
                foreach( var e in topOfInning.Elements())
                {
                    ParseInningEvents(e);
                }

                var bottomOfInning = inning.Element( "bottom" );
                _half = _bottom;
                foreach( var e in bottomOfInning.Elements())
                {
                    ParseInningEvents(e);
                }

                _inning++;
                ResetInning();
            }
        }
        public override void Parse(XDocument doc, Season season, DateTime date, string url)
        {
            try
            {
                foreach (var team in doc.Root.Elements("team"))
                {
                    Dictionary<int, bool> checkPlayers = new Dictionary<int,bool>();

                    string teamAbbr = Convert.ToString( team.Attribute( "id" ).Value ).ToLower();
                    string teamAlias = ConvertTeamAbbr( teamAbbr );

                    foreach (var player in team.Elements("player"))
                    {
                        int playerid = Convert.ToInt32( player.Attribute( "id" ).Value );
                        string firstName = Convert.ToString( player.Attribute( "first" ).Value );
                        string lastName = Convert.ToString( player.Attribute( "last" ).Value );

                        checkPlayers[playerid] = true;

                        Console.WriteLine( "\t  " + firstName + " " + lastName );

                        if (PlayerExists( playerid, firstName, lastName, season.begin.Year ))
                            _dbcontext.UpdatePlayersTeam( playerid, season.begin.Year, teamAlias, date.ToShortDateString() );
                        else
                            CreatePlayer( url, playerid, season.begin.Year, date );
                    }

                    CheckDatabasePlayers( teamAlias, checkPlayers, season.begin.Year, date );
                }
            }
            catch (Exception e)
            {
                _logger.WriteError( e, "Parsing CheckPlayersTeam : " + url );
            }
        }
Пример #3
0
        public void Test7182014()
        {
            ErrorLog log = new ErrorLog( @".\Test_7-18-14.txt" );
            Season season = new Season( new DateTime( 2014, 7, 18 ), new DateTime( 2014, 7, 18 ), new PostSeason( DateTime.Now, DateTime.Now) );
            DBContextFactory factory = DBContextFactory.Instance;

            BoxscoreDownloader downloader = new BoxscoreDownloader( new BoxscoreParser( log, factory.CreateBoxscoreSqlServerDBContext(log) ), season, log );
            downloader.Download();
        }
Пример #4
0
        public override void Parse(XDocument doc, Season season, DateTime date, string url)
        {
            string gameid = "";
            try
            {
                string awayTeam = Convert.ToString( doc.Root.Element( "inning" ).Attribute( "away_team" ).Value );
                string homeTeam = Convert.ToString( doc.Root.Element( "inning" ).Attribute( "home_team" ).Value );

                string[] urlSplit = url.Split( '/' );
                gameid = urlSplit[9];

                gameid = gameid.Substring( 4 );
                string[] parts = gameid.Split( '_' );
                string gameid_1 = parts[0] + "/" + parts[1] + "/" + parts[2] + "/";
                string gameid_2 = parts[3] + "-" + parts[4] + "-" + parts[5];

                gameid = gameid_1 + gameid_2;

                this.SetPlayersDictionary( gameid );

                _sequence = 0;
                _atBatNum = 0;
                _inning = 1;
                _outs = 0;
                _prevOuts = 0;
                _half = "top";

                var innings = doc.Root.Elements( "inning" );

                foreach (var inning in innings)
                {
                    _inning = Convert.ToInt16( inning.Attribute( "num" ).Value );
                    foreach (var atBatAction in inning.Elements( "top" ).Elements())
                    {
                        _half = "top";
                        this.ParseAtBatAction( atBatAction, gameid );
                    }

                    _prevOuts = 0;
                    _outs = 0;

                    foreach (var atBatAction in inning.Element( "bottom" ).Elements())
                    {
                        _half = "bottom";
                        this.ParseAtBatAction( atBatAction, gameid );
                    }

                    _prevOuts = 0;
                    _outs = 0;
                }
            }
            catch (Exception e) { _logger.WriteError( e, "Parsing Play : " + gameid ); }
        }
Пример #5
0
        public override void Parse( XDocument doc, Season season, DateTime date, string url )
        {
            var teams = doc.Root.Elements( "team" );
            foreach (var team in teams)
            {
                var players = team.Elements( "player" );
                string teamAbbr = team.Attribute( "id" ).Value;

                foreach (var player in players)
                {
                    int playerid = Convert.ToInt32( player.Attribute( "id" ).Value );

                    string playerPos = "B";
                    try { playerPos = player.Attribute( "game_positition" ).Value; }
                    catch { }

                    int batOrder = -1;
                    try { batOrder = Convert.ToInt32( player.Attribute( "bat_order" ).Value ); }
                    catch { }

                    _dbcontext.InsertLineup( GetGameIdFromUrl(url), teamAbbr, playerid, playerPos, batOrder, season.begin.Year );
                }
            }
        }
 public CheckPlayerDownloader(XmlParser parser, Season season, ErrorLog logger)
     : base(parser, season, logger)
 {
 }
 public BoxscoreDownloader(XmlParser parser, Season season, ErrorLog logger)
     : base(parser, season, logger)
 {
 }
Пример #8
0
 public LineupDownloader(XmlParser parser, Season season, ErrorLog logger)
     : base(parser, season, logger)
 {
 }
Пример #9
0
        public Season Create2015Season()
        {
            DateTime seasonStartDate = new DateTime( 2015, 4, 5 );
            DateTime seasonEndDate = new DateTime( 2015, 10, 4 );

            DateTime postseasonStartDate = new DateTime( 2015, 10, 6 );
            DateTime postseasonEndDate = new DateTime( 2015, 11, 4 );

            DateTime AllStarGame = new DateTime( 2015, 7, 14 );

            PostSeason postseason = Add2015PostSeason( new PostSeason( postseasonStartDate, postseasonEndDate ) );

            Season season = new Season( seasonStartDate, seasonEndDate, postseason );
            season.AddException( AllStarGame );
            season.ShouldIncludePostSeason = false;

            _dbcontext.InitializeSeason(2015);

            return season;
        }
Пример #10
0
        public Season Create2014Season()
        {
            DateTime seasonStartDate = new DateTime( 2014, 3, 30 );
            DateTime seasonEndDate = new DateTime( 2014, 9, 28 );

            DateTime postseasonStartDate = new DateTime( 2014, 9, 30 );
            DateTime postseasonEndDate = new DateTime( 2014, 10, 29 );

            DateTime AllStarGame = new DateTime( 2014, 7, 15 );

            PostSeason postseason = Add2014PostSeason( new PostSeason( postseasonStartDate, postseasonEndDate ) );

            Season season = new Season( seasonStartDate, seasonEndDate, postseason );
            season.AddException( AllStarGame );
            season.ShouldIncludePostSeason = true;

            season.AddExceptionGame( "2014/03/22/lanmlb-arimlb-1", new DateTime( 2014, 3, 22 ) );
            season.AddExceptionGame( "2014/03/23/lanmlb-arimlb-1", new DateTime( 2014, 3, 23 ) );

            _dbcontext.InitializeSeason( 2014 );

            return season;
        }
Пример #11
0
        public Season Create2013Season()
        {
            DateTime seasonStartDate = new DateTime( 2013, 3, 31 );
            DateTime seasonEndDate = new DateTime( 2013, 9, 30 );

            DateTime postseasonStartDate = new DateTime( 2013, 10, 1 );
            DateTime postseasonEndDate = new DateTime( 2013, 10, 30 );

            DateTime AllStarGame = new DateTime( 2013, 7, 16 );

            PostSeason postseason = Add2013PostSeason( new PostSeason( postseasonStartDate, postseasonEndDate ) );

            Season season = new Season( seasonStartDate, seasonEndDate, postseason );
            season.AddException( AllStarGame );
            season.ShouldIncludePostSeason = true;

            _dbcontext.InitializeSeason( 2013 );

            return season;
        }
Пример #12
0
        public Season Create2012Season()
        {
            DateTime seasonStartDate = new DateTime( 2012, 4, 5 );
            DateTime seasonEndDate = new DateTime( 2012, 10, 3 );

            DateTime postseasonStartDate = new DateTime( 2012, 10, 5 );
            DateTime postseasonEndDate = new DateTime( 2012, 10, 28 );

            DateTime AllStarGame = new DateTime( 2012, 7, 10 );

            PostSeason postseason = Add2012PostSeason( new PostSeason( postseasonStartDate, postseasonEndDate ) );

            Season season = new Season( seasonStartDate, seasonEndDate, postseason );
            season.AddException( AllStarGame );
            season.ShouldIncludePostSeason = true;

            season = this.Add2012SeasonGameExceptions( season );

            _dbcontext.InitializeSeason( 2012 );

            return season;
        }
Пример #13
0
        public Season Create2006Season()
        {
            DateTime seasonStartDate = new DateTime( 2006, 4, 3 );
            DateTime seasonEndDate = new DateTime( 2006, 10, 1 );

            DateTime postseasonStartDate = new DateTime( 2006, 10, 3 );
            DateTime postseasonEndDate = new DateTime( 2006, 10, 27 );

            DateTime AllStarGame = new DateTime( 2006, 7, 11 );

            PostSeason postseason = Add2006PostSeason( new PostSeason( postseasonStartDate, postseasonEndDate ) );

            Season season = new Season( seasonStartDate, seasonEndDate, postseason );
            season.AddException( AllStarGame );
            season.ShouldIncludePostSeason = true;

            season.AddExceptionGame( "gid_2006_04_02_clemlb_chamlb_1", new DateTime( 2006, 4, 2 ) );

            _dbcontext.InitializeSeason( 2006 );

            return season;
        }
Пример #14
0
        public override void Parse(XDocument doc, Season season, DateTime date, string url)
        {
            try
            {
                if (doc != null)
                {
                    date = Convert.ToDateTime( doc.Root.Attribute( "date" ).Value );
                    string gameID = doc.Root.Attribute( "game_id" ).Value;
                    Console.WriteLine( "\t  Parsing Boxscore " + gameID );

                    string startTime = "", gamestatus = "";
                    string[] startingPitchers = new[] { "", "" };

                    try
                    {
                        startTime = GamePreview.GetGameTime( gameID );
                        gamestatus = GamePreview.GetGameStatus( gameID );
                        startingPitchers = GamePreview.GetStartingPitchers( gameID );
                    }
                    catch (Exception e) { _logger.WriteError(e, "Boxscore Parser gamePreview"); }

                    Dictionary<int, int> players = this.GetPlayers(gameID);

                    int year = season.begin.Year;

                    try { InsertGameProfileData( doc, season, gameID, date, startTime, gamestatus ); }
                    catch (Exception e) { _logger.WriteError( e, "Parsing GameProfileData: " + gameID ); }

                    try { InsertInnings( doc, gameID ); }
                    catch (Exception e) { _logger.WriteError( e, "Parsing Innings: " + gameID ); }

                    try { InsertGameBattingFieldingStats( doc, year, gameID, date, players ); }
                    catch (Exception e) { _logger.WriteError( e, "Parsing Batting and Fielding Stats: " + gameID ); }

                    try { InsertGamePitchingStats( doc, year, gameID, date, startingPitchers ); }
                    catch (Exception e) { _logger.WriteError( e, "Parsing Pitching Stats: " + gameID ); }
                }
            }
            catch (Exception e)
            {
                _logger.WriteError( e, "Parse Method of BoxscoreParser" );
            }
        }
        public override void Parse(XDocument doc, Season season, DateTime date, string url)
        {
            string gameid = "";
            string homeTeam = "", awayTeam = "", timedate = "", dateString = "";
            try
            {
                if (season.begin.Year <= 2006)
                {
                    dateString = date.ToShortDateString();

                    string gameLink = doc.Root.Attribute( "gameday_link" ).Value;
                    string gameid_01 = gameLink.Substring( 0, 11 ).Replace( '_', '/' );
                    string gameid_02 = gameLink.Substring( 11 ).Replace( '_', '-' );

                    gameid = gameid_01 + gameid_02;

                    awayTeam = gameLink.Substring( 11, 3 );
                    homeTeam = gameLink.Substring( 18, 3 );
                }
                else
                {
                    homeTeam = doc.Root.Attribute( "home_code" ).Value;
                    awayTeam = doc.Root.Attribute( "away_code" ).Value;
                    gameid = doc.Root.Attribute( "id" ).Value;

                    if (season.begin.Year >= 2013)
                    {
                        timedate = doc.Root.Attribute( "time_date" ).Value;
                        dateString = timedate.Substring( 0, 10 );
                    }
                }
                string status = doc.Root.Attribute("status").Value;
                string time = doc.Root.Attribute("time").Value;
                string orginalDate = "";

                try { orginalDate = doc.Root.Attribute( "original_date" ).Value; }
                catch { orginalDate = date.ToShortDateString(); }

                int isPostSeasonGame = season.IsPostSeason ? 1 : 0;

                int umpid = -1;

                try
                {
                    XDocument playersDoc = Utility.Downloader.GetWebPage( Utility.UrlBuilder.GetUrlFromGameID( gameid ) + "players.xml" );
                    var umps = playersDoc.Root.Element( "umpires" ).Elements("umpire");

                    string name = "";

                    foreach (var ump in umps)
                    {
                        string pos = Convert.ToString( ump.Attribute( "position" ).Value );

                        if (pos == "home")
                        {
                            umpid = Convert.ToInt32( ump.Attribute("id").Value );
                            name = Convert.ToString( ump.Attribute("name").Value );
                            break;
                        }
                    }
                    try { _dbcontext.InsertUmp(umpid, name); }
                    catch (Exception) { }
                }
                catch (Exception e) { }

                _dbcontext.InsertScheduledGame(homeTeam, awayTeam, gameid, time, dateString, orginalDate, season.begin.Year, status, isPostSeasonGame, umpid);

                if (season.postSeason.IsPostSeasonGame(gameid))
                {
                    PostSeasonGame game = season.postSeason.GetPostSeasonGame(gameid);
                    _dbcontext.InsertPostSeasonGame( game.gameid, game.series );
                }
            }
            catch (Exception e)
            {
                _logger.WriteError( e, "Parsing Game " + gameid );
            }
        }
 public TeamScheduleDownloader(XmlParser parser, Season season, ErrorLog logger)
     : base(parser, season, logger)
 {
 }
Пример #17
0
 public Downloader(XmlParser parser, Season season, ErrorLog logger)
 {
     this.parser = parser;
     this.season = season;
     this.logger = logger;
 }
 public PlayByPlayDownloader(XmlParser parser, Season season, ErrorLog logger)
     : base(parser, season, logger)
 {
 }
Пример #19
0
 public abstract void Parse(XDocument doc, Season season, DateTime date, string url);
Пример #20
0
        public Season Add2012SeasonGameExceptions(Season season)
        {
            season.AddExceptionGame( "gid_2012_03_28_seamlb_oakmlb_1", new DateTime(2012, 3, 28) );
            season.AddExceptionGame( "gid_2012_03_29_seamlb_oakmlb_1", new DateTime( 2012, 3, 29 ) );
            season.AddExceptionGame( "gid_2012_04_04_slnmlb_flomlb_1", new DateTime( 2012, 4, 4 ) );

            return season;
        }
Пример #21
0
        /*       public void ParsePlayer(XDocument doc, int season)
        {
            string f = null; string l = null;
            try
            {
                string FirstName = doc.Root.Attribute("first_name").Value;
                string LastName = doc.Root.Attribute("last_name").Value;
                f = FirstName; l = LastName;
                Console.WriteLine("\t\t  Initializing " + FirstName + " " + LastName);

                string MLBTeamAbbr = doc.Root.Attribute("team").Value;
                DateTime Birthdate = Convert.ToDateTime(doc.Root.Attribute("dob").Value);

                if (!_dbcontext.PlayerExists(FirstName, LastName, season, Birthdate, MLBTeamAbbr))
                {
                    int MLBid = Convert.ToInt32(doc.Root.Attribute("id").Value);
                    string Bats = doc.Root.Attribute("bats").Value;
                    string Throws = doc.Root.Attribute("throws").Value;
                    string Height = doc.Root.Attribute("height").Value;
                    int Weight = Convert.ToInt32(doc.Root.Attribute("weight").Value);
                    string Position = doc.Root.Attribute("pos").Value;

                    _dbcontext.InitPlayer(MLBid, FirstName, LastName, MLBTeamAbbr, season, Bats, Throws, Birthdate, Height, Weight, Position);
                }
            }
            catch (Exception e)
            {
            }
        }*/
        public void InsertGameProfileData(XDocument doc, Season season, string gameID, DateTime date, string time, string status)
        {
            Console.WriteLine("\t\tInserting Game Profile");
            try
            {
                int awayruns = Convert.ToInt16(doc.Root.Element("linescore").Attribute("away_team_runs").Value);
                int homeruns = Convert.ToInt16(doc.Root.Element("linescore").Attribute("home_team_runs").Value);
                int awayhits = Convert.ToInt16(doc.Root.Element("linescore").Attribute("away_team_hits").Value);
                int homehits = Convert.ToInt16(doc.Root.Element("linescore").Attribute("home_team_hits").Value);
                int awayerrors = Convert.ToInt16(doc.Root.Element("linescore").Attribute("away_team_errors").Value);
                int homeerrors = Convert.ToInt16(doc.Root.Element("linescore").Attribute("home_team_errors").Value);

                _dbcontext.InsertGameProfileData(gameID, status, awayruns, awayhits, awayerrors, homeruns, homehits, homeerrors);

                if (season.IsPostSeason && season.ShouldIncludePostSeason)
                {
                    PostSeasonGame game = season.postSeason.GetPostSeasonGame( gameID );
                    _dbcontext.InsertPostSeasonGame( gameID, game.series );
                }
            }
            catch (Exception e)
            {
                _logger.WriteError( e, "Parsing Game Profile Data for " + gameID );
            }
        }