コード例 #1
0
        public Lineup AssignLineup(TeamGame teamGame, List <Player> players)
        {
            const int playersInAFullLineup = 5;

            if (players.Count > playersInAFullLineup)
            {
                throw new ArgumentException("players");
            }

            DateTime now      = Settings.CurrentTime;
            TimeSpan gameTime = GetGameTime(teamGame.Game).TotalEllapsedTime;

            Lineup lineup = new Lineup()
            {
                Game          = teamGame.Game,
                Players       = players,
                Team          = teamGame.Team,
                StartDateTime = now,
                StartGameTime = gameTime,
                EndDateTime   = now,
                EndGameTime   = gameTime,
            };

            Lineup oldLineup = teamGame.Lineups.LastOrDefault();

            if (oldLineup != null)
            {
                oldLineup.EndDateTime = now;
                oldLineup.EndGameTime = gameTime;
            }

            teamGame.Lineups.Add(lineup);
            return(lineup);
        }
コード例 #2
0
ファイル: RandomModel.cs プロジェクト: raudut/Infernet-asthme
 /// <summary>
 /// Predicts the outcome of a game.
 /// </summary>
 /// <param name="game">The game.</param>
 /// <param name="posteriors">The posteriors.</param>
 /// <returns>
 /// The <see cref="TwoTeamPrediction" />.
 /// </returns>
 public TwoTeamPrediction PredictOutcome(TeamGame game, Marginals posteriors)
 {
     return(new TwoTeamPrediction
     {
         Actual = game.Outcome,
         Predicted =
             this.Parameters.IncludeDraws
                 ? (TeamMatchOutcome)this.OutcomeDistribution.Sample()
                 : (Rand.Int(2) == 0 ? TeamMatchOutcome.Team1Win : TeamMatchOutcome.Team2Win),
         IncludeDraws = this.Parameters.IncludeDraws
     });
 }
コード例 #3
0
        public StatResult <Stat> AddStat(TeamGame teamGame, Player player, GameTime gameTime, StatType statType)
        {
            Stat stat = CreateGameEvent <Stat>(teamGame, gameTime);

            // Create the stat
            stat.StatTypeId = statType.Id;
            stat.StatName   = statType.StatName;
            // Id for Team and Game were already set by CreateGameEvent
            stat.Team = teamGame.Team;
            stat.Game = teamGame.Game;
            // Lineup has to exist
            stat.Lineup   = teamGame.Lineups.Last();
            stat.LineupId = stat.Lineup.Id;
            // Player could be null for Team stats
            stat.Player = player;
            if (stat.Player != null)
            {
                stat.PlayerId = stat.Player.Id;
            }
            // Possession could be null if it happens before a team estiblishes possession
            stat.Possession = teamGame.Game.Possessions.LastOrDefault();
            if (stat.Possession != null)
            {
                stat.PossessionId = stat.Possession.Id;
            }

            AddStatSummary(teamGame, stat);

            PlayerGame playerGame = teamGame.Players.FirstOrDefault(teamPlayer => teamPlayer.Player == player);

            if (playerGame == null)
            {
                throw new PlayerGameNotFoundException();
            }
            AddStatSummary(playerGame, stat);

            if (statType.WillEndPossession)
            {
                ChangePossession(teamGame.Game, gameTime);
            }

            StatResult <Stat> result = new StatResult <Stat>()
            {
                DependentStats = statType.DependentStats,
                Stat           = stat,
            };

            return(result);
        }
コード例 #4
0
        public Possession AssignPossession(Game game, TeamGame teamGame, GameTime gameTime)
        {
            Possession possession = CreateGameEvent <Possession>(teamGame, gameTime);

            Possession lastPossession = game.Possessions.LastOrDefault();

            if (lastPossession != null)
            {
                lastPossession.EndDateTime = possession.StartDateTime;
                lastPossession.EndGameTime = possession.StartGameTime;
            }

            game.Possessions.Add(possession);

            return(possession);
        }
コード例 #5
0
        public static TeamGame GetTeamGameStats(string date)
        {
            TeamGame teamGame = new TeamGame();
            var      client   = new HttpClient();

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", Ocp_Apim_Subscription_Key);

            // Id 15 - Campeonato Brasileiro
            var uri = "https://api.fantasydata.net/v3/soccer/stats/xml/TeamGameStatsByDate/" + date;

            HttpResponseMessage response = client.GetAsync(uri).Result;

            if (response.IsSuccessStatusCode)
            {
                var json = response.Content.ReadAsStringAsync().Result;
                teamGame = JsonConvert.DeserializeObject <TeamGame>(json);
            }
            return(teamGame);
        }
