Exemplo n.º 1
0
        public static int CalculateStatistic(IEnumerable <Tuple <int, int> > results, StatisticType statisticType, StatisticOrder statisticOrder)
        {
            var statistics = results.GroupBy(x => new { TeamID = x.Item1 })
                             .Select(x => new { x.Key.TeamID, Score = statisticType == StatisticType.Average ? x.Average(y => y.Item2) : x.Sum(y => y.Item2) });

            statistics = statisticOrder == StatisticOrder.Descending ? statistics.OrderByDescending(x => x.Score) : statistics.OrderBy(x => x.Score);

            return(statistics.FirstOrDefault().TeamID);
        }
Exemplo n.º 2
0
        public static async Task <Teams> GetStatistics(AppDbContext dbContext, Expression <Func <CompetitionsResultTable, int> > property, StatisticType statisticType, StatisticOrder statisticOrder)
        {
            var results = await GetAllResults(dbContext.Results, x => x.Won).ToListAsync();

            return(await dbContext.FindAsync <Teams>(CalculateStatistic(results, statisticType, statisticOrder)));
        }