internal static TeamInMatchResponse ToTeamInMatchResponse(this TeamInMatch teamInMatch) { return(new TeamInMatchResponse { Id = teamInMatch.TeamId, Name = teamInMatch.Team.Name, Flag = teamInMatch.Team.Flag, Score = teamInMatch.Score }); }
internal static TeamInMatchDetailsResponse ToTeamInMatchDetailsResponse(this TeamInMatch teamInMatch) { return(new TeamInMatchDetailsResponse { Id = teamInMatch.TeamId, Name = teamInMatch.Team.Name, Flag = teamInMatch.Team.Flag, Score = teamInMatch.Score, Players = teamInMatch.PlayerInTeamInMatches.Select(x => x.ToPlayerResponse()) .OrderByDescending(o => o.Score).ToList() }); }
private void createStartData() { Board = new ScoreBoard(); HomeT = new TeamInMatch { Name = "team1", Country = "Ukraine", Ñoach = "Cool man", TeamScore = 0 }; AwayT = new TeamInMatch { Name = "team2", Country = "USA", Ñoach = "Cool man2", TeamScore = 0 }; NewMatch = new Match(1, HomeT, AwayT); Board.AddMatch(NewMatch); }
public TeamInMatch calculateTeamInfluence(TeamInMatch SourceTeam, TeamInMatch TargetTeam) { // This should be put in a global setting somewhere double BaseModifier = 0.005; foreach (var SourcePlayer in SourceTeam.Players) { //foreach (var TargetPlayer in TargetTeam.Players) //{ // Matchup newMatchup = new Matchup(); // newMatchup.TargetHeroID = TargetPlayer.Hero.HeroInfo.HeroID; // // Get disadvantage data // newMatchup.Disadvantage = _dbService.WinRatesVersus.Where(x => x.BaseHeroID == SourcePlayer.Hero.HeroInfo.HeroID && x.TargetHeroID == newMatchup.TargetHeroID).FirstOrDefault().Disadvantage; // SourcePlayer.Hero.Matchups.Add(newMatchup); // SourcePlayer.Influence += newMatchup.Disadvantage; //} // Amplify Influence by skills // Base Modifier * Player Skill * Hero Skill SourcePlayer.Hero.InfluenceEfficiencyModifier = BaseModifier * SourcePlayer.Efficiency * SourcePlayer.Hero.Efficiency; SourcePlayer.Hero.InfluencePoiseModifier = BaseModifier * SourcePlayer.Poise * SourcePlayer.Hero.Poise; SourcePlayer.Hero.InfluenceSpeedModifier = BaseModifier * SourcePlayer.Speed * SourcePlayer.Hero.Speed; SourcePlayer.Hero.InfluencePositioningModifier = BaseModifier * SourcePlayer.Positioning * SourcePlayer.Hero.Positioning; SourcePlayer.Hero.InfluenceAwarenessModifier = BaseModifier * SourcePlayer.Awareness * SourcePlayer.Hero.Awareness; SourcePlayer.Hero.InfluenceTotalModifier = SourcePlayer.Hero.InfluenceEfficiencyModifier + SourcePlayer.Hero.InfluencePoiseModifier + SourcePlayer.Hero.InfluenceSpeedModifier + SourcePlayer.Hero.InfluencePositioningModifier + SourcePlayer.Hero.InfluenceAwarenessModifier; SourcePlayer.Influence = SourcePlayer.Hero.InfluenceMatchups + ((SourcePlayer.Hero.InfluenceMatchups * SourcePlayer.Hero.InfluenceTotalModifier) / 100); // Sorts matchups by hero ID, testing only - makes for easier comparison SourcePlayer.Hero.Matchups.OrderBy(x => x.TargetHeroID); SourceTeam.Influence += SourcePlayer.Influence; } return(SourceTeam); }
public MatchFixture() { var bowlingFiguresCalculator = new BowlingFiguresCalculator(_oversHelper); var playerIdentityFinder = new PlayerIdentityFinder(); var seedDataGenerator = new SeedDataGenerator(_oversHelper, bowlingFiguresCalculator, playerIdentityFinder, new TeamFakerFactory(), new MatchLocationFakerFactory(), new SchoolFakerFactory()); var homeTeam = new TeamInMatch { MatchTeamId = Guid.NewGuid(), Team = seedDataGenerator.CreateTeamWithMinimalDetails("Home team"), WonToss = true, BattedFirst = true, TeamRole = TeamRole.Home }; var awayTeam = new TeamInMatch { MatchTeamId = Guid.NewGuid(), Team = seedDataGenerator.CreateTeamWithMinimalDetails("Away team"), WonToss = false, BattedFirst = false, TeamRole = TeamRole.Away }; homeTeam.Team.Club = new Club { ClubId = Guid.NewGuid(), ClubName = "Home club", ClubRoute = "/home-club" }; for (var i = 0; i < 11; i++) { HomePlayers.Add(new PlayerIdentity { Player = new Player { PlayerId = Guid.NewGuid(), PlayerRoute = "/players/home-" + (i + 1) }, PlayerIdentityId = Guid.NewGuid(), PlayerIdentityName = "Home player identity " + (i + 1), Team = homeTeam.Team }); } ; for (var i = 0; i < 11; i++) { AwayPlayers.Add(new PlayerIdentity { Player = new Player { PlayerId = Guid.NewGuid(), PlayerRoute = "/players/away-" + (i + 1) }, PlayerIdentityId = Guid.NewGuid(), PlayerIdentityName = "Away player identity " + (i + 12), Team = awayTeam.Team }); } ; var firstInningsOverSets = seedDataGenerator.CreateOverSets(); var secondInningsOverSets = seedDataGenerator.CreateOverSets(); var thirdInningsOverSets = seedDataGenerator.CreateOverSets(); var fourthInningsOverSets = seedDataGenerator.CreateOverSets(); var competition = seedDataGenerator.CreateCompetitionWithMinimalDetails(); var season = seedDataGenerator.CreateSeasonWithMinimalDetails(competition, 2020, 2020); competition.Seasons.Add(season); Match = new Match { MatchId = Guid.NewGuid(), MatchType = MatchType.LeagueMatch, PlayerType = PlayerType.Ladies, MatchName = "Team A beat Team B", UpdateMatchNameAutomatically = true, StartTime = new DateTimeOffset(2020, 7, 1, 19, 00, 00, TimeSpan.FromHours(1)), StartTimeIsKnown = true, Awards = new List <MatchAward> { new MatchAward { AwardedToId = Guid.NewGuid(), Award = new Award { AwardId = Guid.NewGuid(), AwardName = "Champagne moment" }, PlayerIdentity = AwayPlayers[4], Reason = "Amazing catch" }, new MatchAward { AwardedToId = Guid.NewGuid(), Award = new Award { AwardId = Guid.NewGuid(), AwardName = "Player of the match" }, PlayerIdentity = HomePlayers[2], Reason = "Taking wickets" } }, EnableBonusOrPenaltyRuns = true, InningsOrderIsKnown = true, LastPlayerBatsOn = true, PlayersPerTeam = 11, Teams = new List <TeamInMatch> { homeTeam, awayTeam }, Season = season, MatchInnings = new List <MatchInnings> { new MatchInnings { MatchInningsId = Guid.NewGuid(), InningsOrderInMatch = 1, BattingMatchTeamId = homeTeam.MatchTeamId, BowlingMatchTeamId = awayTeam.MatchTeamId, BattingTeam = homeTeam, BowlingTeam = awayTeam, NoBalls = 20, Wides = 15, Byes = 10, BonusOrPenaltyRuns = 5, Runs = 200, Wickets = 2, PlayerInnings = CreateBattingScorecard(HomePlayers, AwayPlayers), OverSets = firstInningsOverSets, OversBowled = seedDataGenerator.CreateOversBowled(AwayPlayers, firstInningsOverSets) }, new MatchInnings { MatchInningsId = Guid.NewGuid(), InningsOrderInMatch = 2, BattingMatchTeamId = awayTeam.MatchTeamId, BowlingMatchTeamId = homeTeam.MatchTeamId, BattingTeam = awayTeam, BowlingTeam = homeTeam, NoBalls = 23, Wides = 12, Byes = 5, BonusOrPenaltyRuns = 0, Runs = 230, Wickets = 7, PlayerInnings = CreateBattingScorecard(AwayPlayers, HomePlayers), OverSets = secondInningsOverSets, OversBowled = seedDataGenerator.CreateOversBowled(HomePlayers, secondInningsOverSets) }, new MatchInnings { MatchInningsId = Guid.NewGuid(), InningsOrderInMatch = 3, BattingMatchTeamId = homeTeam.MatchTeamId, BowlingMatchTeamId = awayTeam.MatchTeamId, BattingTeam = homeTeam, BowlingTeam = awayTeam, NoBalls = 31, Wides = 2, Byes = 18, BonusOrPenaltyRuns = -6, Runs = 150, Wickets = 10, PlayerInnings = CreateBattingScorecard(HomePlayers, AwayPlayers), OverSets = thirdInningsOverSets, OversBowled = seedDataGenerator.CreateOversBowled(AwayPlayers, thirdInningsOverSets) }, new MatchInnings { MatchInningsId = Guid.NewGuid(), InningsOrderInMatch = 4, BattingMatchTeamId = awayTeam.MatchTeamId, BowlingMatchTeamId = homeTeam.MatchTeamId, BattingTeam = awayTeam, BowlingTeam = homeTeam, NoBalls = 16, Wides = 12, Byes = 8, BonusOrPenaltyRuns = 2, Runs = 210, Wickets = 4, PlayerInnings = CreateBattingScorecard(AwayPlayers, HomePlayers), OverSets = fourthInningsOverSets, OversBowled = seedDataGenerator.CreateOversBowled(HomePlayers, fourthInningsOverSets) } }, MatchLocation = seedDataGenerator.CreateMatchLocationWithMinimalDetails(), MatchResultType = MatchResultType.HomeWin, MatchNotes = "<p>This is a test match, not a Test Match.</p>", MatchRoute = "/matches/team-a-vs-team-b-1jul2020-" + Guid.NewGuid(), MemberKey = Guid.NewGuid(), }; var bowlingFigures = new BowlingFiguresCalculator(new OversHelper()); foreach (var innings in Match.MatchInnings) { innings.BowlingFigures = bowlingFigures.CalculateBowlingFigures(innings); } // The last innings will be missing its overs bowled, to simulate bowling figures entered by the user instead of calculated from overs Match.MatchInnings[3].OversBowled.Clear(); }
private static PlayerInMatchStatisticsRecord CreateRecordForPlayerInInningsPair(Match match, MatchInnings innings, PlayerIdentity identity, TeamInMatch team, TeamInMatch opposition) { var isOnBattingTeam = team.MatchTeamId == innings.BattingMatchTeamId; var pairedInnings = match.MatchInnings.Single(x => x.InningsPair() == innings.InningsPair() && x.MatchInningsId != innings.MatchInningsId); return(new PlayerInMatchStatisticsRecord { PlayerId = identity.Player.PlayerId.Value, PlayerIdentityId = identity.PlayerIdentityId.Value, PlayerIdentityName = identity.PlayerIdentityName, PlayerRoute = identity.Player.PlayerRoute, MatchId = match.MatchId.Value, MatchName = match.MatchName, MatchType = match.MatchType, MatchPlayerType = match.PlayerType, MatchRoute = match.MatchRoute, MatchStartTime = match.StartTime, TournamentId = match.Tournament?.TournamentId, MatchLocationId = match.MatchLocation?.MatchLocationId, SeasonId = match.Season?.SeasonId, CompetitionId = match.Season?.Competition?.CompetitionId, MatchInningsPair = innings.InningsPair(), TeamRunsScored = isOnBattingTeam ? innings.Runs : pairedInnings.Runs, TeamWicketsLost = isOnBattingTeam ? innings.Wickets : pairedInnings.Wickets, TeamBonusOrPenaltyRunsAwarded = isOnBattingTeam ? innings.BonusOrPenaltyRuns : pairedInnings.BonusOrPenaltyRuns, TeamRunsConceded = isOnBattingTeam ? pairedInnings.Runs : innings.Runs, TeamNoBallsConceded = isOnBattingTeam ? pairedInnings.NoBalls : innings.NoBalls, TeamWidesConceded = isOnBattingTeam ? pairedInnings.Wides : innings.Wides, TeamByesConceded = isOnBattingTeam ? pairedInnings.Byes : innings.Byes, TeamWicketsTaken = isOnBattingTeam ? pairedInnings.Wickets : innings.Wickets, MatchTeamId = team.MatchTeamId.Value, ClubId = team.Team.Club?.ClubId, TeamId = team.Team.TeamId.Value, TeamName = team.Team.TeamName, TeamRoute = team.Team.TeamRoute, OppositionTeamId = opposition.Team.TeamId.Value, OppositionTeamName = opposition.Team.TeamName, OppositionTeamRoute = opposition.Team.TeamRoute, }); }
private static void FindOrCreateInningsRecordsForBatter(List <PlayerInMatchStatisticsRecord> records, Match match, TeamInMatch homeTeam, TeamInMatch awayTeam, MatchInnings innings, bool homeTeamIsBatting, PlayerIdentity batter) { var allPlayerInningsForThisPlayer = innings.PlayerInnings.Where(x => x.Batter.PlayerIdentityId == batter.PlayerIdentityId).OrderBy(x => x.BattingPosition).ToList(); var firstPlayerInningsForThisPlayer = allPlayerInningsForThisPlayer.FirstOrDefault(); // Find or add a record every batting team member in this innings regardless of whether they are recorded as batting var record = records.SingleOrDefault(x => x.MatchTeamId == innings.BattingMatchTeamId && x.PlayerIdentityId == batter.PlayerIdentityId && x.MatchInningsPair == innings.InningsPair() && (x.PlayerInningsNumber == 1 || x.PlayerInningsNumber == null)); if (record == null) { record = CreateRecordForPlayerInInningsPair(match, innings, batter, homeTeamIsBatting ? homeTeam : awayTeam, homeTeamIsBatting ? awayTeam : homeTeam); records.Add(record); } record.PlayerInningsNumber = 1; AddPlayerInningsDataToRecord(firstPlayerInningsForThisPlayer, record); // There may be player innings with DismissalType = null, but that means they *were* dismissed, so for players who are missing from the batting card assume DidNotBat rather than null record.DismissalType = firstPlayerInningsForThisPlayer != null ? firstPlayerInningsForThisPlayer.DismissalType : DismissalType.DidNotBat; record.PlayerWasDismissed = firstPlayerInningsForThisPlayer != null?StatisticsConstants.DISMISSALS_THAT_ARE_OUT.Contains(firstPlayerInningsForThisPlayer.DismissalType) : false; // Add extra records for any players who batted multiple times in the same innings for (var i = 1; i < allPlayerInningsForThisPlayer.Count; i++) { var extraBattingRecord = records.SingleOrDefault(x => x.MatchTeamId == innings.BattingMatchTeamId && x.PlayerIdentityId == batter.PlayerIdentityId && x.MatchInningsPair == innings.InningsPair() && x.PlayerInningsNumber == i + 1); if (extraBattingRecord == null) { extraBattingRecord = CreateRecordForPlayerInInningsPair(match, innings, batter, homeTeamIsBatting ? homeTeam : awayTeam, homeTeamIsBatting ? awayTeam : homeTeam); extraBattingRecord.PlayerInningsNumber = i + 1; AddPlayerInningsDataToRecord(allPlayerInningsForThisPlayer[i], extraBattingRecord); extraBattingRecord.DismissalType = allPlayerInningsForThisPlayer[i].DismissalType; extraBattingRecord.PlayerWasDismissed = StatisticsConstants.DISMISSALS_THAT_ARE_OUT.Contains(allPlayerInningsForThisPlayer[i].DismissalType); records.Add(extraBattingRecord); } } }
private void FindOrCreateInningsRecordForFielder(List <PlayerInMatchStatisticsRecord> records, Match match, TeamInMatch homeTeam, TeamInMatch awayTeam, MatchInnings innings, bool homeTeamIsBatting, PlayerIdentity fielder) { var record = records.SingleOrDefault(x => x.MatchTeamId == innings.BowlingMatchTeamId && x.PlayerIdentityId == fielder.PlayerIdentityId && x.MatchInningsPair == innings.InningsPair() && (x.PlayerInningsNumber == 1 || x.PlayerInningsNumber == null)); if (record == null) { record = CreateRecordForPlayerInInningsPair(match, innings, fielder, homeTeamIsBatting ? awayTeam : homeTeam, homeTeamIsBatting ? homeTeam : awayTeam); record.PlayerInningsNumber = null; records.Add(record); } var bowlingFigures = innings.BowlingFigures.SingleOrDefault(x => x.Bowler.PlayerIdentityId == fielder.PlayerIdentityId); var oversBowled = innings.OversBowled.Where(x => x.Bowler.PlayerIdentityId == fielder.PlayerIdentityId); record.Catches = innings.PlayerInnings.Count(x => (x.DismissalType == DismissalType.Caught && x.DismissedBy?.PlayerIdentityId == fielder.PlayerIdentityId) || (x.DismissalType == DismissalType.CaughtAndBowled && x.Bowler?.PlayerIdentityId == fielder.PlayerIdentityId)); record.RunOuts = innings.PlayerInnings.Count(x => x.DismissalType == DismissalType.RunOut && x.DismissedBy?.PlayerIdentityId == fielder.PlayerIdentityId); record.BowlingFiguresId = bowlingFigures?.BowlingFiguresId; record.OverNumberOfFirstOverBowled = innings.OversBowled.OrderBy(x => x.OverNumber).FirstOrDefault(x => x.Bowler.PlayerIdentityId == fielder.PlayerIdentityId)?.OverNumber; if (oversBowled.Any()) { record.BallsBowled = oversBowled.Where(x => x.BallsBowled.HasValue).Sum(x => x.BallsBowled) + (oversBowled.Count(x => !x.BallsBowled.HasValue) * StatisticsConstants.BALLS_PER_OVER); record.NoBalls = oversBowled.Sum(x => x.NoBalls); record.Wides = oversBowled.Sum(x => x.Wides); } else { record.BallsBowled = bowlingFigures?.Overs != null?_oversHelper.OversToBallsBowled(bowlingFigures.Overs.Value) : (int?)null; } record.Overs = bowlingFigures?.Overs; record.Maidens = bowlingFigures?.Maidens; record.RunsConceded = bowlingFigures?.RunsConceded; record.HasRunsConceded = bowlingFigures?.RunsConceded != null; record.Wickets = bowlingFigures?.Wickets; record.WicketsWithBowling = (bowlingFigures != null && oversBowled.Any()) ? bowlingFigures.Wickets : (int?)null; }