コード例 #6
0
        /// <summary>
        /// Create a new game
        /// </summary>
        /// <param name="homeTeam">Name of the home team</param>
        /// <param name="awayTeam">Name of the away team</param>
        /// <returns>Returns true/false if the game is created or not</returns>
        public bool StartGame(string homeTeam, string awayTeam)
        {
            TeamGame homeTeamGame = new TeamGame
            {
                Team = new Team
                {
                    TeamName = homeTeam
                },
                Score = 0
            };

            TeamGame awayTeamGame = new TeamGame
            {
                Team = new Team
                {
                    TeamName = awayTeam
                },
                Score = 0
            };

            //Check if a team is already playing a game, if is already playing one, we dont add the new game
            var teamPlaying = GetAllGames().Where(x => x.HomeTeam.Team.TeamName == homeTeamGame.Team.TeamName || x.AwayTeam.Team.TeamName == awayTeamGame.Team.TeamName);

            if (teamPlaying.Count() == 0)
            {
                _games.Add(new Game
                {
                    Id        = _idGame,
                    HomeTeam  = homeTeamGame,
                    AwayTeam  = awayTeamGame,
                    StartDate = DateTime.Now
                });

                _idGame++;
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
        private T CreateGameEvent <T>(TeamGame teamGame, GameTime gameTime) where T : DbGameEvent, new()
        {
            DateTime now = Settings.CurrentTime;

            T gameEvent = new T()
            {
                Id            = Guid.NewGuid(),
                GameId        = teamGame.Game.Id,
                TeamId        = teamGame.Team.Id,
                CreatedAt     = now,
                CreatedBy     = Settings.CurrentUser,
                UpdatedAt     = now,
                UpdatedBy     = Settings.CurrentUser,
                StartDateTime = now,
                EndDateTime   = now,
                StartGameTime = gameTime.TotalEllapsedTime,
                EndGameTime   = gameTime.TotalEllapsedTime,
            };

            return(gameEvent);
        }
コード例 #8
0
        private void InspectTeamGame(Game game, TeamGame teamGame, Team team)
        {
            Assert.IsNotNull(teamGame);
            Assert.AreEqual(team, teamGame.Team);
            Assert.AreEqual(game, teamGame.Game);

            Assert.IsNotNull(teamGame.Players);
            Assert.AreEqual(team.Players.Count, teamGame.Players.Count);
            for (var i = 0; i < team.Players.Count; i++)
            {
                Assert.IsNotNull(teamGame.Players[i].StatSummaries);
                Assert.IsNotNull(teamGame.Players[i].ShotTypeSummaries);
                Assert.IsNotNull(teamGame.Players[i].Fouls);

                Assert.AreEqual(team.Players[i], teamGame.Players[i].Player);
            }

            Assert.IsNotNull(teamGame.Fouls);
            Assert.IsNotNull(teamGame.Lineups);
            Assert.IsNotNull(teamGame.ShotTypeSummaries);
            Assert.IsNotNull(teamGame.StatSummaries);
        }
コード例 #9
0
        private TeamGame CreateTeamGame(Team team, Game game)
        {
            var teamGame = new TeamGame()
            {
                Game              = game,
                Team              = team,
                Lineups           = new List <Lineup>(),
                Fouls             = new List <Foul>(),
                ShotTypeSummaries = new Dictionary <Guid, ShotTypeSummary>(),
                StatSummaries     = new Dictionary <Guid, StatSummary>(),
            };

            teamGame.Players = team.Players.Select(player => new PlayerGame()
            {
                Fouls             = new List <Foul>(),
                Game              = game,
                Player            = player,
                ShotTypeSummaries = new Dictionary <Guid, ShotTypeSummary>(),
                StatSummaries     = new Dictionary <Guid, StatSummary>(),
            }).ToList();

            return(teamGame);
        }
コード例 #10
0
 public StatResult <Shot> AddShot(TeamGame game, Shot shot)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
 public StatResult <Stat> AddDependentStat(TeamGame game, Player player, string statName)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
        public void GameStatEngine_AddStat()
        {
            Player   player   = _homeTeam.Players.First();
            StatType statType = new StatType()
            {
                Id                 = Guid.NewGuid(),
                StatName           = "Defensive Rebound",
                WillEndPossession  = true,
                RequiresParentStat = false,
                DependentStats     = new List <StatType>(),
            };
            GameTime gameTime   = _gameManager.GetGameTime(_game);
            var      possession = _gameStatEngine.AssignPossession(_game, _game.AwayTeam, gameTime);

            Settings.CurrentTime = Settings.CurrentTime.Add(gameTime.TotalEllapsedTime);
            gameTime             = _gameManager.GetGameTime(_game);

            StatResult <Stat> statResult = _gameStatEngine.AddStat(_game.HomeTeam, player, gameTime, statType);

            Assert.AreEqual(statType.DependentStats, statResult.DependentStats);

            Stat stat = statResult.Stat;

            Assert.AreNotEqual(Guid.Empty, stat.Id);
            Assert.AreEqual(statType.StatName, stat.StatName);
            Assert.AreEqual(statType.Id, stat.StatTypeId);

            // Check that the returned stat was created properly
            Assert.AreEqual(player, stat.Player);
            Assert.AreEqual(_homeTeam, stat.Team);
            Assert.AreEqual(_game, stat.Game);
            Assert.AreEqual(_game.HomeTeam.Lineups.Last(), stat.Lineup);
            Assert.AreEqual(possession, stat.Possession);

            // Check that the player's stats were incremented properly
            PlayerGame playerGame = _game.HomeTeam.Players.FirstOrDefault(plyr => plyr.Player == player);

            Assert.AreEqual(1, playerGame.StatSummaries.Count);
            Assert.AreEqual(1, playerGame.StatSummaries[stat.StatTypeId].StatCount);
            Assert.AreEqual(statType.StatName, playerGame.StatSummaries[stat.StatTypeId].StatName);

            // Check team stats got implemented correctly
            TeamGame teamGame = _game.HomeTeam;

            Assert.AreEqual(1, teamGame.StatSummaries.Count);
            Assert.AreEqual(1, teamGame.StatSummaries[stat.StatTypeId].StatCount);
            Assert.AreEqual(statType.StatName, teamGame.StatSummaries[stat.StatTypeId].StatName);


            // Check that a new possession was added
            Assert.AreEqual(Settings.CurrentTime, possession.EndDateTime);
            Assert.AreEqual(gameTime.TotalEllapsedTime, possession.EndGameTime);
            Assert.AreEqual(2, _game.Possessions.Count);

            Possession nextPossession = _game.Possessions.Last();

            Assert.AreEqual(Settings.CurrentTime, nextPossession.StartDateTime);
            Assert.AreEqual(gameTime.TotalEllapsedTime, nextPossession.StartGameTime);
            Assert.AreEqual(_homeTeam.Id, nextPossession.TeamId);
            Assert.AreEqual(_game.Id, nextPossession.GameId);
        }
コード例 #13
0
        public void GameStatEngine_AddDependantStat()
        {
            GameTime gameTime   = _gameManager.GetGameTime(_game);
            var      possession = _gameStatEngine.AssignPossession(_game, _game.AwayTeam, gameTime);

            Player   turnoverPlayer   = _awayTeam.Players.First();
            Player   stealPlayer      = _homeTeam.Players.First();
            StatType turnoverStatType = new StatType()
            {
                Id                 = Guid.NewGuid(),
                StatName           = "Turnover",
                WillEndPossession  = true,
                RequiresParentStat = false,
                DependentStats     = new List <StatType>(),
            };
            StatType stealStatType = new StatType()
            {
                Id                 = Guid.NewGuid(),
                StatName           = "Steal",
                WillEndPossession  = false,
                RequiresParentStat = true,
                DependentStats     = new List <StatType>(),
            };

            turnoverStatType.DependentStats.Add(turnoverStatType);

            Settings.CurrentTime = Settings.CurrentTime.Add(gameTime.TotalEllapsedTime);
            gameTime             = _gameManager.GetGameTime(_game);

            StatResult <Stat> turnoverStatResult = _gameStatEngine.AddStat(_game.AwayTeam, turnoverPlayer, gameTime, turnoverStatType);

            StatResult <Stat> stealStatResult = _gameStatEngine.AddDependentStat(turnoverStatResult.Stat, _game.HomeTeam, stealPlayer, gameTime, stealStatType);

            Assert.AreEqual(turnoverStatType.DependentStats, turnoverStatResult.DependentStats);

            Stat stat = stealStatResult.Stat;

            Assert.AreNotEqual(Guid.Empty, stat.Id);
            Assert.AreEqual(stealStatType.StatName, stat.StatName);
            Assert.AreEqual(stealStatType.Id, stat.StatTypeId);

            // Check that the returned stat was created properly
            Assert.AreEqual(stealPlayer, stat.Player);
            Assert.AreEqual(_homeTeam, stat.Team);
            Assert.AreEqual(_game, stat.Game);
            Assert.AreEqual(_game.HomeTeam.Lineups.Last(), stat.Lineup);
            Assert.AreEqual(possession, stat.Possession);

            // Check that the player's stats were incremented properly
            PlayerGame playerGame = _game.HomeTeam.Players.FirstOrDefault(plyr => plyr.Player == stealPlayer);

            Assert.AreEqual(1, playerGame.StatSummaries.Count);
            Assert.AreEqual(1, playerGame.StatSummaries[stat.StatTypeId].StatCount);
            Assert.AreEqual(stealStatType.StatName, playerGame.StatSummaries[stat.StatTypeId].StatName);

            // Check team stats got implemented correctly
            TeamGame teamGame = _game.HomeTeam;

            Assert.AreEqual(1, teamGame.StatSummaries.Count);
            Assert.AreEqual(1, teamGame.StatSummaries[stat.StatTypeId].StatCount);
            Assert.AreEqual(stealStatType.StatName, teamGame.StatSummaries[stat.StatTypeId].StatName);
        }
コード例 #14
0
 public StatResult <Stat> AddDependentStat(Stat parentStat, TeamGame game, Player player, GameTime gameTime, StatType statType)
 {
     throw new NotImplementedException();
 }