public void EvaluateTour(int headToHeadTourId) { var headToHeadTour = _context.HeadToHeadTours.Include(t => t.Matches).Single(t => t.HeadToHeadTourId == headToHeadTourId); var tourId = headToHeadTour.ParentTourId; var headToHeadMatches = headToHeadTour.Matches; //////////////////////////////////////////////////////////////////////////////////////////////// var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithPredictionsWithExperts() }; var tours = _context.GetLastTournamentTours(fetchStrategies); var tour = tours.Single(t => t.TourId == tourId); if (!tour.IsClosed) { throw new InvalidOperationException("Tour must be closed."); } var matches = tour.Matches; var predictionSumByExpert = GetExpertTourSums(matches); //////////////////////////////////////////////////////////////////////////////////////////////// foreach (var match in headToHeadMatches) { match.HomeGoals = (byte)predictionSumByExpert[match.HomeExpertId]; match.AwayGoals = (byte)predictionSumByExpert[match.AwayExpertId]; } _context.SaveChanges(); }
public IReadOnlyCollection <Match> GenerateMatchlist(int tournamentId, int tourId) { var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithHomeTeam(), new FetchToursWithMatchesWithAwayTeam() }; return(_context.GetLastTournamentTours(fetchStrategies).TourById(tourId).Matches.ToList()); }
//optimization! looks ugly // "0" for all tours public List <ExpertDto> GenerateExpertsInfo(int tourNumber = 0) { var results = new List <ExpertDto>(); if (tourNumber == 0) { var experts = _context.Experts.ToList(); experts.ForEach(e => results.Add(new ExpertDto(e.Nickname, e.Sum, e.Scores, e.Differences, e.Outcomes))); return(results); } var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithPredictionsWithExperts() }; var tours = _context.GetLastTournamentTours(fetchStrategies); var matches = tours.Single(t => t.TourNumber == tourNumber) .Matches; var predictions = matches .SelectMany(m => m.Predictions) .GroupBy(p => p.Expert) .ToList(); foreach (var epGroup in predictions) { var info = new ExpertDto { Nickname = epGroup.Key.Nickname }; foreach (var prediction in epGroup) { info.Sum += prediction.Sum; if (prediction.Score) { info.Scores++; } else if (prediction.Difference) { info.Differences++; } else if (prediction.Outcome) { info.Outcomes++; } } results.Add(info); } return(results.OrderByDescending(expert => expert.Sum).ToList()); }
public List <Team> GetLastTournamentTeams() { var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithHomeTeam(), new FetchToursWithMatchesWithAwayTeam() }; var firstTour = Queryable.First <Tour>(_context.GetLastTournamentTours(fetchStrategies)); if (firstTour.Matches.IsNullOrEmpty()) { return(Enumerable.ToList <Team>(_context.Teams)); } var teams = new List <Team>(); firstTour.Matches.ForEach(m => { teams.Add(m.HomeTeam); teams.Add(m.AwayTeam); }); return(teams); }
public List <Tour> GetLastTournamentTours() { var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchTours() }; return(_context.GetLastTournamentTours(fetchStrategies).ToList()); }