예제 #1
0
        public List <StreakRecord> GetData()
        {
            var allStreaks = new List <List <Game> >();

            foreach (var team in _leagueData.Teams)
            {
                var t            = team;
                var orderedGames = team.Games.GroupBy(g => g.Week.Season).OrderBy(g => g.Key.Year).SelectMany(g => g).Where(g => g.Week.IsRegular()).ToList();
                var teamStreaks  = StreakHelper.GetAllStreaks(orderedGames, g => g.GetTeamScore(t) >= 1000).ToList();
                allStreaks.AddRange(teamStreaks);
            }

            List <StreakRecord> results = new List <StreakRecord>();

            var topStreaks = allStreaks.OrderByDescending(s => s.Count).Take(_count);

            foreach (var streak in topStreaks)
            {
                var team = streak.First().Home.Team;
                if (!streak.TrueForAll(g => g.Away.Team == team || g.Home.Team == team))
                {
                    team = streak.First().Away.Team;
                    if (!streak.TrueForAll(g => g.Away.Team == team || g.Home.Team == team))
                    {
                        throw new Exception();
                    }
                }

                var r = new StreakRecord()
                {
                    Value = streak.Count,
                    Team  = team,
                    From  = streak.First().Week,
                    To    = streak.Last().Week,
                };
                results.Add(r);
            }


            return(results);
        }
예제 #2
0
        public List <StreakRecord> GetData()
        {
            var allStreaks = new List <List <Game> >();

            foreach (var team in _leagueData.Teams)
            {
                var t            = team;
                var orderedGames = team.Games.GroupBy(g => g.Week.Season).OrderBy(g => g.Key.Year).SelectMany(g => g).Where(g => g.Week.IsRegular()).ToList();
                var teamStreaks  = StreakHelper.GetAllStreaks(orderedGames, g => g.IsWinningTeam(t)).ToList();
                allStreaks.AddRange(teamStreaks);
            }

            var topStreaks = allStreaks.OrderByDescending(s => s.Count).Take(_count);

            return(topStreaks.Select(s => new StreakRecord()
            {
                Value = s.Count,
                Team = s.First().GetWinningTeam(),
                From = s.First().Week,
                To = s.Last().Week,
            }).ToList());
        }