public void UpdateForSeason(SeasonType type, int startingYear) { // get all games for the season var teamGameLogs = NBAStats.GetTeamGameLogs(startingYear, type, "0", null, null); // iterate through unique games var uniqueGamesIds = teamGameLogs.Tables[0].AsEnumerable().Select(r => r.Field <String>("GAME_ID")).Distinct(); // Check if the game has been processes Dictionary <string, DataSet> gameResults = new Dictionary <string, DataSet>(); Parallel.ForEach(uniqueGamesIds, new ParallelOptions { MaxDegreeOfParallelism = 1 }, (gameId) => { gameResults.Add(gameId + "_BoxScoreSummary", NBAStats.GetBoxscoreSummary(gameId)); gameResults.Add(gameId + "_BoxScoreWholeGame", NBAStats.GetBoxScoreTraditionalV2(gameId)); //gameResults.Add(gameId + "_PlayByPlayV2", NBAStats.GetPlayByPlayV2(gameId)); //gameResults.Add(gameId + "_PlayByPlay", NBAStats.GetPlayByPlay(gameId)); }); // Insert box scores in sequence foreach (KeyValuePair <string, DataSet> kvp in gameResults) { _db.InsertData(kvp.Value); } // Insert all games _db.InsertData(teamGameLogs); }
public static DataSet GetBoxScoreTraditionalV2(string gameId) { // https://stats.nba.com/stats/boxscoretraditionalv2?EndPeriod=10&EndRange=28800&GameID=0011800076&RangeType=0&Season=2018-19&SeasonType=Pre+Season&StartPeriod=1&StartRange=0 String s = $"boxscoretraditionalv2?EndPeriod=10&EndRange=28800&GameID={gameId}&RangeType=0&StartPeriod=1&StartRange=0"; return(NBAStats.ReadApiResultSet(NBAStats.StatsApiGet($"boxscoretraditionalv2?EndPeriod=10&EndRange=28800&GameID={gameId}&RangeType=0&StartPeriod=1&StartRange=0"), "boxscoretraditionalv2wholegame")); }
public static DataSet GetPlayByPlay(String gameId) { // https://stats.nba.com/stats/playbyplayv2?GAMEID=0011800018&StartPeriod=0&EndPeriod=0 return(NBAStats.ReadApiResultSet(NBAStats.StatsApiGet($"playbyplay?GAMEID={gameId}&StartPeriod=0&EndPeriod=0"), "playbyplay", new List <string> { "PlayByPlay" })); }
public static DataSet GetBoxscoreSummary(string gameId) { var tablesToInclude = new List <string> { "GameInfo", "GameSummary", "InactivePlayers", "LineScore", "Officials", "OtherStats", "TeamGameLogs" }; DataSet ds = NBAStats.ReadApiResultSet(NBAStats.StatsApiGet($"boxscoresummaryv2/?gameId={gameId}"), "teamgamelogs", tablesToInclude); ds = NBAStats.UpdateApiResultSetWithValues(ds, new Dictionary <string, object> { { "GAME_ID", gameId } }); return(ds); }
//public static DataSet GetShotChartDetail(String gameId) //{ // // https://stats.nba.com/stats/shotchartdetail?AheadBehind=&CFID=&CFPARAMS=&ClutchTime=&Conference=&ContextFilter=&ContextMeasure=FGA&DateFrom=05%2F31%2F2018&DateTo=&Division=&EndPeriod=10&EndRange=28800&GROUP_ID=&GameEventID=&GameID=&GameSegment=&GroupID=&GroupMode=&GroupQuantity=5&LastNGames=0&LeagueID=00&Location=&Month=0&OnOff=&OpponentTeamID=0&Outcome=&PORound=0&Period=0&PlayerID=2544&PlayerID1=&PlayerID2=&PlayerID3=&PlayerID4=&PlayerID5=&PlayerPosition=&PointDiff=&Position=&RangeType=0&RookieYear=&Season=2017-18&SeasonSegment=&SeasonType=Playoffs&ShotClockRange=&StartPeriod=1&StartRange=0&StarterBench=&TeamID=1610612739&VsConference=&VsDivision=&VsPlayerID1=&VsPlayerID2=&VsPlayerID3=&VsPlayerID4=&VsPlayerID5=&VsTeamID= // String a = $"https://stats.nba.com/stats/shotchartdetail?AheadBehind=&CFID=&CFPARAMS=&ClutchTime=&Conference=&ContextFilter=&ContextMeasure=FGA&DateFrom=05%2F31%2F2018&DateTo=&Division=&EndPeriod=10&EndRange=28800&GROUP_ID=&GameEventID=&GameID=0011800018&GameSegment=&GroupID=&GroupMode=&GroupQuantity=5&LastNGames=0&LeagueID=00&Location=&Month=0&OnOff=&OpponentTeamID=0&Outcome=&PORound=0&Period=0&PlayerID=2544&PlayerID1=&PlayerID2=&PlayerID3=&PlayerID4=&PlayerID5=&PlayerPosition=&PointDiff=&Position=&RangeType=0&RookieYear=&Season=2017-18&SeasonSegment=&SeasonType=Playoffs&ShotClockRange=&StartPeriod=1&StartRange=0&StarterBench=&TeamID=1610612745&VsConference=&VsDivision=&VsPlayerID1=&VsPlayerID2=&VsPlayerID3=&VsPlayerID4=&VsPlayerID5=&VsTeamID="; //} // Get games for day // https://stats.nba.com/stats/scoreboardV2?DayOffset=0&LeagueID=00&gameDate=10%2F06%2F2018 public static DataSet GetTeamGameLogs(int seasonStartingYear, SeasonType seasonType, string teamId, DateTime?fromDate, DateTime?toDate, String leagueId = "00") { String fromDateFormatted = FormatDateTimeToString(fromDate, ""); String toDateFomatted = FormatDateTimeToString(toDate, ""); String season = FormatSeason(seasonStartingYear); if (String.IsNullOrEmpty(teamId)) { teamId = "0"; } String uri = $"teamgamelogs?DateFrom={fromDate}&DateTo={toDate}&GameSegment=&LastNGames=0&LeagueID={leagueId}&Location=&MeasureType=Base&Month=0&OpponentTeamID={teamId}&Outcome=&PORound=0&PaceAdjust=N&PerMode=Totals&Period=0&PlusMinus=N&Rank=N&Season={season}&SeasonSegment=&SeasonType={FormatSeasonType(seasonType)}&ShotClockRange=&TeamID=&VsConference=&VsDivision="; return(NBAStats.ReadApiResultSet(NBAStats.StatsApiGet(uri), "teamgamelogs")); }