public List <PlayerFixture> GetTopPlayerStatsForFixture(int fixtureId, int teamLeagueId)
        {
            bool          mvpFound = false;
            PlayerFixture mvp      = null;

            // Get top scorers for fixture
            // TODO Remove hardcoded number of results value
            List <PlayerFixture> topScorers = this.statsReportingRepository.GetTopScorersForFixture(fixtureId, teamLeagueId, 3).ToList();

            foreach (PlayerFixture pf in topScorers)
            {
                if (pf.IsMvp == "Y")
                {
                    mvpFound = true;
                    break;
                }
            }

            // If MVP not found, find them. I.e. So the MVP is always shown
            if (!mvpFound)
            {
                // TODO Move this to a separate method?
                mvp = this.statsReportingRepository.GetMvpForFixture(fixtureId, teamLeagueId).SingleOrDefault();

                if (mvp != null)
                {
                    topScorers.Add(mvp);
                }
            }

            return(topScorers);
        }
        public void ShouldWin_WhenRandomValueNotGreaterThanWinProbability()
        {
            // arrange
            var options = new AttackOptions();

            var(originalPlayer, actualPlayer) = PlayerFixture.CreateClonedPlayers();
            var(mockCalculator, mockRandom)   = SetupRandomAndCalc(0.7, 0.7);

            var sut = CreateSut(
                player: actualPlayer,
                calculator: mockCalculator,
                random: mockRandom,
                options: options);
            // act
            var result = sut.Handle(new AttackCommand());

            // assert result
            result.Should().BeOfType <OkResult>();
            result.Message.Should().ContainEquivalentOf("win");
            // assert player state change
            actualPlayer.Health.Should()
            .Be(originalPlayer.Health - (int)(options.WinHealthReduceRate * originalPlayer.Health));
            actualPlayer.Coins.Should()
            .Be(originalPlayer.Coins + options.WinBonusCoins);
        }
        public PlayerCupStats UpdatePlayerCupStats(PlayerFixture playerFixture, Cup cup, Season season)
        {
            PlayerCupStats playerCupStats;

            // Get all PlayerFixture records for specified season
            List <PlayerFixture> playerFixturesForCup = statsReportingService.GetPlayerFixtureStatsForCupAndSeason(playerFixture.Player.Id, cup.Id, season.Id).ToList();

            // Total stats
            int totalPoints = playerFixturesForCup.Sum(pf => pf.PointsScored);
            int totalFouls  = playerFixturesForCup.Sum(pf => pf.Fouls);
            int mvpAwards   = playerFixturesForCup.Count(pf => pf.IsMvp == "Y");


            // Find existing record
            playerCupStats = statsReportingService.GetPlayerCupStats(playerFixture.Player.Id, cup.Id, season.Id);

            // If doesn't exist, create new
            if (playerCupStats == null)
            {
                playerCupStats = new PlayerCupStats(playerFixture.Player, cup, season, totalPoints, totalFouls, playerFixturesForCup.Count, mvpAwards);
            }
            else
            {
                // Update values
                playerCupStats.UpdateStats(totalPoints, totalFouls, playerFixturesForCup.Count, mvpAwards);
            }

            // Save
            matchResultRepository.SavePlayerCupStats(playerCupStats);

            return(playerCupStats);
        }
示例#4
0
        public void MapToPlayerFixture_Success()
        {
            playerFixtureStats.PointsScored = 10;
            playerFixtureStats.Fouls        = 4;
            playerFixtureStats.IsMvp        = false;

            PlayerFixture pf = new PlayerFixture()
            {
                Id     = 2,
                Player = new Player()
                {
                    Id = 10, Forename = "A", Surname = "B"
                },
                PointsScored = 3,
                Fouls        = 5,
                IsMvp        = "Y"
            };

            pf = playerFixtureStats.MapToPlayerFixture(pf);

            Assert.That(pf.Id, Is.EqualTo(2));
            Assert.That(pf.Player.Id, Is.EqualTo(10));
            Assert.That(pf.Player.ToString(), Is.EqualTo("A B"));
            Assert.That(pf.PointsScored, Is.EqualTo(playerFixtureStats.PointsScored));
            Assert.That(pf.Fouls, Is.EqualTo(playerFixtureStats.Fouls));
            Assert.That(pf.IsMvp, Is.EqualTo("N"));
        }
 private void CalculateResultType(PlayerFixture 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;
     }
 }
