public async Task SaveGameInformation(GamePageInformation gameInfo) { Console.WriteLine("Retrieving Leagues..."); var leagues = await _leagueService.List(); var league = leagues.First(s => s.Name == "DIHL"); Console.WriteLine("Retrieving Seaons..."); var seasons = await _seasonService.List(); var season = seasons.First(s => s.LeagueId == league.Id && s.Year == 2018); Console.WriteLine("Retrieving Teams..."); var teams = await _teamService.List(); var homeTeam = teams.First(s => s.Name == gameInfo.HomeTeam && s.LeagueId == league.Id); var awayTeam = teams.First(s => s.Name == gameInfo.AwayTeam && s.LeagueId == league.Id); Console.WriteLine("Saving Game..."); var game = await SaveGame(gameInfo, awayTeam, homeTeam, season); Console.WriteLine("Saving Games Played..."); await SaveGamesPlayed(gameInfo.AwayRoster, awayTeam.Id, game.Id); await SaveGamesPlayed(gameInfo.HomeRoster, homeTeam.Id, game.Id); Console.WriteLine("Saving Penalties..."); await SavePenalties(gameInfo.GamePenalties, teams, game.Id); Console.WriteLine("Saving Goals..."); await SaveGoals(gameInfo.GameGoals, teams, game.Id); Console.WriteLine("Saving Goalie Statistics..."); await SaveGoalieStatistics(gameInfo.HomeGoalieStats, game.Id, homeTeam.Id); await SaveGoalieStatistics(gameInfo.AwayGoalieStats, game.Id, awayTeam.Id); }
private void PopulateGameInformation(GamePageInformation gameInfo) { string headerSelector = "#form1 > div:nth-child(9) > div.mso-section-blue.mso-big.mso-bold > div"; string headerString = _webDriver.FindElement(By.CssSelector(string.Format(headerSelector, "1"))).Text; string[] splitHeader = headerString.Split("\r\n"); string timeString = splitHeader[0]; string location = splitHeader[1]; if (timeString.StartsWith("0")) { timeString = timeString.Substring(6); } var gameDate = DateTime.ParseExact(timeString, "dddd MMMM d, yyyy - h:mm tt", null); gameInfo.Time = gameDate.TimeOfDay; gameInfo.Date = gameDate.Date; gameInfo.Location = location; gameInfo.AwayTeam = _webDriver.FindElement(By.CssSelector("#maincontent_divTeamAway > span.mso-big.mso-bold")).Text; gameInfo.HomeTeam = _webDriver.FindElement(By.CssSelector("#maincontent_divTeamHome > strong > span")).Text; string awayScore = _webDriver.FindElement(By.CssSelector("#form1 > div:nth-child(9) > div:nth-child(2) > div:nth-child(2) > div:nth-child(2) > div.col-xs-5.col-sm-5.text-right")).Text; string homeScore = _webDriver.FindElement(By.CssSelector("#form1 > div:nth-child(9) > div:nth-child(2) > div:nth-child(2) > div:nth-child(2) > div.col-xs-5.col-sm-5.text-left")).Text; gameInfo.AwayScore = int.Parse(awayScore); gameInfo.HomeScore = int.Parse(homeScore); }
public void PopulateGoalieStatistics(GamePageInformation gameInfo) { var homeGoalies = _webDriver.FindElements(By.CssSelector("#maincontent_gvGoaliesHome_gvPlayers > tbody > tr")); gameInfo.HomeGoalieStats = new List <GamePageGoalieStats>(); foreach (var player in homeGoalies) { var columns = player.FindElements(By.CssSelector("td")); GamePageGoalieStats goalieStats = new GamePageGoalieStats() { GoalieName = columns[0].Text, ShotsAgainst = int.Parse(columns[1].Text), GoalsAgainst = int.Parse(columns[2].Text), Saves = int.Parse(columns[3].Text), Win = int.Parse(columns[7].Text), Loss = int.Parse(columns[8].Text), Tie = int.Parse(columns[9].Text), SOW = int.Parse(columns[11].Text), SOL = int.Parse(columns[12].Text) }; gameInfo.HomeGoalieStats.Add(goalieStats); gameInfo.HomeRoster.Add(goalieStats.GoalieName); } var awayGoalies = _webDriver.FindElements(By.CssSelector("#maincontent_gvGoaliesVisitor_gvPlayers > tbody > tr")); gameInfo.AwayGoalieStats = new List <GamePageGoalieStats>(); foreach (var player in awayGoalies) { var columns = player.FindElements(By.CssSelector("td")); GamePageGoalieStats goalieStats = new GamePageGoalieStats() { GoalieName = columns[0].Text, ShotsAgainst = int.Parse(columns[1].Text), GoalsAgainst = int.Parse(columns[2].Text), Saves = int.Parse(columns[3].Text), Win = int.Parse(columns[7].Text), Loss = int.Parse(columns[8].Text), Tie = int.Parse(columns[9].Text), SOW = int.Parse(columns[11].Text), SOL = int.Parse(columns[12].Text) }; gameInfo.AwayGoalieStats.Add(goalieStats); gameInfo.AwayRoster.Add(goalieStats.GoalieName); } }
private async Task <GameDTO> SaveGame(GamePageInformation gameInfo, TeamDTO awayTeam, TeamDTO homeTeam, SeasonDTO season) { GameDTO gameDto = new GameDTO() { AwayTeamId = awayTeam.Id, HomeTeamId = homeTeam.Id, Date = gameInfo.Date, Time = gameInfo.Time, Location = gameInfo.Location, SeasonId = season.Id, CreatedOnUtc = DateTime.Now }; return(await _gameService.Upsert(gameDto)); }
public GamePageInformation RetrieveGameDetails() { GamePageInformation gameInfo = new GamePageInformation(); Console.WriteLine("Gathering game information..."); PopulateGameInformation(gameInfo); Console.WriteLine("Gathering game goals..."); PopulateGameGoals(gameInfo); //TODO: Check for shootout goals Console.WriteLine("Gathering game penalties..."); PopulateGamePenalties(gameInfo); Console.WriteLine("Gathering game rosters..."); PopulateRosters(gameInfo); Console.WriteLine("Gathering game goalie statistics..."); PopulateGoalieStatistics(gameInfo); return(gameInfo); }
private void PopulateGamePenalties(GamePageInformation gameInfo) { var tableRows = _webDriver.FindElements(By.CssSelector("#maincontent_gvBoxScorePim > tbody > tr")); int period = 0; gameInfo.GamePenalties = new List <GamePagePenalty>(); foreach (var row in tableRows) { var columns = row.FindElements(By.CssSelector("td")); if (columns.Count == 1) { if (!string.IsNullOrEmpty(columns[0].GetAttribute("style"))) { period++; } } else { //Populate info string time = columns[0].Text; string teamShortCode = columns[1].Text; string player = columns[2].Text; string penaltyType = columns[3].Text; string length = columns[4].Text; if (!string.IsNullOrEmpty(penaltyType) && !string.IsNullOrEmpty(time)) { GamePagePenalty penalty = new GamePagePenalty { Period = period, Time = string.IsNullOrEmpty(time) ? (TimeSpan?)null : TimeSpan.Parse(time), TeamShortCode = teamShortCode, Player = player, PenaltyType = penaltyType, Length = !string.IsNullOrEmpty(length) ? TimeSpan.Parse(length) : TimeSpan.FromMinutes(0) }; gameInfo.GamePenalties.Add(penalty); } } } }
private void PopulateRosters(GamePageInformation gameInfo) { var homePlayers = _webDriver.FindElements(By.CssSelector("#maincontent_gvSkatersHome_gvPlayers_wrapper > div:nth-child(2) > div > div > div.DTFC_LeftWrapper > div.DTFC_LeftBodyWrapper > div > table > tbody > tr")); gameInfo.HomeRoster = new List <string>(); foreach (var player in homePlayers) { var columns = player.FindElements(By.CssSelector("td")); gameInfo.HomeRoster.Add(columns[0].Text); } var awayPlayers = _webDriver.FindElements(By.CssSelector("#maincontent_gvSkatersVisitor_gvPlayers_wrapper > div:nth-child(2) > div > div > div.DTFC_LeftWrapper > div.DTFC_LeftBodyWrapper > div > table > tbody > tr")); gameInfo.AwayRoster = new List <string>(); foreach (var player in awayPlayers) { var columns = player.FindElements(By.CssSelector("td")); gameInfo.AwayRoster.Add(columns[0].Text); } }
private void PopulateGameGoals(GamePageInformation gameInfo) { //TODO: The website has changed, this may need to change to reflect that var tableRows = _webDriver.FindElements(By.CssSelector("#maincontent_gvBoxScoreGoals > tbody > tr")); int period = 0; gameInfo.GameGoals = new List <GamePagePoint>(); foreach (var row in tableRows) { var columns = row.FindElements(By.CssSelector("td")); if (columns.Count == 1) { if (!string.IsNullOrEmpty(columns[0].GetAttribute("style"))) { period++; } } else { //Populate info string time = columns[0].Text; string teamShortCode = columns[1].Text; string scorers = columns[2].Text; string details = columns[3].Text.Replace("\r\n", ", "); GamePagePoint point = new GamePagePoint { Period = period, Time = string.IsNullOrEmpty(time) ? (TimeSpan?)null : TimeSpan.Parse(time), TeamShortCode = teamShortCode, PointScorers = scorers, Details = details }; gameInfo.GameGoals.Add(point); } } }