private string GetFullTeamTitle(int TeamId, List <Match> Map, ExpectedLineUp expectedLinup, int secondaryTeamId) { var rankList = new List <Tuple <double, string> >(); var FTRankList = Map.GroupBy(p => p.T1FTR).ToList(); var returnSymbol = "<br>";//"
"; var Title = ""; // Group by FTRating. foreach (var n in FTRankList) { var TotalWins = n.Count(p => p.ResultT1 > p.ResultT2); var TotalLosses = n.Count(p => p.ResultT2 > p.ResultT1); var WinPercent = Math.Round(n.Count(p => p.ResultT1 > p.ResultT2) / (double)n.Count() * 100, 1); var AverageWinRounds = Math.Round(n.Sum(p => p.ResultT1) / (double)n.Count(), 1); var AverageLossRounds = Math.Round(n.Sum(p => p.ResultT2) / (double)n.Count(), 1); rankList.Add(new Tuple <double, string>(n.Key, $"{TotalWins} / {TotalLosses} {WinPercent}% av.r: {AverageWinRounds} / {AverageLossRounds}")); } // Order the list by FTRating var orderedList = rankList.OrderByDescending(p => p.Item1).ToList(); // Create the title "hover" list foreach (Tuple <double, string> tup in orderedList) { Title += string.IsNullOrEmpty(Title) ? "<b>Full Team Rating:</b><br> " : " " + returnSymbol + " "; Title += tup.Item1 + " - " + tup.Item2; } return(Title); }
public async Task <TeamStatisticPeriodModel> GetTeamPeriodStatistics(int TeamId, List <string> PeriodSelection, ExpectedLineUp expectedLinup, int secondaryTeamId, bool NoCache, int MinFullTeamRanking, string teamRank, string logo, int?ignoreTeamId = null) { var result = new TeamStatisticPeriodModel(); result.TeamId = TeamId; result.TeamName = GetTeamName(TeamId); result.TeamDifficultyRating = _program.GetRankingValueForTeam(TeamId, DateTime.Now); result.TeamRank = teamRank; result.Logo = logo; foreach (var period in PeriodSelection) { await Task.Run(() => result.TeamStatistics.Add(GetTeamPeriodStatistics(TeamId, (PeriodEnum)int.Parse(period), expectedLinup, secondaryTeamId, NoCache, MinFullTeamRanking, ignoreTeamId))).ConfigureAwait(false); } return(result); }
public List <MapStatisticModel> CalculateResults(int TeamId, List <Match> fixedMatches, ExpectedLineUp expectedLinup, int secondaryTeamId, int MinFullTeamRanking) { if (MinFullTeamRanking > 0) { if (MinFullTeamRanking == 5) { fixedMatches = fixedMatches.Where(p => expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()).ToList(); } else if (MinFullTeamRanking == 4) { fixedMatches = fixedMatches.Where(p => (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any())).ToList(); } } // Group list by maps. var groupedbymaps = fixedMatches.GroupBy(k => k.Map, StringComparer.InvariantCultureIgnoreCase).ToList(); var result = groupedbymaps.Select(n => new MapStatisticModel { Map = n.Key, TitleMapMatches = GetTitleMapMatches(fixedMatches.Where(p => p.Map == n.Key).OrderByDescending(p => p.Date).ToList()), TotalMatches = n.Count(), TotalWins = n.Count(p => p.ResultT1 > p.ResultT2), TotalLosses = n.Count(p => p.ResultT2 > p.ResultT1), WinPercent = Math.Round(n.Count(p => p.ResultT1 > p.ResultT2) / (double)n.Count() * 100, 1), // *** Get Average Win rounds *** AverageWinRounds = Math.Round(n.Sum(p => p.ResultT1) / (double)n.Count(), 1), // *** Get Average Loss rounds *** AverageLossRounds = Math.Round(n.Sum(p => p.ResultT2) / (double)n.Count(), 1), // *** Get Average Win rounds when team has won *** AverageWinRoundsWhenWin = Math.Round(n.Where(p => p.ResultT1 > p.ResultT2) // Where team won .Sum(p => p.ResultT1) / // Sum team rounds (double)n.Count(p => p.ResultT1 > p.ResultT2), 1), // Divided total games we won // *** Get Average Loss rounds when team has won *** AverageLossRoundsWhenWin = Math.Round(n.Where(p => p.ResultT1 > p.ResultT2) // Where team won .Sum(p => p.ResultT2) / // Sum opponents rounds (double)n.Count(p => p.ResultT1 > p.ResultT2), 1), // Divided total games we won // *** Get Average Win rounds when team has lost *** AverageWinRoundsWhenLoss = Math.Round(n.Where(p => p.ResultT1 < p.ResultT2) // Where team lost .Sum(p => p.ResultT1) / // Sum team rounds (double)n.Count(p => p.ResultT1 < p.ResultT2), 1), // Divided total games we lost // *** Get Average Loss rounds when team has lost *** AverageLossRoundsWhenLoss = Math.Round(n.Where(p => p.ResultT1 < p.ResultT2) // Where team lost .Sum(p => p.ResultT2) / // Sum opponents rounds (double)n.Count(p => p.ResultT1 < p.ResultT2), 1), // Divided total games we lost DifficultyRating = Math.Round(n.Sum(p => p.Team2RankValue) / (double)n.Count(), 2), DiffTitleGroupBy = GetDiffTitleGroupBy(n.ToList()), FullTeamRanking = GetFullTeamPercent(TeamId, n.ToList(), expectedLinup, secondaryTeamId), FullTeamGroupBy = GetFullTeamTitle(TeamId, n.ToList(), expectedLinup, secondaryTeamId), FirstRound1HWinPercent = GetFirstRoundStats(TeamId, n.ToList(), true), FirstRound2HWinPercent = GetFirstRoundStats(TeamId, n.ToList(), false), BombExplosions = n.Sum(p => p.BombExplosions), //Math.Round(n.Sum(p => p.BombExplosions) / (double)n.Count(), 1), BombExplosionsWin35 = n.Count(p => p.BombExplosions > 3.5), BombExplosionsWin45 = n.Count(p => p.BombExplosions > 4.5), BombExplosionsWin55 = n.Count(p => p.BombExplosions > 5.5), BombExplosionsWin65 = n.Count(p => p.BombExplosions > 6.5), //Math.Round((n.Count(p => p.BombExplosions > 4.5) / (double)n.Count()) * 100, 1), BombDefuses = n.Sum(p => p.BombDefuses), //Math.Round(n.Sum(p => p.BombDefuses) / (double)n.Count(), 1), BombDefusesWin25 = n.Count(p => p.BombDefuses > 2.5), BombDefusesWin35 = n.Count(p => p.BombDefuses > 3.5), BombDefusesWin45 = n.Count(p => p.BombDefuses > 4.5), //Math.Round((n.Count(p => p.BombDefuses > 3.5) / (double)n.Count()) * 100, 1),, BombDefuses1stHalf = n.Sum(p => p.BombDefuses1stHalf), //Math.Round(n.Sum(p => p.BombDefuses) / (double)n.Count(), 1), BombDefuses1stHalfWin15 = n.Count(p => p.BombDefuses1stHalf > 1.5), BombDefuses1stHalfWin25 = n.Count(p => p.BombDefuses1stHalf > 2.5), TimeOut = n.Sum(p => p.TimeOut), //Math.Round(n.Sum(p => p.TimeOut) / (double)n.Count(), 1), TimeOutWin05 = n.Count(p => p.TimeOut > 0.5), TimeOutWin15 = n.Count(p => p.TimeOut > 1.5), //Math.Round((n.Count(p => p.TimeOut > 0.5) / (double)n.Count()) * 100, 1), GrenadeKill = n.Sum(p => p.GrenadeKill), //Math.Round(n.Sum(p => p.GrenadeKill) / (double)n.Count(), 1), GrenadeKillWin = n.Count(p => p.GrenadeKill > 0.5), //Math.Round((n.Count(p => p.GrenadeKill > 0.5) / (double)n.Count()) * 100, 1), MolotovKill = n.Sum(p => p.MolotovKill), //Math.Round(n.Sum(p => p.MolotovKill) / (double)n.Count(), 1), MolotovKillWin = n.Count(p => p.MolotovKill > 0.5), //Math.Round((n.Count(p => p.MolotovKill > 0.5) / (double)n.Count()) * 100, 1), ZuesKill = n.Sum(p => p.ZuesKill), //Math.Round(n.Sum(p => p.ZuesKill) / (double)n.Count(), 1), ZuesKillWin = n.Count(p => p.ZuesKill > 0.5), //Math.Round((n.Count(p => p.ZuesKill > 0.5) / (double)n.Count()) * 100, 1), KnifeKill = n.Sum(p => p.KnifeKill), //Math.Round(n.Sum(p => p.KnifeKill) / (double)n.Count(), 1), KnifeKillWin = n.Count(p => p.KnifeKill > 0.5), //Math.Round((n.Count(p => p.KnifeKill > 0.5) / (double)n.Count()) * 100, 1) Round1BombWin = n.Count(p => p.round1BombExplosion == true), Round1DefuseWin = n.Count(p => p.round1Defuse == true), Round1TimeoutWin = n.Count(p => p.round1Timout == true), Round1KillWin = n.Count(p => p.round1KillWin == true), Round16BombWin = n.Count(p => p.round16BombExplosion == true), Round16DefuseWin = n.Count(p => p.round16Defuse == true), Round16TimeoutWin = n.Count(p => p.round16Timout == true), Round16KillWin = n.Count(p => p.round16KillWin == true) }).OrderByDescending(n => n.WinPercent).ToList(); return(result); }
private double GetFullTeamPercent(int TeamId, List <Match> Map, ExpectedLineUp expectedLinup, int secondaryTeamId) { double Accumulator = 0; double AvFTR = 0; // Calculate how many of expectedLinup played each match. foreach (var match in Map) { int FTRank = 0; if ((match.Team1Id == TeamId || match.Team1Id == secondaryTeamId) && expectedLinup != null) { if (secondaryTeamId > 0) { if (expectedLinup.Players.Where(p => (p.TeamID == TeamId || p.TeamID == secondaryTeamId) && p.PlayerId == match.T1Player1Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => (p.TeamID == TeamId || p.TeamID == secondaryTeamId) && p.PlayerId == match.T1Player2Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => (p.TeamID == TeamId || p.TeamID == secondaryTeamId) && p.PlayerId == match.T1Player3Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => (p.TeamID == TeamId || p.TeamID == secondaryTeamId) && p.PlayerId == match.T1Player4Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => (p.TeamID == TeamId || p.TeamID == secondaryTeamId) && p.PlayerId == match.T1Player5Id).Any()) { FTRank += 1; } } else { if (expectedLinup.Players.Where(p => p.TeamID == TeamId && p.PlayerId == match.T1Player1Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => p.TeamID == TeamId && p.PlayerId == match.T1Player2Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => p.TeamID == TeamId && p.PlayerId == match.T1Player3Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => p.TeamID == TeamId && p.PlayerId == match.T1Player4Id).Any()) { FTRank += 1; } if (expectedLinup.Players.Where(p => p.TeamID == TeamId && p.PlayerId == match.T1Player5Id).Any()) { FTRank += 1; } } // How many played this map match.T1FTR = FTRank; // Add to Accumulator for total average. Accumulator += FTRank; } } // Av. played if (Accumulator > 0) { AvFTR = Accumulator / Map.Count; } return(AvFTR); }
public List <MapStatisticModel> GetMapStatistics(int TeamId, DateTime dFrom, DateTime dTo, ExpectedLineUp expectedLinup, int secondaryTeamId, bool NoCache, int MinFullTeamRanking, int?ignoreTeamId = null) { var result = new List <MapStatisticModel>(); List <Match> fixedMatches = null; // Create Cachekey from parameters var CACHEKEY = "cacheKey:TeamId=" + TeamId + "-DateFrom=" + dFrom.Date.ToString() + "-dTo=" + dTo.Date.ToString(); // If we have object in cache, return it if (NoCache && Cache.Exists(CACHEKEY)) { fixedMatches = (List <Match>)Cache.Get(CACHEKEY); } else { List <Match> matches = new List <Match>(); if (ignoreTeamId.HasValue) { matches = _db.Match .Where(p => (p.Team1Id == TeamId || p.Team2Id == TeamId) && !(p.Team1Id == ignoreTeamId.Value || p.Team2Id == ignoreTeamId.Value) && (p.Date >= dFrom.Date && p.Date <= dTo.Date)).ToList(); } else { matches = _db.Match .Where(p => (p.Team1Id == TeamId || p.Team2Id == TeamId) && (p.Date >= dFrom.Date && p.Date <= dTo.Date)).ToList(); } // Fix matches so that "our" team is always Team1, to simplify later query fixedMatches = FixTeamMatches(matches, TeamId); if (secondaryTeamId > 0) { // Get matches for secondaryTeamId var secondaryMatches = _db.Match .Where(p => (p.Team1Id == secondaryTeamId || p.Team2Id == secondaryTeamId) && (p.Date >= dFrom.Date && p.Date <= dTo.Date)).ToList(); // Fix matches for secondaryMatches var fixedsecondaryMatches = FixTeamMatches(secondaryMatches, secondaryTeamId); // Add matches from secondaryTeamId to fixedMatches fixedMatches.AddRange(fixedsecondaryMatches); } } if (!string.IsNullOrEmpty(CACHEKEY)) { if (!Cache.Exists(CACHEKEY)) { int storeTime = 1000 * 3600 * 24 * 2; // store 2 days Cache.Store(CACHEKEY, fixedMatches, storeTime); } else { Cache.Update(CACHEKEY, fixedMatches); } } result = CalculateResults(TeamId, fixedMatches, expectedLinup, secondaryTeamId, MinFullTeamRanking); return(result); }
public TeamStatisticModel GetTeamPeriodStatistics(int TeamId, PeriodEnum period, ExpectedLineUp expectedLinup, int secondaryTeamId, bool NoCache, int MinFullTeamRanking, int?ignoreTeamId = null) { var result = new TeamStatisticModel(); var dTo = DateTime.Now; var dFrom = new DateTime(); var mapList = new List <string> { "nuke", "overpass", "cobblestone", "train", "inferno", "mirage", "cache", "vertigo", "ancient" }; switch (period) { case PeriodEnum.ThreeMonths: dFrom = dTo.AddMonths(-3); result.Period = "3 Months"; break; case PeriodEnum.SixMonths: dFrom = dTo.AddMonths(-6); result.Period = "6 Months"; break; case PeriodEnum.Year: dFrom = dTo.AddYears(-1); result.Period = "Year"; break; } result.Maps = GetMapStatistics(TeamId, dFrom, dTo, expectedLinup, secondaryTeamId, NoCache, MinFullTeamRanking, ignoreTeamId); foreach (var map in mapList) { if (!result.Maps.Where(p => p.Map.ToLower() == map).Any()) { result.Maps.Add(new MapStatisticModel { Map = map, FirstRound1HWinPercent = new Tuple <double, string>(0, ""), FirstRound2HWinPercent = new Tuple <double, string>(0, "") }); } } return(result); }
public List <MapStatisticModel> CalculateResults(int TeamId, List <Match> fixedMatches, ExpectedLineUp expectedLinup, int secondaryTeamId, int MinFullTeamRanking) { if (MinFullTeamRanking > 0) { if (MinFullTeamRanking == 5) { fixedMatches = fixedMatches.Where(p => expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()).ToList(); } else if (MinFullTeamRanking == 4) { fixedMatches = fixedMatches.Where(p => (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player1Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any()) || (expectedLinup.Players.Where(x => p.T1Player2Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player3Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player4Id == x.PlayerId).Any() && expectedLinup.Players.Where(x => p.T1Player5Id == x.PlayerId).Any())).ToList(); } } // Group list by maps. var groupedbymaps = fixedMatches.GroupBy(k => k.Map, StringComparer.InvariantCultureIgnoreCase).ToList(); var result = groupedbymaps.Select(n => new MapStatisticModel { Map = n.Key, TitleMapMatches = GetTitleMapMatches(fixedMatches.Where(p => p.Map == n.Key).OrderByDescending(p => p.Date).ToList()), TotalWins = n.Count(p => p.ResultT1 > p.ResultT2), TotalLosses = n.Count(p => p.ResultT2 > p.ResultT1), WinPercent = Math.Round(n.Count(p => p.ResultT1 > p.ResultT2) / (double)n.Count() * 100, 1), // *** Get Average Win rounds *** AverageWinRounds = Math.Round(n.Sum(p => p.ResultT1) / (double)n.Count(), 1), // *** Get Average Loss rounds *** AverageLossRounds = Math.Round(n.Sum(p => p.ResultT2) / (double)n.Count(), 1), // *** Get Average Win rounds when team has won *** AverageWinRoundsWhenWin = Math.Round(n.Where(p => p.ResultT1 > p.ResultT2) // Where team won .Sum(p => p.ResultT1) / // Sum team rounds (double)n.Count(p => p.ResultT1 > p.ResultT2), 1), // Divided total games we won // *** Get Average Loss rounds when team has won *** AverageLossRoundsWhenWin = Math.Round(n.Where(p => p.ResultT1 > p.ResultT2) // Where team won .Sum(p => p.ResultT2) / // Sum opponents rounds (double)n.Count(p => p.ResultT1 > p.ResultT2), 1), // Divided total games we won // *** Get Average Win rounds when team has lost *** AverageWinRoundsWhenLoss = Math.Round(n.Where(p => p.ResultT1 < p.ResultT2) // Where team lost .Sum(p => p.ResultT1) / // Sum team rounds (double)n.Count(p => p.ResultT1 < p.ResultT2), 1), // Divided total games we lost // *** Get Average Loss rounds when team has lost *** AverageLossRoundsWhenLoss = Math.Round(n.Where(p => p.ResultT1 < p.ResultT2) // Where team lost .Sum(p => p.ResultT2) / // Sum opponents rounds (double)n.Count(p => p.ResultT1 < p.ResultT2), 1), // Divided total games we lost DifficultyRating = Math.Round(n.Sum(p => p.Team2RankValue) / (double)n.Count(), 2), DiffTitleGroupBy = GetDiffTitleGroupBy(n.ToList()), FullTeamRanking = GetFullTeamPercent(TeamId, n.ToList(), expectedLinup, secondaryTeamId), FullTeamGroupBy = GetFullTeamTitle(TeamId, n.ToList(), expectedLinup, secondaryTeamId), FirstRound1HWinPercent = GetFirstRoundStats(TeamId, n.ToList(), true), FirstRound2HWinPercent = GetFirstRoundStats(TeamId, n.ToList(), false) }).OrderByDescending(n => n.WinPercent).ToList(); return(result); }
public ExpectedLineUp GetTeamLineup(string matchUrls, int team1Id = 0, int team2ID = 0) { try { var expectedLineUp = new ExpectedLineUp(); if (expectedLineUp.Players == null) { expectedLineUp.Players = new List <Player>(); } //var teamIDs = GetTeamIdsFromUrl(); var urlHtml = $"[@class='//match-page-link button']"; var url = matchUrls; var matchHtml = HWeb.Load(matchUrls); var span1Name = new HtmlNodeCollection(HtmlNode.CreateNode("")); var span2Name = new HtmlNodeCollection(HtmlNode.CreateNode("")); Team1Rank = GetTeamRank(team1Id, Team1Name); try { // Get Event name string eventspan = $"//*[@class='event text-ellipsis']//@href"; var eventnode = matchHtml.DocumentNode.SelectNodes(eventspan); expectedLineUp.EventName = eventnode.Count > 0 ? eventnode[0].InnerHtml : ""; // Get MatchId expectedLineUp.MatchId = GetTeamIdFromUrl(url); // Get Start var startUnix = matchHtml.DocumentNode.Descendants("div") // All <a links .Where(d => d.Attributes.Contains("class") && // contains href attribute d.Attributes["class"].Value.Contains("date") && // with this value d.Attributes.Contains("data-unix")) // contains href attribute .Select(p => p.Attributes["data-unix"].Value).FirstOrDefault(); // return InnerHtml DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); double dUnix; if (!string.IsNullOrEmpty(startUnix) && double.TryParse(startUnix, out dUnix)) { expectedLineUp.Start = dtDateTime.AddMilliseconds(dUnix).ToLocalTime(); } string span1; //var team1IdHtmlString = $"//*[@class='team1-gradient']"; span1 = $"//*[@class='lineup standard-box']"; span1Name = matchHtml.DocumentNode.SelectNodes(span1); /*Get players from lineup*/ var counter = 0; foreach (var item in span1Name) { /*Players line up box on match overview site*/ var players = item.SelectNodes("//*[@class='players']/*[@class='table']//*[@class='player']//@href"); foreach (var player in players) { var names = player.InnerText.Trim(); if (names != "") { var ids = GetPlayerID(player.Attributes[0].Value); var pl = new Player(); pl.PlayerId = ids; pl.PlayerName = names; if (counter <= 4) { if (team1Id > 0) { //teamID that comes from runcompare in home controller pl.TeamID = team1Id; } else { pl.TeamID = Team1ID; } } else { if (team1Id > 0) { //teamID that comes from runcompare in home controller pl.TeamID = team2ID; } else { pl.TeamID = Team2ID; } } Team2Rank = GetTeamRank(team2ID, Team2Name); var plexists = expectedLineUp.Players.Any(x => x.PlayerId == ids); if (!plexists) { expectedLineUp.Players.Add(pl); } counter++; } } } } catch (Exception ex) { var nothing = ex; } return(expectedLineUp); } catch (Exception) { /*Logga niður villur*/ //throw; // return empty list, to avoid crash return(new ExpectedLineUp()); } }
public ExpectedLineUp GetTeamLineupFromDetails(string matchUrls, int team1Id = 0, int team2ID = 0) { try { var expectedLineUp = new ExpectedLineUp(); if (expectedLineUp.Players == null) { expectedLineUp.Players = new List <Player>(); } //var teamIDs = GetTeamIdsFromUrl(); var urlHtml = $"[@class='//match-page-link button']"; var url = matchUrls; var MoreInfo = HWeb.Load(url); var span1Name = new HtmlNodeCollection(HtmlNode.CreateNode("")); var span2Name = new HtmlNodeCollection(HtmlNode.CreateNode("")); try { int leftTeamID = 0; int rightTeamID = 0; string sLeftTeamId = ""; string sRightTeamId = ""; string span1; //var team1IdHtmlString = $"//*[@class='team1-gradient']"; span1 = $"//*[@class='lineup standard-box']"; var spantest = "//*[@class='match-info-box-con']"; //span1Name = matchHtml.DocumentNode.SelectNodes(span1); var lineup = MoreInfo.DocumentNode.SelectNodes(spantest); var href = lineup[0].ChildNodes[13].OuterHtml; var externalLink = GetMatchUrlForDetails(href); var externalUrl = "http://www.hltv.org" + externalLink; MoreInfo = HWeb.Load(externalUrl); //*********** GET IDs FROM PAGE *********** var LeftNode = MoreInfo.DocumentNode.SelectSingleNode("//div[@class='team1-gradient']/a"); // divs of class="team-left" if (LeftNode.Attributes.Contains("href")) { sLeftTeamId = LeftNode.Attributes["href"].Value; } var RightNode = MoreInfo.DocumentNode.SelectSingleNode("//div[@class='team2-gradient']/a"); // divs of class="team-left" if (RightNode.Attributes.Contains("href")) { sRightTeamId = RightNode.Attributes["href"].Value; } if (!string.IsNullOrEmpty(sLeftTeamId)) { leftTeamID = GetTeamIDFromUrl(sLeftTeamId); } if (!string.IsNullOrEmpty(sRightTeamId)) { rightTeamID = GetTeamIDFromUrl(sRightTeamId); } //***************************************** span1Name = MoreInfo.DocumentNode.SelectNodes(span1); /*Get players from lineup*/ var counter = 0; foreach (var item in span1Name) { //td[@class="plaintext"] var players = item.SelectNodes("//*[@class='players']/*[@class='table']//*[@class='player']//@href"); foreach (var player in players) { var names = player.InnerText.Trim(); if (names != "") { var ids = GetPlayerID(player.Attributes[0].Value); var pl = new Player(); pl.PlayerId = ids; pl.PlayerName = names; if (counter <= 4) { if (leftTeamID > 0) { pl.TeamID = leftTeamID; } else { pl.TeamID = Team1ID; } } else { if (rightTeamID > 0) { pl.TeamID = rightTeamID; } else { pl.TeamID = Team2ID; } } var plexists = expectedLineUp.Players.Any(x => x.PlayerId == ids); if (!plexists) { expectedLineUp.Players.Add(pl); } counter++; } } } } catch (Exception ex) { var nothing = ex; } return(expectedLineUp); } catch (Exception) { /*Logga niður villur*/ //throw; // return empty list, to avoid crash return(new ExpectedLineUp()); } }