示例#6
0
        public static PlayerResultFixtureDto AssembleDto(this PlayerFixture fixture)
        {
            var dto = new PlayerResultFixtureDto
            {
                ID       = fixture.ID,
                Entrant1 = fixture.Entrant1.AssembleDto(),
                Entrant2 = fixture.Entrant2.AssembleDto(),
                Legs     = fixture.Legs,
                FixtureCalculationEngineID = fixture.FixtureCalculationEngineID,
                FixtureStatusID            = fixture.FixtureStatusID,
                Result1     = fixture.AssembleFixtureEntrant1Score(),
                Result2     = fixture.AssembleFixtureEntrant2Score(),
                SummaryData = fixture.AssembleSummaryDataDto()
            };

            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);
        }
示例#7
0
        private async Task Validate(UpdatePendingFixtureCommand command, PlayerFixture playerFixture)
        {
            ValidationContext <UpdatePendingFixtureCommand> validationContext = new ValidationContext <UpdatePendingFixtureCommand>(command);

            validationContext.RootContextData.Add("Fixture", playerFixture);
            this._validationResult = await this._validator.ValidateAsync(command);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PlayerFixture playerFixture = db.PlayerFixtures.Find(id);

            db.PlayerFixtures.Remove(playerFixture);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public PlayerFixture MapToPlayerFixture(PlayerFixture playerFixture)
        {
            playerFixture.PointsScored = this.PointsScored;
            playerFixture.Fouls        = this.Fouls;
            playerFixture.IsMvp        = this.IsMvp.BoolToYesNo();

            return playerFixture;
        }
示例#10
0
        public PlayerFixture MapToPlayerFixture(PlayerFixture playerFixture)
        {
            playerFixture.PointsScored = this.PointsScored;
            playerFixture.Fouls        = this.Fouls;
            playerFixture.IsMvp        = this.IsMvp.BoolToYesNo();

            return(playerFixture);
        }
示例#11
0
 public void MapToModel(PlayerFixture playerFixture)
 {
     this.PlayerFixtureId = playerFixture.Id;
     this.PlayerId        = playerFixture.Player.Id;
     this.Name            = playerFixture.Player.ToString();
     this.PointsScored    = playerFixture.PointsScored;
     this.Fouls           = playerFixture.Fouls;
     this.IsMvp           = playerFixture.IsMvp.YesNoToBool();
 }
 public void MapToModel(PlayerFixture playerFixture)
 {
     this.PlayerFixtureId = playerFixture.Id;
     this.PlayerId        = playerFixture.Player.Id;
     this.Name            = playerFixture.Player.ToString();
     this.PointsScored    = playerFixture.PointsScored;
     this.Fouls           = playerFixture.Fouls;
     this.IsMvp           = playerFixture.IsMvp.YesNoToBool();
 }
示例#13
0
 private static void PopulateBaseValues(BasePlayerFixtureDto dto, PlayerFixture 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;
 }
示例#14
0
 public PlayerFixtureDto(PlayerFixture pf)
 {
     this.FixtureId = pf.Fixture.Id;
     this.PlayerId  = pf.Player.Id;
     this.Forename  = pf.Player.Forename;
     this.Surname   = pf.Player.Surname;
     this.Fouls     = pf.Fouls;
     this.Points    = pf.PointsScored;
     this.IsMvp     = pf.IsMvp.YesNoToBool();
 }
        protected virtual void CalculateMatch(PlayerFixture fixture, Entities.Match.Match match)
        {
            this.CalculateChalks(fixture, match);
            this.CalculateGames(fixture, match);
            this.CalculateBonusPoints(fixture, match);
            this.CalculateResultType(fixture, match);

            fixture.Entrant1Walkover = match.HomeWalkover;
            fixture.Entrant2Walkover = match.AwayWalkover;
        }
        public void ShouldIncreasePower_WhenPurchase()
        {
            var originalPlayer = PlayerFixture.CreateDefaultPlayer();

            var(actualPlayer, options) = MakePurchase(originalPlayer);

            actualPlayer.Power.Should()
            .Be(originalPlayer.Power + options.MaxValue);
            actualPlayer.Coins.Should()
            .Be(originalPlayer.Coins - options.Price);
        }
        public void ShouldNotIncreaseHealthMoreThanMaxHealth_WhenPurchased()
        {
            var originalPlayer = PlayerFixture.CreateDefaultPlayer(maxHealth: 100, health: 95);

            var(actualPlayer, options) = MakePurchase(originalPlayer);

            actualPlayer.Health.Should()
            .Be(originalPlayer.MaxHealth);
            actualPlayer.Coins.Should()
            .Be(originalPlayer.Coins - options.Price);
        }
示例#18
0
 public ActionResult Edit(PlayerFixture @playerFixture)
 {
     if (ModelState.IsValid)
     {
         playerFixtureService.Update(@playerFixture);
         playerFixtureService.Commit();
         SuccessMessage(FormMessages.SaveSuccess);
         return(RedirectToAction("Index"));
     }
     return(View(@playerFixture));
 }
 public ActionResult Edit([Bind(Include = "PlayerFixturesID,FixtureID,TeamID,PlayerID,GoalsScored,YellowCards,RedCards,Assists")] PlayerFixture playerFixture)
 {
     if (ModelState.IsValid)
     {
         db.Entry(playerFixture).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FixtureID = new SelectList(db.Fixtures, "FixtureID", "FixtureID", playerFixture.FixtureID);
     ViewBag.PlayerID  = new SelectList(db.Players, "PlayerID", "PlayerName", playerFixture.PlayerID);
     return(View(playerFixture));
 }
示例#20
0
        public void CanCreatePlayerFixture()
        {
            PlayerFixture playerFixture = new PlayerFixture(teamLeagueHome, fixture, player, 15, 3);

            Assert.IsNotNull(playerFixture);
            Assert.That(playerFixture.TeamLeague, Is.EqualTo(teamLeagueHome));
            Assert.That(playerFixture.Fixture, Is.EqualTo(fixture));
            Assert.That(playerFixture.Player, Is.EqualTo(player));
            Assert.That(playerFixture.PointsScored, Is.EqualTo(15));
            Assert.That(playerFixture.Fouls, Is.EqualTo(3));
            Assert.That(playerFixture.IsMvp, Is.EqualTo("N"));
        }
示例#21
0
        public static FixtureSummaryDataDto AssembleSummaryDataDto(this PlayerFixture data)
        {
            var dto = new FixtureSummaryDataDto();

            dto.CompetitionName = data.CompetitionRound.Competition.Name;
            dto.CompetitionVenueDefaultPitchID = GetCompetitionDefaultPitch(data.CompetitionRound.Competition).ID;
            dto.CompetitionStageDescription    = GenerateCompetitionStageDescription(data);
            dto.CompetitionRoundDescription    = GenerateCompetitionRoundDescription(data.CompetitionRound);
            dto.CompetitionRoundType           = data.CompetitionRound.CompetitionRoundTypeID;
            dto.CompetitionRoundGameNumber     = data.CompetitionRound.GameNumber;

            return(dto);
        }
示例#22
0
        public static PlayerFixture CreatePlayerFixture(int id)
        {
            Player player = CreatePlayer();

            Fixture    fixture = CreateFixture(id);
            TeamLeague tl      = CreateTeamLeague();

            PlayerFixture playerFixture = new PlayerFixture(tl, fixture, player, 10, 2);

            EntityIdSetter.SetIdOf(playerFixture, id);

            return(playerFixture);
        }
        // GET: PlayerFixtures/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PlayerFixture playerFixture = db.PlayerFixtures.Find(id);

            if (playerFixture == null)
            {
                return(HttpNotFound());
            }
            return(View(playerFixture));
        }
示例#24
0
        public static BasePlayerFixtureDto AssembleDto(this PlayerFixture fixture)
        {
            switch (fixture.FixtureStatusID)
            {
            case FixtureStatuses.Pending:
                return(AssemblePendingDto(fixture));

            case FixtureStatuses.Incomplete:
            case FixtureStatuses.Complete:
                return(AssembleConfirmedDto(fixture));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        // GET: PlayerFixtures/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PlayerFixture playerFixture = db.PlayerFixtures.Find(id);

            if (playerFixture == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FixtureID = new SelectList(db.Fixtures, "FixtureID", "FixtureID", playerFixture.FixtureID);
            ViewBag.PlayerID  = new SelectList(db.Players, "PlayerID", "PlayerName", playerFixture.PlayerID);
            return(View(playerFixture));
        }
        private THandler CreateSut(
            Player player            = null,
            IPlayerStore playerStore = null,
            IRandom random           = null,
            TOptions options         = null)
        {
            player      = player ?? PlayerFixture.CreateDefaultPlayer();
            playerStore = playerStore ?? Substitute.For <IPlayerStore>();
            playerStore.GetPlayer().Returns(player);
            random = random ?? Substitute.For <IRandom>();
            var opts = Substitute.For <IOptions <TOptions> >();

            opts.Value.Returns(options ?? new TOptions());

            return(CreateSutImpl(playerStore, random, opts));
        }
示例#27
0
        public async Task <DefaultIdentityCommandResponse> Handle(AddPlayerFixtureCommand command)
        {
            this._unitOfWork.Begin();

            try
            {
                PlayerFixture fixture = null;

                if (this._validationResult.IsValid)
                {
                    await this.Load(command);

                    await this.ValidateOrCreateRound(command);

                    this.Validate(command);
                }

                if (this._validationResult.IsValid)
                {
                    fixture           = this._round.CreateFixture(command.TotalLegs, command.VenueType, command.Date);
                    fixture.Reference = command.Reference;
                    this.SetupFixture(fixture, command);

                    await this._playerCompetitionRoundRepository.Save(this._round);
                }

                if (this._validationResult.IsValid)
                {
                    this._unitOfWork.SoftCommit();
                    await this._playerCompetitionRoundRepository.Flush();

                    return(DefaultIdentityCommandResponse.Create(this._validationResult, fixture.ID));
                }
                else
                {
                    this._unitOfWork.Rollback();
                    return(DefaultIdentityCommandResponse.Create(this._validationResult));
                }
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                this._logger.LogCritical(e, nameof(AddPlayerFixtureCommandHandler));
                throw;
            }
        }
        public void ShouldFail_WhenNotEnoughCoins()
        {
            // arrange
            var options = new TOptions();

            var(originalPlayer, actualPlayer) = PlayerFixture.CreateClonedPlayers(coins: 0);

            var sut = CreateSut(
                player: actualPlayer,
                options: options);

            // act
            var result = sut.Handle(new TCommand());

            // assert
            result.Should().BeOfType <ErrorResult>();
        }
示例#29
0
        public void Constructor_Success()
        {
            PlayerFixture pf = new PlayerFixture()
            {
                Id     = 2,
                Player = new Player()
                {
                    Id = 10, Forename = "A", Surname = "B"
                },
                PointsScored = 3,
                Fouls        = 5,
                IsMvp        = "Y"
            };
            PlayerFixtureStats stats = new PlayerFixtureStats(pf, true);

            Assert.That(stats.HasPlayed, Is.True);
        }
        //protected Player SavePlayer(Player player)
        //{
        //    playerRepository.SaveOrUpdate(player);
        //    FlushSessionAndEvict(player);
        //    return player;
        //}

        private PlayerFixture AddPlayerFixture(TeamLeague teamLeague, Fixture fixture, Player player, int points, int fouls, bool isMvp)
        {
            PlayerFixture playerFixture = new PlayerFixture(teamLeague, fixture, player, points, fouls);

            if (isMvp)
            {
                playerFixture.IsMvp = "Y";
            }
            else
            {
                playerFixture.IsMvp = "N";
            }

            //statsRepository.SaveOrUpdatePlayerFixture(playerFixture);
            //FlushSessionAndEvict(playerFixture);
            return(playerFixture);
        }
示例#31
0
        private static PendingPlayerFixtureDto AssemblePendingDto(PlayerFixture fixture)
        {
            var dto = new PendingPlayerFixtureDto();

            PopulateBaseValues(dto, fixture);
            dto.PendingDate = fixture.PendingDate.Value;

            var entrant1 = new List <PlayerEntrantDto>();
            var entrant2 = new List <PlayerEntrantDto>();

            dto.Entrant1 = entrant1;
            dto.Entrant2 = entrant2;

            if (fixture.Entrant1 != null)
            {
                entrant1.Add(fixture.Entrant1.AssembleDto());
            }
            else if (fixture.PendingPlayer1Fixture != null)
            {
                GetTeams(entrant1, fixture.PendingPlayer1Fixture);
                dto.Entrant1Description = MapResultTypeDescription(fixture.Pending1ResultTypeID.Value, fixture.PendingPlayer1Fixture.Reference);
            }
            else
            {
                dto.Entrant1Description = "TBC";
            }

            if (fixture.Entrant2 != null)
            {
                entrant2.Add(fixture.Entrant2.AssembleDto());
            }
            else if (fixture.PendingPlayer2Fixture != null)
            {
                GetTeams(entrant2, fixture.PendingPlayer2Fixture);
                dto.Entrant2Description = MapResultTypeDescription(fixture.Pending2ResultTypeID.Value, fixture.PendingPlayer2Fixture.Reference);
            }
            else
            {
                dto.Entrant2Description = "TBC";
            }

            return(dto);
        }
示例#32
0
        public void ShouldCallFormulaCalculator_WithFormulaFromOptions()
        {
            // arrange
            var(_, actualPlayer) = PlayerFixture.CreateClonedPlayers();
            var mockCalculator = Substitute.For <IFormulaCalculator>();
            var options        = new AttackOptions {
                WinProbFormula = "formula"
            };

            var sut = CreateSut(
                player: actualPlayer,
                calculator: mockCalculator,
                options: options);

            // act
            sut.Handle(new AttackCommand());
            // assert
            mockCalculator.Received().Calculate("formula", Arg.Any <FormulaContext>());
        }
 public PlayerFixtureStats(PlayerFixture playerFixture, bool hasPlayed)
 {
     MapToModel(playerFixture);
     this.HasPlayed = hasPlayed;
 }