public static TeamStandingsForm ToViewModel(this TeamStanding model) { var viewModel = new TeamStandingsForm { Id = model.Id, Team = model.Team, Games = model.Games, Home = model.Home, Last5 = model.Last5, Lost = model.Lost, Papf = model.Papf, Pts = model.Pts, Rank = model.Rank, Road = model.Road, ScoreRoad = model.ScoreRoad, ScoreHome = model.ScoreHome, Wins = model.Wins, PlusMinusField = model.PlusMinusField }; if (Thread.CurrentThread.CurrentUICulture.Name == "he-IL") { ReverseValues(viewModel, model); } return(viewModel); }
private static List <TeamStanding> GetHeadToHeadRecordsFor(Team teamData) { var results = new List <TeamStanding>(); var grouping = teamData.Games.GroupBy(g => g.OpponentOf(teamData)).OrderByDescending(g => g.Count()); foreach (var group in grouping) { int wins = group.Where(g => g.Week.Name.StartsWith("Week ")).Count(g => g.GetWinningTeam() == teamData); int losses = group.Where(g => g.Week.Name.StartsWith("Week ")).Count(g => g.GetLosingTeam() == teamData); int pwins = group.Where(g => !g.Week.Name.StartsWith("Week ")).Count(g => g.GetWinningTeam() == teamData); int plosses = group.Where(g => !g.Week.Name.StartsWith("Week ")).Count(g => g.GetLosingTeam() == teamData); var r = new TeamStanding() { Team = group.Key, SeasonRecord = new Record() { Wins = wins, Losses = losses }, PlayoffRecord = new Record() { Wins = pwins, Losses = plosses }, }; results.Add(r); } return(results); }
/// <summary> /// Determines if any team in the arena has the current standing. /// </summary> /// <param name="arena">The arena to check.</param> /// <param name="standing">The standing to check for.</param> /// <returns>True if any team has the given standing.</returns> public static bool AnyTeamHasStanding(this IArena arena, TeamStanding standing) { if (arena is null) { throw new ArgumentNullException(nameof(arena)); } return(arena.Teams.Any((team) => team.CurrentStanding == standing)); }
internal List <TeamStanding> GetStandings(string competitionName) { List <TeamStanding> teamStandings = new List <TeamStanding>(); try { List <Matches> matches = _matchesList?.Where(x => x.MatchTypeName == competitionName && /*(x.StatusId == 13 || x.StatusId == 12)&& */ (x.RoundId < 1000)).ToList(); foreach (Matches match in matches) { if (!teamStandings.Any(x => x.Team.Trim() == match.HomeTeam.Trim())) { TeamStanding teamStanding = new TeamStanding { Team = match.HomeTeam, TeamID = _teamsList?.FirstOrDefault(x => x.TeamName.Trim() == match.HomeTeam.Trim())?.TeamId ?? 0, CompetitionName = competitionName }; teamStandings.Add(teamStanding); CalculatePoints(teamStanding, match, match.HomeTeamScore, match.AwayTeamScore); } else { TeamStanding teamStanding = teamStandings.FirstOrDefault(x => x.Team.Trim() == match.HomeTeam.Trim()); CalculatePoints(teamStanding, match, match.HomeTeamScore, match.AwayTeamScore); } if (!teamStandings.Any(x => x.Team.Trim() == match.AwayTeam.Trim())) { TeamStanding teamStanding = new TeamStanding { Team = match.AwayTeam, TeamID = _teamsList?.FirstOrDefault(x => x.TeamName.Trim() == match.AwayTeam.Trim())?.TeamId ?? 0, CompetitionName = competitionName }; teamStandings.Add(teamStanding); CalculatePoints(teamStanding, match, match.AwayTeamScore, match.HomeTeamScore); } else { TeamStanding teamStanding = teamStandings.FirstOrDefault(x => x.Team.Trim() == match.AwayTeam.Trim()); CalculatePoints(teamStanding, match, match.AwayTeamScore, match.HomeTeamScore); } } } catch (Exception ex) { var exception = ex.Message; } //ReducePenaltiesPoint(teamStandings); teamStandings.RemoveAll(x => x.TeamID == 0); return(teamStandings.OrderByDescending(x => x.Points) .ThenByDescending(x => x.GoalDifference) .ThenByDescending(x => x.GoalScored) .ThenBy(x => x.GoalAgainst).ToList()); }
private static void ReverseValues(TeamStandingsForm viewModel, TeamStanding model) { viewModel.Home = model.Home.Reverse(); viewModel.Last5 = model.Last5.Reverse(); viewModel.Papf = model.Papf.Reverse(); viewModel.Road = model.Road.Reverse(); viewModel.ScoreRoad = model.ScoreRoad.Reverse(); viewModel.ScoreHome = model.ScoreHome.Reverse(); viewModel.PlusMinusField = model.PlusMinusField.Reverse(); }
/// <summary> /// Gets all the teams with the given standing. /// </summary> /// <param name="arena">The arena to check against.</param> /// <param name="standing">The standing to search for.</param> /// <returns>A sequence of teams that match the check.</returns> public static IEnumerable <T> GetTeamsWithStanding <T>(this IArena arena, TeamStanding standing) where T : ITeam { if (arena is null) { throw new ArgumentNullException(nameof(arena)); } return(from team in arena.Teams where team.CurrentStanding == standing select(T) team); }
private TeamStanding _generateTeamStandingFromRow(Element row) { var team = new TeamStanding { Rank = int.Parse(row.FindElement(By.CssSelector(".ordinal")).Text), Name = row.FindElement(By.CssSelector(".team .name")).Text, Record = row.FindElement(By.CssSelector(".team .record")).Text }; return(team); }
private string GetPositionColor(TeamStanding teamStanding) { if (teamStanding.CompetitionName == "Betri deildin") { switch (teamStanding.Position) { case 1: return("gold"); case 3: return("green"); case 8: return("darkred"); default: return("dimgray"); } } else if (teamStanding.CompetitionName == "Betri deildin kvinnur") { switch (teamStanding.Position) { case 1: return("gold"); default: return("dimgray"); } } else if (teamStanding.CompetitionName == "VFF Cup") { return("dimgray"); } else if (teamStanding.CompetitionName == "VFF Cup kvinnur") { return("dimgray"); } else { switch (teamStanding.Position) { case 2: return("green"); case 8: return("darkred"); default: return("dimgray"); } } }
public TeamStanding GetTeamByName(string name) { var row = Map.TeamRows.FirstOrDefault(r => r.Text.Contains(name)); var team = new TeamStanding { Rank = int.Parse(row.FindElement(By.CssSelector(".rank")).Text), Name = row.FindElement(By.CssSelector(".team-container")).Text, Record = row.FindElement(By.CssSelector(".record.show-for-large-up")).Text }; return(team); }
public WeeklyTable(IMessageChannel chnl) { var leagueTable = new Action(async() => { var system = new string[] { "psn", "xbox" }; foreach (var table in system) { EmbedBuilder embed = new EmbedBuilder(); // TeamInfo.ClubInfo("psn","Leverkusen", ref embed); TeamStanding.GetStandings(table, ref embed, "WeeklyTable"); await chnl.SendMessageAsync("", embed: embed.Build()); } }); Schedule(leagueTable).ToRunNow().AndEvery(1).Weeks().On(DayOfWeek.Wednesday).At(12, 0); }
public async Task Standings(string league) { EmbedBuilder embed = new EmbedBuilder(); var options = new RequestOptions { Timeout = 2 }; await Context.Message.DeleteAsync(options); if (Context.Channel.Id == Convert.ToUInt64(Environment.GetEnvironmentVariable("stats_channel"))) { TeamStanding.GetStandings(league, ref embed, "Standings"); await ReplyAsync("", embed : embed.Build()); } else { await ReplyAsync( $"{Context.User.Mention} you are using the command in the wrong channel, try again in " + $"{MentionUtils.MentionChannel(Convert.ToUInt64(Environment.GetEnvironmentVariable("stats_channel")))}"); } }
private void CalculatePoints(TeamStanding teamStanding, Matches match, int?mainTeamScore, int?opponentTeamScore) { //teamStanding.IsLive = !teamStanding.IsLive && match.StatusId > 1 && match.StatusId < 5; //if (match.StatusId < 2 || match.StatusId > 13) //{ // return; //} if (match.StatusId != 12 && match.StatusId != 13) { return; } teamStanding.MatchesNo += 1; if (mainTeamScore != null && opponentTeamScore != null) { if (mainTeamScore > opponentTeamScore) { teamStanding.Points += 3; teamStanding.Victories += 1; } else if (mainTeamScore == opponentTeamScore) { teamStanding.Points += 1; teamStanding.Draws += 1; } else if (mainTeamScore < opponentTeamScore) { teamStanding.Losses += 1; } teamStanding.GoalScored += mainTeamScore; teamStanding.GoalAgainst += opponentTeamScore; teamStanding.GoalDifference = teamStanding.GoalScored - teamStanding.GoalAgainst; } var result = (double)teamStanding.Points / (teamStanding.MatchesNo * 3) * 100; teamStanding.PointsProcent = (int)Math.Round((double)result, 2); }
public StandingsVM GetLeagueStandings() { FantasyContent content; StandingsVM standingsVM = new StandingsVM(); try { content = Client.ExecuteRequest <FantasyContent>(@"http://fantasysports.yahooapis.com/fantasy/v2/league/359.l.247388/standings"); } catch (SportsApiException) { var token = Client.RefreshToken(); content = Client.ExecuteRequest <FantasyContent>(@"http://fantasysports.yahooapis.com/fantasy/v2/league/359.l.247388/standings"); } standingsVM.leagueName = content.League.Name; List <TeamStanding> teamStandings = new List <TeamStanding>(); int placement = 1; foreach (var team in content?.League.LeagueStandings.Teams) { TeamStanding teamStanding = new TeamStanding() { TeamManager = team.Managers.Single().Nickname, Placement = placement, NumberOfMoves = team.NumberOfMoves, logoUrl = team.Logos.Single().LogoUrl }; placement++; teamStandings.Add(teamStanding); } standingsVM.TeamStandings = teamStandings; return(standingsVM); }
public void ForceStanding(TeamStanding standing) { // This is needed, but how widely? Or should I make this // a forfeit method? CurrentStanding = standing; }
public void ForceStanding(TeamStanding standing) { throw new System.NotImplementedException(); }
/// <summary> /// Gets the number of teams with the given standing. /// </summary> /// <param name="arena">The arena to check against.</param> /// <param name="standing">The standing to search for.</param> /// <returns>The number of teams with the given standing.</returns> public static int CountTeamsWithStanding(this IArena arena, TeamStanding standing) { return(arena.GetTeamsWithStanding <ITeam>(standing).Count()); }
public void UpdateTeamStandingsFromScrapper(IList <string> gamesUrl) { var standings = new List <StandingDTO>(); var service = new ScrapperService(); foreach (var standingUrl in gamesUrl) { var items = service.StandingScraper(standingUrl); standings.AddRange(items); } foreach (var standing in standings) { //var strToIntRank = Convert.ToInt32(standing.Rank.Replace(".", string.Empty)); int outVal; int.TryParse(standing.Rank.Replace(".", string.Empty), out outVal); var dbStanding = db.TeamStandings.FirstOrDefault( x => x.Team == standing.Team); //if we find the team update it if (dbStanding != null) { dbStanding.Rank = outVal; dbStanding.Games = standing.Games.ToByte(); dbStanding.Wins = standing.Win.ToByte(); dbStanding.Lost = standing.Lost.ToByte(); dbStanding.Pts = standing.Pts.ToByte(); dbStanding.Papf = standing.PaPf; dbStanding.Home = standing.Home; dbStanding.Road = standing.Road; dbStanding.ScoreHome = standing.ScoreHome; dbStanding.ScoreRoad = standing.ScoreRoad; dbStanding.Last5 = standing.Last5; dbStanding.PlusMinusField = standing.PlusMinusField; } //else create new teamStanding else { var standingGameId = db.TeamStandingGames.FirstOrDefault(x => x.GamesUrl == standing.Url)?.Id; var newTeamStnading = new TeamStanding { Team = standing.Team, Rank = outVal, Games = standing.Games.ToByte(), Wins = standing.Win.ToByte(), Lost = standing.Lost.ToByte(), Pts = standing.Pts.ToByte(), Papf = standing.PaPf, Home = standing.Home, Road = standing.Road, ScoreHome = standing.ScoreHome, ScoreRoad = standing.ScoreRoad, Last5 = standing.Last5, TeamStandingGamesId = standingGameId, PlusMinusField = standing.PlusMinusField, }; db.TeamStandings.Add(newTeamStnading); } } try { Save(); service.Quit(); } catch (DbEntityValidationException e) { } catch (Exception) { throw; } }
public void UpdateTeamStandingsFromModel(List <StandingDTO> standings, int standingId, string newUrl) { //TODO clear previous data if url is different. var existedTeamStandingGame = db.TeamStandings.Where(x => x.TeamStandingGamesId == standingId && x.TeamStandingGame.GamesUrl != newUrl).ToList(); if (existedTeamStandingGame.Count > 0) { db.TeamStandings.RemoveRange(existedTeamStandingGame); Save(); } foreach (var standing in standings) { var strToIntRank = Convert.ToInt32(standing.Rank.Replace(".", string.Empty)); var dbStanding = db.TeamStandings.FirstOrDefault( x => x.Team == standing.Team && x.TeamStandingGamesId == standingId); //if we find the team update it if (dbStanding != null) { dbStanding.Rank = strToIntRank; dbStanding.Games = standing.Games.ToByte(); dbStanding.Wins = standing.Win.ToByte(); dbStanding.Lost = standing.Lost.ToByte(); dbStanding.Pts = standing.Pts.ToByte(); dbStanding.Papf = standing.PaPf; dbStanding.Home = standing.Home; dbStanding.Road = standing.Road; dbStanding.ScoreHome = standing.ScoreHome; dbStanding.ScoreRoad = standing.ScoreRoad; dbStanding.Last5 = standing.Last5; dbStanding.PlusMinusField = standing.PlusMinusField; } //else create new teamStanding else { var newTeamStnading = new TeamStanding { Team = standing.Team, Rank = strToIntRank, Games = standing.Games.ToByte(), Wins = standing.Win.ToByte(), Lost = standing.Lost.ToByte(), Pts = standing.Pts.ToByte(), Papf = standing.PaPf, Home = standing.Home, Road = standing.Road, ScoreHome = standing.ScoreHome, ScoreRoad = standing.ScoreRoad, Last5 = standing.Last5, TeamStandingGamesId = standingId, PlusMinusField = standing.PlusMinusField }; db.TeamStandings.Add(newTeamStnading); } } try { Save(); } catch (DbEntityValidationException e) { } catch (Exception) { throw; } }