GameByTeam GetGameInfo(string html, Game game, string teamId) { var info = new GameByTeam(); info.Id = game.Id.ToString(); info.TeamId = teamId; info.TeamName = (Teams.ContainsKey(teamId)) ? Teams [teamId] : DeletedTeamName; info.GameName = game.Name; return(info); }
void ReadStatisticsFor(string team, string _id) { try { if (string.IsNullOrEmpty(team)) { team = Teams [_id]; } var result = string.Empty; List <GameByTeam> games; if (!string.IsNullOrEmpty(team)) { games = GamesByTeam.FindAll(item => item.TeamName == team); } else { games = GamesByTeam.FindAll(item => item.TeamId == _id); } result += "\n"; result += "\n"; result += $"Команда {team}"; result += "\n"; result += "\n"; if (!games.Any()) { result = "Команда не сыграла ни одной игры."; Console.WriteLine(result); return; } var game = Games.First(item => item.Id.ToString() == games.First().Id); result += $"Первая игра {game.Date} {game.Name}."; result += "\n"; result += "\n"; var seasonNumbers = games.Select(item => item.Season).Distinct().ToList(); result += $"Участвовала в {seasonNumbers.Count} сезонах ({string.Join (", ", seasonNumbers)})"; result += "\n"; result += "\n"; result += $"Участвовала в {games.Count} рейтинговых играх"; var won = games.Where(item => item.Place == 1).ToList(); if (won.Count() > 0) { result += "\n"; result += "\n"; result += $"Выиграно игр {won.Count} "; var maxGap = -1; GameByTeam maxGapGame = null; foreach (var wongame in won) { result += "\n"; var diff = wongame.SecondCommonTime - wongame.CommonTime; if (diff > maxGap) { maxGap = diff; maxGapGame = wongame; } var gameInfo = Games.First(item => item.Id.ToString() == wongame.Id); result += $" {gameInfo.Date} {gameInfo.Name} (сезон {wongame.Season})"; } result += "\n"; result += "\n"; if (maxGapGame != null) { var maxGapGameInfo = Games.First(item => item.Id.ToString() == maxGapGame.Id); result += $"Максимальный отрыв при победе {TimeSpan.FromSeconds(maxGap)} игра {maxGapGameInfo.Date} {maxGapGame.GameName} "; } } else { result += "\n"; result += "\n"; var timeToLead = games.Select(item => item.TimeToLeader).Min(); var gameToLead = games.Find(item => item.TimeToLeader == timeToLead); var ttt = Games.First(item => item.Id.ToString() == gameToLead.Id); result += $"Ближе всего к победе : {TimeSpan.FromSeconds (timeToLead)}, {ttt.Date} {gameToLead.GameName}"; } result += "\n"; result += "\n"; result += "Какие места занимала команда за свою историю?"; var placesDirty = games.Select(item => item.Place).ToList(); var placesClean = placesDirty.Distinct().ToList(); placesClean.Sort(); for (var i = 1; i < 1000; i++) { result += "\n"; result += $" {i} место - {placesDirty.Count (item => item == i)} шт"; if (i >= placesClean.Last()) { break; } } int maxAbsoluteGapInBestTime = 0; string maxAbsoluteGapInBestTimeGameId = string.Empty; double maxDependendGapInBestTime = 0; string maxDependendGapInBestTimeGameId = string.Empty; var ids = games.Select(item => item.Id).ToList(); var gameInfos = GamesByTeam.FindAll(item => ids.Contains(item.Id)); var bestPlacesGameIds = new List <string> (); foreach (var g in gameInfos) { for (var ind = 0; ind < g.LevelTimes.Count; ind++) { if (g.BestTimes == null) { break; } if (g.LevelTimes [ind] == g.BestTimes [ind]) { if (g.TeamName == team) { bestPlacesGameIds.Add(g.Id); var absoluteDiffBetweenFirstAndSecondTime = g.SecondBestTimes[ind] - g.BestTimes[ind]; if (absoluteDiffBetweenFirstAndSecondTime > maxAbsoluteGapInBestTime) { maxAbsoluteGapInBestTime = absoluteDiffBetweenFirstAndSecondTime; maxAbsoluteGapInBestTimeGameId = g.Id; } var dependantDiffBetweenFirstAndSecondTime = (g.SecondBestTimes[ind] - g.BestTimes[ind]) / ((double)g.BestTimes[ind]); if (dependantDiffBetweenFirstAndSecondTime > maxDependendGapInBestTime) { maxDependendGapInBestTime = dependantDiffBetweenFirstAndSecondTime; maxDependendGapInBestTimeGameId = g.Id; } } } } } if (bestPlacesGameIds.Count > 0) { result += "\n"; result += "\n"; result += $"Лучшие времена: {bestPlacesGameIds.Count} шт"; var bestPlacesClean = bestPlacesGameIds.Distinct().ToList(); Dictionary <int, List <string> > bestpl = new Dictionary <int, List <string> > (); List <int> bp = new List <int> (); foreach (var id in bestPlacesClean) { var count = bestPlacesGameIds.Count(item => item == id); bp.Add(count); if (bestpl.ContainsKey(count)) { bestpl [count].Add(id); } else { bestpl.Add(count, new List <string> { id }); } } bp.Sort(); var max = bp.Max(); if (max == 8) { Console.WriteLine(1); } for (var i = max; i > 0; i--) { result += "\n"; var count = bp.Count(item => item == i); result += $" {i} лучших времен в { count} играх"; if (i <= bp.First()) { break; } } result += "\n"; result += "\n"; result += $"Максимум лучших времен ({max}) в играх :"; var maxBPGameIds = bestpl.Where(item => item.Key == max).FirstOrDefault().Value; foreach (var gMaxBP in maxBPGameIds) { var g = Games.Find(item => gMaxBP == item.Id.ToString()); result += "\n"; result += $"{g.Date} {g.Name}"; } } if (!string.IsNullOrEmpty(maxAbsoluteGapInBestTimeGameId)) { result += "\n"; result += "\n"; var minutes = maxAbsoluteGapInBestTime / 60; var time = $"{minutes}:{maxAbsoluteGapInBestTime - minutes * 60}"; var g = Games.Find(item => maxAbsoluteGapInBestTimeGameId == item.Id.ToString()); result += $"Максимальный абсолютный отрыв в лучшем времени {time} до ближайшего соперника в игре {g.Date} {g.Name}"; result += "\n"; result += "\n"; g = Games.Find(item => maxDependendGapInBestTimeGameId == item.Id.ToString()); result += $"Максимальный относительный отрыв в лучшем времени:\n в {maxDependendGapInBestTime + 1} раз(а) быстрее ближайшего соперника в игре {g.Date} {g.Name}"; } var minLevelTime = 1000000000; GameByTeam minLevelTimeGame = new GameByTeam(); var minTime = 10000000000; GameByTeam minTimeGame = new GameByTeam(); foreach (var ga in games) { var newMin = ga.LevelTimes.Min((arg) => arg); if (newMin < minLevelTime) { minLevelTime = newMin; minLevelTimeGame = ga; } if (ga.CommonTime < minTime) { minTime = ga.CommonTime; minTimeGame = ga; } } result += "\n"; result += "\n"; var lll = Games.First(item => item.Id.ToString() == minLevelTimeGame.Id); result += $"Самый быстрый быстрый уровень за всю историю: {TimeSpan.FromSeconds (minLevelTime)}, {lll.Date} {minLevelTimeGame.GameName}"; result += "\n"; result += "\n"; lll = Games.First(item => item.Id.ToString() == minTimeGame.Id); result += $"Самая быстрая игра: {TimeSpan.FromSeconds (minTime)}, {lll.Date} {minTimeGame.GameName}"; Console.WriteLine(result); } catch (Exception e) { Console.WriteLine($"!!!!!! {team} {_id}"); } }