public async Task <bool> SaveTeamsBoxScorePlayoffs(int gameId, List <BoxScore> boxScores) { for (int i = 0; i < boxScores.Count; i++) { BoxScore bs = boxScores[i]; PlayoffBoxScore gbs = new PlayoffBoxScore { GameId = gameId, TeamId = bs.TeamId, PlayerId = bs.Id, Minutes = bs.Minutes, Points = bs.Points, Rebounds = bs.Rebounds, Assists = bs.Assists, Steals = bs.Steals, Blocks = bs.Blocks, BlockedAttempts = bs.BlockedAttempts, FieldGoalsMade = bs.FGM, FieldGoalsAttempted = bs.FGA, ThreeFieldGoalsMade = bs.ThreeFGM, ThreeFieldGoalsAttempted = bs.ThreeFGA, FreeThrowsMade = bs.FTM, FreeThrowsAttempted = bs.FTA, ORebs = bs.ORebs, DRebs = bs.DRebs, Turnovers = bs.Turnovers, Fouls = bs.Fouls, PlusMinus = bs.PlusMinus }; await _context.AddAsync(gbs); } return(await _context.SaveChangesAsync() > 0); }
public void GetGameBoxScoreTestBasic() { NHLApiClient api = new NHLApiClient(); // Load Expected result from file var testResponse = File.ReadAllText(@"../../../TestAPIResponses/GetGameBoxScoreResult.json"); var jobj = JObject.Parse(testResponse); var expected = JsonConvert.DeserializeObject <BoxScore>(jobj.ToString()); // Make API web call BoxScore actual = api.GetGameBoxScore(2017030325); //Jets vs Vegas WCF Game 5 2018 //Assert Assert.AreEqual(expected, actual); }
private void UpdatePlayerData(DateTime date) { string dateString = date.ToString("yyyy-MM-dd"); ConfigFile file = new ConfigFile(true); if (file.ScheduleDaysLoaded.Contains(dateString)) { return; } Schedule sched = new Schedule(dateString); bool save = true; if (sched.games != null) { foreach (Game game in sched.games) { List <Player> plrs = game.gameParticipants; if (plrs != null && plrs.Count > 0) { Dictionary <int, int> plrsIndex = Player.PlayerIdToIndexVault(plrs); BoxScore bs = game.gameBoxScore; List <PlayerGameStats> playerGameStats = bs.awayTeamStats.teamPlayers.Concat(bs.homeTeamStats.teamPlayers).ToList(); for (int i = 0; i < playerGameStats.Count(); i++) { PlayerEnhanced plrE = new PlayerEnhanced(); int index; plrsIndex.TryGetValue(playerGameStats[i].playerID, out index); plrE.Player = plrs[index]; plrE.GameStats.Add(playerGameStats[i]); UpdatePlayer(plrE, game.gameID); } } else { Console.Error.WriteLine($"gameParticipants found to be null or empty. File not saved for {dateString}"); save = false; } } if (save) { this.SaveToFile(); file.ScheduleDaysLoaded.Add(dateString); file.SaveToFile(); } } }
public async Task <IEnumerable <BoxScore> > GetBoxScoresForGameIdPlayoffs(int gameId) { List <BoxScore> boxScores = new List <BoxScore>(); var gameBoxScores = await _context.PlayoffBoxScores.Where(x => x.GameId == gameId).ToListAsync(); foreach (var gbs in gameBoxScores) { // Need to get player name var player = await _context.Players.FirstOrDefaultAsync(x => x.Id == gbs.PlayerId); BoxScore bs = new BoxScore { Id = gbs.Id, ScheduleId = gbs.GameId, TeamId = gbs.TeamId, FirstName = player.FirstName, LastName = player.Surname, Minutes = gbs.Minutes, Points = gbs.Points, Rebounds = gbs.Rebounds, Assists = gbs.Assists, Steals = gbs.Steals, Blocks = gbs.Blocks, BlockedAttempts = gbs.BlockedAttempts, FGM = gbs.FieldGoalsMade, FGA = gbs.FieldGoalsAttempted, ThreeFGM = gbs.ThreeFieldGoalsMade, ThreeFGA = gbs.ThreeFieldGoalsAttempted, FTM = gbs.FreeThrowsMade, FTA = gbs.FreeThrowsAttempted, ORebs = gbs.ORebs, DRebs = gbs.DRebs, Turnovers = gbs.Turnovers, Fouls = gbs.Fouls, PlusMinus = gbs.PlusMinus }; boxScores.Add(bs); } return(boxScores); }
public static BoxScore GetBoxScore(int gameId) { BoxScore boxScore = new BoxScore(); var client = new HttpClient(); // Request headers client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Ocp_Apim_Subscription_Key); // Id 15 - Campeonato Brasileiro var uri = "https://api.fantasydata.net/v3/soccer/stats/json/BoxScore/" + gameId; HttpResponseMessage response = client.GetAsync(uri).Result; if (response.IsSuccessStatusCode) { var json = response.Content.ReadAsStringAsync().Result; List <BoxScore> box = JsonConvert.DeserializeObject <List <BoxScore> >(json); boxScore = box.FirstOrDefault(); } return(boxScore); }
public BoxScore ParseGameHTML(Game gameObj, string html) { var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(html); var awayTeam = htmlDocument.DocumentNode.Descendants("h5").ElementAt(0).InnerText; var homeTeam = htmlDocument.DocumentNode.Descendants("h5").ElementAt(1).InnerText; var bs = new BoxScore(); bs.AwayTeam = awayTeam.Substring(0, awayTeam.Length - 10); bs.HomeTeam = homeTeam.Substring(0, homeTeam.Length - 10); var awayHittingTable = htmlDocument.DocumentNode.Descendants("table").ElementAt(0); var homeHittingTable = htmlDocument.DocumentNode.SelectNodes("//table").ElementAt(1); var awayPitchingTable = htmlDocument.DocumentNode.SelectNodes("//table").ElementAt(2); var homePitchingTable = htmlDocument.DocumentNode.SelectNodes("//table").ElementAt(3); try { var playerRows = awayHittingTable.Descendants("tr") .Where(node => node.GetAttributeValue("class", "") .Contains("playerRow")) .ToList(); foreach (var row in playerRows) { var tds = row.Descendants("td"); bs.AwayHittingBoxLines.Add(new HittingBoxLine { Name = tds.ElementAt(0).InnerText.Trim(), AB = Int32.Parse(tds.ElementAt(1).InnerText.Trim()), R = Int32.Parse(tds.ElementAt(2).InnerText.Trim()), H = Int32.Parse(tds.ElementAt(3).InnerText.Trim()), RBI = Int32.Parse(tds.ElementAt(4).InnerText.Trim()), BB = Int32.Parse(tds.ElementAt(5).InnerText.Trim()), SO = Int32.Parse(tds.ElementAt(6).InnerText.Trim()), }); } playerRows = homeHittingTable.Descendants("tr") .Where(node => node.GetAttributeValue("class", "") .Contains("playerRow")) .ToList(); foreach (var row in playerRows) { var tds = row.Descendants("td"); bs.HomeHittingBoxLines.Add(new HittingBoxLine { Name = tds.ElementAt(0).InnerText.Trim(), AB = Int32.Parse(tds.ElementAt(1).InnerText.Trim()), R = Int32.Parse(tds.ElementAt(2).InnerText.Trim()), H = Int32.Parse(tds.ElementAt(3).InnerText.Trim()), RBI = Int32.Parse(tds.ElementAt(4).InnerText.Trim()), BB = Int32.Parse(tds.ElementAt(5).InnerText.Trim()), SO = Int32.Parse(tds.ElementAt(6).InnerText.Trim()), }); } playerRows = awayPitchingTable.Descendants("tr") .Where(node => node.GetAttributeValue("class", "") .Contains("playerRow")) .ToList(); foreach (var row in playerRows) { var tds = row.Descendants("td"); bs.AwayPitchingBoxLines.Add(new PitchingBoxLine { Name = tds.ElementAt(0).InnerText.Trim(), IP = float.Parse(tds.ElementAt(1).InnerText.Trim()), NumberPitches = int.Parse(tds.ElementAt(2).InnerText.Trim()), StikePercent = float.Parse(tds.ElementAt(3).InnerText.Trim()), H = Int32.Parse(tds.ElementAt(4).InnerText.Trim()), R = Int32.Parse(tds.ElementAt(5).InnerText.Trim()), ER = Int32.Parse(tds.ElementAt(6).InnerText.Trim()), SO = Int32.Parse(tds.ElementAt(7).InnerText.Trim()), BB = Int32.Parse(tds.ElementAt(8).InnerText.Trim()), HR = Int32.Parse(tds.ElementAt(9).InnerText.Trim()), }); } playerRows = homePitchingTable.Descendants("tr") .Where(node => node.GetAttributeValue("class", "") .Contains("playerRow")) .ToList(); foreach (var row in playerRows) { var tds = row.Descendants("td"); bs.HomePitchingBoxLines.Add(new PitchingBoxLine { Name = tds.ElementAt(0).InnerText.Trim(), IP = float.Parse(tds.ElementAt(1).InnerText.Trim()), NumberPitches = int.Parse(tds.ElementAt(2).InnerText.Trim()), StikePercent = float.Parse(tds.ElementAt(3).InnerText.Trim()), H = Int32.Parse(tds.ElementAt(4).InnerText.Trim()), R = Int32.Parse(tds.ElementAt(5).InnerText.Trim()), ER = Int32.Parse(tds.ElementAt(6).InnerText.Trim()), SO = Int32.Parse(tds.ElementAt(7).InnerText.Trim()), BB = Int32.Parse(tds.ElementAt(8).InnerText.Trim()), HR = Int32.Parse(tds.ElementAt(9).InnerText.Trim()), }); } } catch (Exception) { //crap excecption catching Console.WriteLine("No Game Data!"); } return(bs); }
// GET: Jogo public ActionResult Index(int gameId) { BoxScore jogo = Campeonato.GetBoxScore(gameId); return(View(jogo)); }
protected override void OnNavigatedTo(NavigationEventArgs e) { this.BoxScore = (BoxScore)e.Parameter; base.OnNavigatedTo(e); }
static public ISportingRequest GetRequest(string get) { ISportingRequest selector = null; switch (get) { case SportAPIUtil.Schedule: selector = new Schedule(); break; case SportAPIUtil.LeagueHierarchy: selector = new LeagueHierarchy(); break; case SportAPIUtil.TeamGameStatByDate: selector = new TeamGameStatByDate(); break; case SportAPIUtil.Standings: selector = new Standings(); break; case SportAPIUtil.PlayersByTeam: selector = new PlayersByTeam(); break; case SportAPIUtil.CompetitionFixtures: selector = new CompetitionFixtures(); break; case SportAPIUtil.PlayerGameStatsByDate: selector = new PlayerGameStatsByDate(); break; case SportAPIUtil.PlayerSeasonStatsByTeam: selector = new PlayerSeasonStatsByTeam(); break; case SportAPIUtil.GamesByDate: selector = new GamesByDate(); break; case SportAPIUtil.BoxScore: selector = new BoxScore(); break; case SportAPIUtil.CompetitionsByGameId: selector = new CompetitionsByGameId(); break; case SportAPIUtil.BoxScoresByDateAndCompetition: selector = new BoxScoresByDateAndCompetition(); break; case SportAPIUtil.Competitions: selector = new Competitions(); break; default: break; } return(selector); }