private CompetitionStandingDto LoadSingleKoStandings(FinalDayCompetition competition) { var matches = Db.Select(Db.From <MatchView>().Where(x => x.FinalDayCompetitionId == competition.Id).OrderBy(x => x.CupRound).ThenBy(x => x.RoundOrder)).ToList(); var dtos = matches.ConvertAll(s => s.ConvertTo <ExtendedMatchDto>()); return(new CompetitionStandingDto { CompetitionId = competition.Id, CompetitionName = competition.Name, CompetitionMode = competition.CompetitionMode, CompetitionState = competition.State, SingleKoMatches = dtos }); }
private FinalDayCompetitionProgressDto GetProgressForCompetition(FinalDayCompetition finalDayCompetition) { var competitionMode = CompetitionModeFactory.GetCompetitionMode(Db, finalDayCompetition.CompetitionMode); var progress = new FinalDayCompetitionProgressDto { CompetitionState = finalDayCompetition.State, CompetitionName = finalDayCompetition.Name, CompetitionId = finalDayCompetition.Id, CompetitionMode = finalDayCompetition.CompetitionMode, MatchesRunning = Db.Count(Db.From <MatchView>().Where(x => x.FinalDayCompetitionId == finalDayCompetition.Id && x.PlayDate != null && x.ResultDate == null)), }; var finishedMatches = Db.Select(Db.From <MatchView>().Where(x => x.FinalDayCompetitionId == finalDayCompetition.Id && (x.PlayDate != null && x.ResultDate != null || x.IsFreeTicket))); progress.MatchesPlayed = finishedMatches.Count; progress.MatchesOpen = competitionMode.GetNumberOfMatches(finalDayCompetition.Id) - progress.MatchesPlayed - progress.MatchesRunning; var playedMatches = finishedMatches.Where(x => !x.IsFreeTicket).ToList(); if (playedMatches.Any()) { progress.AverageMatchDuration = (int)TimeSpan .FromSeconds(playedMatches.Average(x => (x.ResultDate - x.PlayDate).Value.TotalSeconds)) .TotalMinutes; var numberOfTables = GetNumberOfTablesForFinalDayCompetition(finalDayCompetition.Id); if (numberOfTables != 0) { double totalDurationInMinutes = progress.AverageMatchDuration * progress.MatchesOpen / numberOfTables; var competitionDuration = TimeSpan.FromMinutes(totalDurationInMinutes); progress.ExpectedEnd = DateTime.Now + competitionDuration; } } return(progress); }
private CompetitionStandingDto LoadCrazyDypStandings(FinalDayCompetition competition) { var compDto = new CompetitionStandingDto { CompetitionId = competition.Id, CompetitionName = competition.Name, CompetitionMode = competition.CompetitionMode, CompetitionState = competition.State }; var sqlExpression = Db.From <CompetitionPlayerStanding>() .Where(x => x.FinalDayCompetitionId == competition.Id) .ThenBy(x => x.Rank); var standings = Db.LoadSelect(sqlExpression).ToList(); compDto.Players = standings.Select(x => x.ConvertTo <CompetitionPlayerStandingDto>()).ToList(); return(compDto); }
private CompetitionStandingDto LoadGroupStandings(FinalDayCompetition competition) { // TODO SSH: Refactor this -> Duplicated code just above... var compDto = new CompetitionStandingDto { CompetitionId = competition.Id, CompetitionName = competition.Name, CompetitionMode = competition.CompetitionMode, CompetitionState = competition.State }; var sqlExpression = Db.From <CompetitionTeamStandingView>() .Where(x => x.FinalDayCompetitionId == competition.Id) .OrderBy(x => x.GroupId) .ThenBy(x => x.Rank); var standings = Db.Select(sqlExpression).ToList(); compDto.Groups = MapToCompetitionTeamStandingDto(standings); return(compDto); }