public StandingsEntity GetSeasonStandings(SessionBaseEntity currentSession, LeagueDbContext dbContext, int maxRacesCount = -1) { StandingsEntity standings = new StandingsEntity() { ScoringTable = this, SessionId = (currentSession?.SessionId).GetValueOrDefault() }; if (currentSession == null) { return(standings); } if (maxRacesCount == -1) { maxRacesCount = Sessions.Count() - DropWeeks; } if (ScoringKind == ScoringKindEnum.Team) { return(GetSeasonTeamStandings(currentSession, dbContext, maxRacesCount)); } var allScoredResults = Scorings?.SelectMany(x => x.ScoredResults).ToList(); var previousScoredResults = allScoredResults.Where(x => x.Result.Session.Date < currentSession.Date).ToList(); var currentResult = currentSession.SessionResult; var currentScoredResult = allScoredResults.SingleOrDefault(x => x.Result.Session == currentSession); var previousScoredRows = previousScoredResults.SelectMany(x => x.FinalResults).ToList(); var previousStandingsRows = previousScoredRows .AggregateByDriver(maxRacesCount, true) .OrderBy(x => - x.TotalPoints) .ThenBy(x => x.PenaltyPoints) .ThenBy(x => - x.Wins); previousStandingsRows.Select((value, index) => new { index, value }).ToList().ForEach(x => x.value.Position = x.index + 1); allScoredResults = previousScoredResults.ToList(); allScoredResults.Add(currentScoredResult); var currentStandingsRows = allScoredResults .SelectMany(x => x.FinalResults) .AggregateByDriver(maxRacesCount, true) .OrderBy(x => - x.TotalPoints) .ThenBy(x => x.PenaltyPoints) .ThenBy(x => - x.Wins); currentStandingsRows.Select((value, index) => new { index, value }).ToList().ForEach(x => x.value.Position = x.index + 1); standings.StandingsRows = currentStandingsRows .Diff(previousStandingsRows) .OrderBy(x => - x.TotalPoints) .ThenBy(x => x.PenaltyPoints) .ThenBy(x => - x.Wins) .ToList(); standings.StandingsRows.ForEach(x => x.ScoringTable = this); standings.Calculate(); return(standings); }
public override void HandleTournamentStarted(Scorings _scoring, int _maxTimePerBoard, int _maxTimePerCard, string _tournamentName) { this.scoring = _scoring; this.maxTimePerBoard = _maxTimePerBoard; this.maxTimePerCard = _maxTimePerCard; this.tournamentName = _tournamentName; }
public List <SessionBaseEntity> GetAllSessions() { if (Scorings != null && Scorings.Count > 0) { return(Scorings.Where(x => x.Sessions != null).SelectMany(x => x.Sessions).ToList()); } return(Sessions.ToList()); }
public override void HandleTournamentStarted(Scorings scoring, int maxTimePerBoard, int maxTimePerCard, string tournamentName) { if (this.OnTournamentStarted != null) { this.Add(() => { this.OnTournamentStarted.Invoke(scoring, maxTimePerBoard, maxTimePerCard, tournamentName); }); } }
/// <summary> /// Only for the serializer /// </summary> public Tournament() { this.created = DateTime.Now; this._boards = new Collection <Board2>(); this.theParticipants = new List <Participant>(); this.scoringMethod = Scorings.scPairs; this.allowReplay = false; this.BidContest = false; this.AllowOvercalls = true; }
private List <KeyValuePair <ScoringEntity, float> > GetScoringFactors() { //Get floating point values from ';' separated string - default to 1 if value can not be parsed. var scoringFactorValues = ScoringFactors.Split(';').Select(x => float.TryParse(x, out float res) ? res : (float)1); //Create list of key value pairs { Scoring, ScoringFactor} - default to 1 if factor is not in List. var pairs = Scorings .Select((x, i) => new KeyValuePair <ScoringEntity, float>(x, (i < scoringFactorValues.Count()) ? scoringFactorValues.ElementAt(i) : (float)1)) .ToList(); return(pairs); }
public List <ScoringPoints> GetScoringEventsForPlayer(int playerId) { var db = new BoardSquaresRepository(); var list = db.Context.ScoringPoints.Where(s => s.PlayerID == playerId && s.RoundID == Round && s.Year == Year) .OrderByDescending(s => s.CreatedDate) .ToList(); var total = 0; foreach (var scoringPoint in list) { scoringPoint.RoundName = RoundsDictionary.First(r => r.Key == scoringPoint.RoundID.ToString()).Value; scoringPoint.ScoringEventName = Scorings.FirstOrDefault(k => k.Key == scoringPoint.ScoringEventID.ToString()).Value; total += scoringPoint.Points; } RoundTotal = total; return(list); }
public virtual void HandleTournamentStarted(Scorings scoring, int maxTimePerBoard, int maxTimePerCard, string tournamentName) { }
public override void Delete(LeagueDbContext dbContext) { Scorings?.Clear(); base.Delete(dbContext); }
public TeamStandingsEntity GetSeasonTeamStandings(SessionBaseEntity currentSession, LeagueDbContext dbContext, int maxRacesCount = -1) { if (currentSession == null) { return(null); } if (maxRacesCount == -1) { maxRacesCount = Sessions.Count() - maxRacesCount; } var allScoredResults = Scorings?.SelectMany(x => x.ScoredResults).OfType <ScoredTeamResultEntity>().ToList(); var previousScoredResults = allScoredResults.Where(x => x.Result.Session.Date < currentSession.Date).ToList(); foreach (var scoredTeamResult in previousScoredResults) { dbContext.Entry(scoredTeamResult).Collection(x => x.TeamResults).Query() .Include(x => x.Team) .Include(x => x.ScoredResultRows.Select(y => y.ScoredResult)).Load(); } var currentResult = currentSession.SessionResult; var currentScoredResult = allScoredResults.SingleOrDefault(x => x.Result.Session == currentSession); dbContext.Entry(currentScoredResult).Collection(x => x.TeamResults).Query() .Include(x => x.Team) .Include(x => x.ScoredResultRows.Select(y => y.ScoredResult)).Load(); TeamStandingsEntity teamStandings = new TeamStandingsEntity() { ScoringTable = this, SessionId = currentSession.SessionId }; var previousScoredRows = previousScoredResults.SelectMany(x => x.TeamResults).ToList(); IEnumerable <TeamStandingsRowEntity> previousStandingsRows; IEnumerable <TeamStandingsRowEntity> currentStandingsRows; if (DropRacesOption == DropRacesOption.PerDriverResults) { var allScoredDriverResults = Scorings?.SelectMany(x => x.GetResultsFromSource()).ToList(); var previousScoredDriverResults = allScoredDriverResults.Where(x => x.Result.Session.Date < currentSession.Date).ToList(); var currentDriverResult = currentSession.SessionResult; var currentScoredDriverResult = allScoredDriverResults.SingleOrDefault(x => x.Result.Session == currentSession); var previousScoredDriverRows = previousScoredDriverResults.SelectMany(x => x.FinalResults); previousStandingsRows = previousScoredRows.AggregateByTeam(maxRacesCount, true, DropRacesOption, ResultsPerRaceCount, previousScoredDriverRows) .OrderBy(x => - x.TotalPoints); allScoredDriverResults = previousScoredDriverResults.ToList(); allScoredDriverResults.Add(currentScoredDriverResult); allScoredResults = previousScoredResults.ToList(); allScoredResults.Add(currentScoredResult); var allScoredDriverRows = allScoredDriverResults.SelectMany(x => x.FinalResults); currentStandingsRows = allScoredResults.SelectMany(x => x.TeamResults) .AggregateByTeam(maxRacesCount, true, DropRacesOption, ResultsPerRaceCount, allScoredDriverRows) .OrderBy(x => - x.TotalPoints) .ThenBy(x => x.PenaltyPoints) .ThenBy(x => x.Wins); } else { previousStandingsRows = previousScoredRows.AggregateByTeam(maxRacesCount, true, DropRacesOption, ResultsPerRaceCount).OrderBy(x => - x.TotalPoints); allScoredResults = previousScoredResults.ToList(); allScoredResults.Add(currentScoredResult); currentStandingsRows = allScoredResults.SelectMany(x => x.TeamResults).AggregateByTeam(maxRacesCount, true, DropRacesOption, ResultsPerRaceCount).OrderBy(x => - x.TotalPoints); } previousStandingsRows.Select((value, index) => new { index, value }).ToList().ForEach(x => x.value.Position = x.index + 1); currentStandingsRows.Select((value, index) => new { index, value }).ToList().ForEach(x => x.value.Position = x.index + 1); teamStandings.StandingsRows = currentStandingsRows .Diff(previousStandingsRows) .OrderBy(x => - x.TotalPoints) .ThenBy(x => x.PenaltyPoints) .ThenBy(x => - x.Wins) .ToList(); //teamStandings.StandingsRows = currentStandingsRows.OrderBy(x => -x.TotalPoints).Cast<StandingsRowEntity>().ToList(); teamStandings.StandingsRows.ForEach(x => x.ScoringTable = this); //teamStandings.Calculate(); return(teamStandings); }