private void GuardCheck(TeamFixture fixture) { foreach (var match in fixture.Matches) { match.MatchStatusID.GuardCheckProcessedWithResult(); } }
public async Task <ITeamResultEngine> GetEngine(IResultsEngineRequest request) { this._unitOfWork.GuardCheckInTransaction(); await this._competitionRepository.GetForUpdate(request.CompetitionID); Entities.Competition competition = await this._competitionRepository.GetWithStages(request.CompetitionID); CompetitionStage stage = this.GetStage(competition, request.CompetitionStageLoadMode, request.CompetitionStageValue); TeamFixture fixture = await this._fixtureRepository.GetTeamFixtureFull(request.FixtureID); if (fixture.CompetitionRound.Competition.ID != competition.ID) { throw new ArgumentException("Incorrect competition/fixture ID combination", nameof(request)); } ITeamFixtureModel teamFixtureModel = this._serviceProvider.GetService <ITeamFixtureModel>(); ITeamResultEngineContext context = this._serviceProvider.GetService <ITeamResultEngineContext>(); await context.Initialise(competition, stage, fixture.CompetitionRound.CompetitionEvent, fixture.CompetitionRound, teamFixtureModel); var engine = this._serviceProvider.GetService <ITeamResultEngine>(); engine.SetContext(context); await teamFixtureModel.Initialise(fixture, context); return(engine); }
private void CalculateResultType(TeamFixture fixture) { if (fixture.Entrant1ChalkScore == fixture.Entrant2ChalkScore) { if (fixture.Entrant1GameScore > fixture.Entrant2GameScore) { fixture.Entrant1ResultTypeID = ResultType.Win; fixture.Entrant2ResultTypeID = ResultType.Lose; } else if (fixture.Entrant1GameScore < fixture.Entrant2GameScore) { fixture.Entrant1ResultTypeID = ResultType.Lose; fixture.Entrant2ResultTypeID = ResultType.Win; } } else if (fixture.Entrant1ChalkScore > fixture.Entrant2ChalkScore) { fixture.Entrant1ResultTypeID = ResultType.Win; fixture.Entrant2ResultTypeID = ResultType.Lose; } else { fixture.Entrant1ResultTypeID = ResultType.Lose; fixture.Entrant2ResultTypeID = ResultType.Win; } }
private void CalculateResultType(TeamFixture fixture) { var team1Difference = (fixture.Entrant1ChalkScore - fixture.Entrant2ChalkScore); if (fixture.Entrant1GameScore == fixture.Entrant2GameScore) { if (team1Difference > 0) { fixture.Entrant1ResultTypeID = ResultType.Win; fixture.Entrant2ResultTypeID = ResultType.Lose; } else if (team1Difference < 0) { fixture.Entrant1ResultTypeID = ResultType.Lose; fixture.Entrant2ResultTypeID = ResultType.Win; } } else if (fixture.Entrant1GameScore > fixture.Entrant2GameScore) { fixture.Entrant1ResultTypeID = ResultType.Win; fixture.Entrant2ResultTypeID = ResultType.Lose; } else { fixture.Entrant1ResultTypeID = ResultType.Lose; fixture.Entrant2ResultTypeID = ResultType.Win; } }
private static void PopulateBaseValues(BaseTeamFixtureDto dto, TeamFixture data) { dto.ID = data.ID; dto.Legs = data.Legs; dto.FixtureCalculationEngineID = data.FixtureCalculationEngineID; dto.FixtureStatusID = data.FixtureStatusID; dto.SummaryData = data.AssembleSummaryDataDto(); dto.Reference = data.Reference; }
protected virtual void CalculateMatch(TeamFixture fixture, Entities.Match.Match match) { CalculateChalks(fixture, match); CalculateGames(fixture, match); CalculateBonusPoints(fixture, match); CalculateResultType(fixture, match); fixture.Entrant1Walkover = match.HomeWalkover; fixture.Entrant2Walkover = match.AwayWalkover; }
public async Task Remove(Entities.League league, TeamLeagueTable table, TeamFixture fixture) { this.GuardCheck(fixture); var line1 = table.GetOrCreateLine(fixture.Entrant1); var line2 = table.GetOrCreateLine(fixture.Entrant2); await this.InnerRemove(league, line1, fixture); await this.InnerRemove(league, line2, fixture); }
private void SetLastUpdate(TeamLeagueTable table, TeamFixture fixture) { var matchDate = fixture.Matches.Max(x => x.Date); if (!table.LastUpdate.HasValue) { table.LastUpdate = matchDate; } else { table.LastUpdate = (table.LastUpdate < matchDate) ? matchDate : table.LastUpdate; } }
public async Task Add(Entities.League league, TeamLeagueTable table, TeamFixture fixture) { this.GuardCheck(fixture); var line1 = table.GetOrCreateLine(fixture.Entrant1); var line2 = table.GetOrCreateLine(fixture.Entrant2); await this.InnerAdd(league, line1, fixture); await this.InnerAdd(league, line2, fixture); this.SetLastUpdate(table, fixture); }
public static FixtureSummaryDataDto AssembleSummaryDataDto(this TeamFixture data) { var dto = new FixtureSummaryDataDto(); dto.CompetitionName = data.CompetitionRound.Competition.Name; dto.CompetitionVenueDefaultPitchID = null; //TODO: may need to review this dto.CompetitionStageDescription = GenerateCompetitionStageDescription(data); dto.CompetitionRoundDescription = GenerateCompetitionRoundDescription(data.CompetitionRound); dto.CompetitionRoundType = data.CompetitionRound.CompetitionRoundTypeID; dto.CompetitionRoundGameNumber = data.CompetitionRound.GameNumber; return(dto); }
public ITeamLeagueTableCalculationEngine Create(TeamFixture fixture) { if (fixture.Legs == 1) { return(this._singleMatchTeamLeagueTableCalculationEngine); } if (fixture.Legs > 1) { return(this._multiMatchTeamLeagueTableCalculationEngine); } return(null); }
public static BaseTeamFixtureDto AssembleDto(this TeamFixture fixture) { switch (fixture.FixtureStatusID) { case FixtureStatuses.Pending: return(AssemblePendingDto(fixture)); case FixtureStatuses.Incomplete: case FixtureStatuses.Complete: return(AssembleConfirmedDto(fixture)); default: throw new ArgumentOutOfRangeException(); } }
public virtual void RemovePoints(TeamFixture fixture, short bonusPoints, short points) { foreach (var match in fixture.Matches) { match.MatchStatusID.GuardCheckProcessedWithResult(); } if (fixture.Entrant1.ID == this.Party.ID || fixture.Entrant2.ID == this.Party.ID) { this.NeutralBonusPoints -= bonusPoints; this.NeutralPoints -= points; } else { throw new InvalidOperationException("TeamMatch provided does not contain results for team [" + this.Party.ID + "]"); } }
private static PendingTeamFixtureDto AssemblePendingDto(TeamFixture fixture) { var dto = new PendingTeamFixtureDto(); PopulateBaseValues(dto, fixture); dto.PendingDate = fixture.PendingDate.Value; var entrant1 = new List <TeamDto>(); var entrant2 = new List <TeamDto>(); dto.Entrant1 = entrant1; dto.Entrant2 = entrant2; if (fixture.Entrant1 != null) { entrant1.Add(fixture.Entrant1.AssembleDto()); dto.Entrant1Description = GenerateEntrantDisplayName(entrant1); } else if (fixture.PendingTeam1Fixture != null) { GetTeams(entrant1, fixture.PendingTeam1Fixture); dto.Entrant1Description = MapResultTypeDescription(fixture.Pending1ResultTypeID.Value, GenerateEntrantDisplayName(entrant1)); } else { dto.Entrant1Description = "TBC"; } if (fixture.Entrant2 != null) { entrant2.Add(fixture.Entrant2.AssembleDto()); dto.Entrant2Description = GenerateEntrantDisplayName(entrant2); } else if (fixture.PendingTeam2Fixture != null) { GetTeams(entrant2, fixture.PendingTeam2Fixture); dto.Entrant2Description = MapResultTypeDescription(fixture.Pending2ResultTypeID.Value, GenerateEntrantDisplayName(entrant2)); } else { dto.Entrant2Description = "TBC"; } return(dto); }
public virtual void Add(TeamFixture fixture) { foreach (var match in fixture.Matches) { match.MatchStatusID.GuardCheckProcessedWithResult(); } if (fixture.Entrant1.ID == this.Party.ID) { this.AddNeutralResult(fixture.Entrant1ResultTypeID.Value, fixture.Entrant1Walkover.Value, fixture.Entrant1GameScore.Value, fixture.Entrant2GameScore.Value, fixture.Entrant1ChalkScore.Value, fixture.Entrant2ChalkScore.Value); } else if (fixture.Entrant2.ID == this.Party.ID) { this.AddNeutralResult(fixture.Entrant2ResultTypeID.Value, fixture.Entrant2Walkover.Value, fixture.Entrant2GameScore.Value, fixture.Entrant1GameScore.Value, fixture.Entrant2ChalkScore.Value, fixture.Entrant1ChalkScore.Value); } else { throw new InvalidOperationException("TeamMatch provided does not contain results for team [" + this.Party.ID + "]"); } }
private static void GetTeams(List <TeamDto> players, TeamFixture pendingFixture) { if (pendingFixture.Entrant1 != null) { players.Add(pendingFixture.Entrant1.AssembleDto()); } if (pendingFixture.Entrant2 != null) { players.Add(pendingFixture.Entrant2.AssembleDto()); } if (pendingFixture.PendingTeam1Fixture != null) { GetTeams(players, pendingFixture.PendingTeam1Fixture); } if (pendingFixture.PendingTeam2Fixture != null) { GetTeams(players, pendingFixture.PendingTeam2Fixture); } }
private static ConfirmedTeamFixtureDto AssembleConfirmedDto(TeamFixture fixture) { var dto = new ConfirmedTeamFixtureDto(); PopulateBaseValues(dto, fixture); dto.Entrant1 = fixture.Entrant1.AssembleDto(); dto.Entrant2 = fixture.Entrant2.AssembleDto(); dto.Result1 = fixture.AssembleFixtureEntrant1Score(); dto.Result2 = fixture.AssembleFixtureEntrant2Score(); foreach (var match in fixture.Matches) { var homeEntrant = (match.Home.ID == fixture.Entrant1.ID ? dto.Entrant1 : dto.Entrant2); var awayEntrant = (match.Away.ID == fixture.Entrant2.ID ? dto.Entrant2 : dto.Entrant1); var matchDto = match.AssembleDto(homeEntrant, awayEntrant); dto.Matches.Add(matchDto); } return(dto); }
protected override Task InnerCalculate(TeamFixture fixture) { if (fixture.Matches.Count == fixture.Legs && fixture.Matches.All(x => x.MatchStatusID.IsProcessedWithResult())) { var match = fixture.Matches.SingleOrDefault(); if (match != null) { this.CalculateMatch(fixture, match); fixture.SetComplete(); } else { fixture.SetIncomplete(); } } else { fixture.SetIncomplete(); } return(Task.CompletedTask); }
protected abstract Task InnerRemove(Entities.League league, TeamLeagueTableLine line, TeamFixture fixture);
public Builder WithCompletedFixture(TeamFixture fixture) { this.Instance.CompletedFixture = fixture; return(this); }
private Task <TeamLeagueTableLinePoints> CalculatePoints(Entities.League league, int teamID, TeamFixture fixture) { var entry = fixture.GetScoresSummaryByEntrantID(teamID); switch (league.LeaguePointsModeID) { case LeaguePointsModes.ResultPoints: return(this.CalculateByResultPoints(league, entry)); case LeaguePointsModes.Chalks: return(this.CalculateByChalks(league, entry)); case LeaguePointsModes.GamesAndBonus: return(this.CalculateByGamesAndBonus(league, entry)); default: throw new ArgumentOutOfRangeException(); } }
protected override async Task InnerRemove(Entities.League league, TeamLeagueTableLine line, TeamFixture fixture) { var points = await this.CalculatePoints(league, line.Party.ID, fixture); line.Remove(fixture); line.RemovePoints(fixture, points.BonusPoints, points.Points); }
private static void CalculateChalks(TeamFixture fixture, Entities.Match.Match match) { fixture.Entrant1ChalkScore = match.HomeChalkScore; fixture.Entrant2ChalkScore = match.AwayChalkScore; }
protected abstract Task InnerCalculate(TeamFixture fixture);
private static void CalculateResultType(TeamFixture fixture, Entities.Match.Match match) { fixture.Entrant1ResultTypeID = match.HomeResultTypeID; fixture.Entrant2ResultTypeID = match.AwayResultTypeID; }
private static void CalculateBonusPoints(TeamFixture fixture, Entities.Match.Match match) { fixture.Entrant1BonusScore = match.HomeBonusScore; fixture.Entrant2BonusScore = match.AwayBonusScore; }
protected override async Task InnerRemove(Entities.League league, TeamLeagueTableLine line, TeamFixture fixture) { var match = fixture.Matches.Single(); var points = await this.CalculatePoints(league, line.Party.ID, match); line.Remove(match); line.RemovePoints(match, points.BonusPoints, points.Points); }
public Task Calculate(TeamFixture fixture) { return(this.InnerCalculate(fixture)); }
private static void CalculateGames(TeamFixture fixture, Entities.Match.Match match) { fixture.Entrant1GameScore = match.HomeGameScore; fixture.Entrant2GameScore = match.AwayGameScore; }
protected override Task InnerCalculate(TeamFixture fixture) { if (fixture.Matches.Count == fixture.Legs && fixture.Matches.All(x => MatchStatus.IsProcessedWithResult(x.MatchStatusID))) { fixture.Entrant1GameScore = 0; fixture.Entrant1ChalkScore = 0; fixture.Entrant1Walkover = true; fixture.Entrant2GameScore = 0; fixture.Entrant2ChalkScore = 0; fixture.Entrant2Walkover = true; foreach (TeamMatch playerMatch in fixture.Matches) { short gameScore; short chalkScore; short?bonusScore; bool? walkover; playerMatch.GetScoresByEntrantID(fixture.Entrant1.ID, out gameScore, out chalkScore, out bonusScore, out walkover); fixture.Entrant1GameScore += gameScore; fixture.Entrant1ChalkScore += chalkScore; if (bonusScore.HasValue) { if (!fixture.Entrant1BonusScore.HasValue) { fixture.Entrant1BonusScore = 0; } fixture.Entrant1BonusScore += bonusScore.Value; } if (walkover.HasValue) { fixture.Entrant1Walkover &= walkover.Value; } playerMatch.GetScoresByEntrantID(fixture.Entrant2.ID, out gameScore, out chalkScore, out bonusScore, out walkover); fixture.Entrant2GameScore += gameScore; fixture.Entrant2ChalkScore += chalkScore; if (bonusScore.HasValue) { if (!fixture.Entrant2BonusScore.HasValue) { fixture.Entrant2BonusScore = 0; } fixture.Entrant2BonusScore += bonusScore.Value; } if (walkover.HasValue) { fixture.Entrant2Walkover &= walkover.Value; } } this.CalculateResultType(fixture); fixture.SetComplete(); } else { fixture.SetIncomplete(); } return(Task.CompletedTask); }