public override bool Equals(object obj) { HeadToHeadKey h2 = obj as HeadToHeadKey; if (h2 == null) { return(false); } return(Id1 == h2.Id1 && Id2 == h2.Id2); }
private IEnumerable <int> sortDataWithSamePoints(List <SortInfo> dataWithSameWins, Dictionary <HeadToHeadKey, HeadToHeadInfo <SortInfo> > playerHeadToHeadInfos) { if (dataWithSameWins.Count == 1) { return(new List <int>() { dataWithSameWins.FirstOrDefault().ID }); } Dictionary <int, SortInfo> headToHeadInfo = new Dictionary <int, SortInfo>(); foreach (var data in dataWithSameWins) { headToHeadInfo.Add(data.ID, new SortInfo()); headToHeadInfo[data.ID].ID = data.ID; } // if none than we just return as was sorted in start bool hasHeadToHead = false; for (int i = 0; i < dataWithSameWins.Count - 1; i++) { for (int j = i + 1; j < dataWithSameWins.Count; j++) { var headToHeadKey = new HeadToHeadKey(dataWithSameWins[i].ID, dataWithSameWins[j].ID); if (playerHeadToHeadInfos.ContainsKey(headToHeadKey)) { hasHeadToHead = true; var headToHead = playerHeadToHeadInfos[headToHeadKey]; headToHeadInfo[headToHead.Info1.ID].Aggregate(headToHead.Info1); headToHeadInfo[headToHead.Info2.ID].Aggregate(headToHead.Info2); } } } if (!hasHeadToHead) { return(dataWithSameWins.Select(x => x.ID).ToList()); } var headToHeadTeamList = headToHeadInfo.Values.ToList(); headToHeadTeamList.Sort(); headToHeadTeamList.Reverse(); return(headToHeadTeamList.Select(x => x.ID).ToList()); }
protected void populateHeadToHead(DbMatchInfo <TableTennisMatchInfo> match) { // not played matches we dont want if (match.MatchInfo == null) { return; } HeadToHeadKey key = new HeadToHeadKey(match.CompetitorId1, match.CompetitorId2); if (!PlayerHeadToHeadInfos.ContainsKey(key)) { PlayerHeadToHeadInfos.Add(key, new HeadToHeadInfo <SortInfo>(match.CompetitorId1, match.CompetitorId2)); } PlayerHeadToHeadInfos[key].Info1.Update(match); PlayerHeadToHeadInfos[key].Info2.Update(match); }