//============ Constructors =================// public GameService(int id) { _context = new Context(); _id = id; _gameStat = GameStatistic(_id, _context); _game = FetchGameByGameStatistic(_gameStat); }
private Game FetchGameByGameStatistic(GameStatistic gameStatistic) { var query = (from game in _context.Games where gameStatistic.GameRefNum == game.RefNum select game).Single(); return(query); }
/// <summary> /// Initializes a new instance of the <see cref="App"/> class. /// </summary> /// <exception cref="T:System.InvalidOperationException"> /// More than one instance of the <see cref="T:System.Windows.Application"/> class is created per <see cref="T:System.AppDomain"/>. /// </exception> public App() { settings = Settings.Create(); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!Directory.Exists(Settings.LogPath)) { Directory.CreateDirectory(Settings.LogPath); } statistics = new GameStatistic(); }
// Return statistic public GameStatistic getStatistic() { var g = new GameStatistic(); g.alive = entityes.Count; g.died = died; g.eatenMeals = eatenMeals; g.step = steps; g.mindState = mindState; g.agesSum = sumEntityAges; g.healthSum = sumEntityHealth; return(g); }
public void AddGamer(Guid userId) { GameStatistic gameStatistic = new GameStatistic { UserId = userId, AllGameWithUsers = 0, WinWithUsers = 0, LoseWithUsers = 0, AllGameWithComputer = 0, LoseWithComputer = 0, WinWithComputer = 0 }; _efUnitOfWork.GameRepository.Create(gameStatistic); }
void Awake() { // Scene transition protection for singleton if (_instance == null) { //If I am the first instance, make me the Singleton _instance = this; DontDestroyOnLoad(this); } else { //If a Singleton already exists and you find //another reference in scene, destroy it! if (this != _instance) { Destroy(this.gameObject); } } }
public void SaveStatistics(int gameId, GameStatistic statistic) { IDictionary <int, FixedSizeFiloCollection <GameStatistic> > statistics; if (!memoryCache.TryGetValue(GameStatisticsConsts.GamesStatisticsCacheKey, out statistics)) { statistics = new Dictionary <int, FixedSizeFiloCollection <GameStatistic> >(); var cacheOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromHours(24)); memoryCache.Set(GameStatisticsConsts.GamesStatisticsCacheKey, statistics, cacheOptions); } if (!statistics.ContainsKey(gameId)) { statistics.Add(gameId, new FixedSizeFiloCollection <GameStatistic>(GameStatisticsConsts.GamesStatisticsCollectionSize)); //ref updates in memory without set } statistics[gameId].Push(statistic); }
public void SetUp() { queryProcessor = new QueryProcessor(); statistic = new GameStatistic(); jsonSerializer = new JsonSerializer(); }
public GameStatisticViewModel(GameStatistic gameStatistic) { this.gameStatistic = gameStatistic; }
//============= Constructors =================// public GameViewModel(int id) { _gameService = new GameService(id); _gameStat = _gameService.GameStatistics(); }
private bool IsNotPlayedGame(GameStatistic game) { return(game.Winners == null); }
private void AddLastGamesForUpdateToDb(List <FootballGameBM> lastGamesForUpdate) { foreach (var game in lastGamesForUpdate) { var existGame = this.db .FootballGames .Where(g => (g.MatchDate.Date == game.MatchDate.Date) && (g.HomeTeam.UniqueName == game.HomeTeam.UniqueName) && (g.AwayTeam.UniqueName == game.AwayTeam.UniqueName) && (g.League.Name == game.League.Name)) .FirstOrDefault(); if (existGame == null) { // Add home team to the DB and to current game var homeTeam = this.db .Teams .Where(t => t.UniqueName == game.HomeTeam.UniqueName) .FirstOrDefault(); if (homeTeam == null) { homeTeam = new Team { Name = game.HomeTeam.Name, UniqueName = game.HomeTeam.UniqueName }; this.db.Add(homeTeam); this.db.SaveChanges(); } // Add away team to the DB and to current game var awayTeam = this.db .Teams .Where(t => t.UniqueName == game.AwayTeam.UniqueName) .FirstOrDefault(); if (awayTeam == null) { awayTeam = new Team { Name = game.AwayTeam.Name, UniqueName = game.AwayTeam.UniqueName }; this.db.Add(awayTeam); this.db.SaveChanges(); } // Add league to the DB and to current game var league = this.db .Leagues .Where(l => l.UniqueName == game.League.UniqueName) .FirstOrDefault(); if (league == null) { league = new League { Name = game.League.Name, Country = game.League.Country, Year = game.League.Year, Stage = game.League.Stage, Type = game.League.Type, UniqueName = game.League.UniqueName }; this.db.Add(league); this.db.SaveChanges(); } // Add current game existGame = new FootballGame { MatchDate = game.MatchDate, LeagueId = league.Id, League = league, HomeTeamId = homeTeam.Id, HomeTeam = homeTeam, AwayTeamId = awayTeam.Id, AwayTeam = awayTeam }; this.db.Add(existGame); this.db.SaveChanges(); league.Games.Add(existGame); this.db.SaveChanges(); } // Add full time result to the DB and to current game if (game.FullTimeResult != null) { GameResult fullTimeResult = new GameResult { Result = game.FullTimeResult.Result, HomeTeamGoals = game.FullTimeResult.HomeTeamGoals, AwayTeamGoals = game.FullTimeResult.AwayTeamGoals }; this.db.Add(fullTimeResult); this.db.SaveChanges(); existGame.FullTimeResult = fullTimeResult; existGame.FullTimeResultId = fullTimeResult.Id; } // Add first time result to the DB and to current game if (game.FirstHalfResult != null) { GameResult firstHalf = new GameResult { Result = game.FirstHalfResult.Result, HomeTeamGoals = game.FirstHalfResult.HomeTeamGoals, AwayTeamGoals = game.FirstHalfResult.AwayTeamGoals }; this.db.Add(firstHalf); this.db.SaveChanges(); existGame.FirstHalfResult = firstHalf; existGame.FirstHalfResultId = firstHalf.Id; } // Add game statistic to the DB and to current game if (game.GameStatistic != null) { GameStatistic gameStatistic = new GameStatistic { HomeTeamCorners = game.GameStatistic.HomeTeamCorners, AwayTeamCorners = game.GameStatistic.AwayTeamCorners, HomeTeamShotsOnTarget = game.GameStatistic.HomeTeamShotsOnTarget, AwayTeamShotsOnTarget = game.GameStatistic.AwayTeamShotsOnTarget, HomeTeamShotsWide = game.GameStatistic.HomeTeamShotsWide, AwayTeamShotsWide = game.GameStatistic.AwayTeamShotsWide, HomeTeamFouls = game.GameStatistic.HomeTeamFouls, AwayTeamFouls = game.GameStatistic.AwayTeamFouls, HomeTeamOffsides = game.GameStatistic.HomeTeamOffsides, AwayTeamOffsides = game.GameStatistic.AwayTeamOffsides }; this.db.Add(gameStatistic); this.db.SaveChanges(); existGame.GameStatistic = gameStatistic; existGame.GameStatisticId = gameStatistic.Id; } this.db.SaveChanges(); } }
private void AddOldGamesToDb(List <FootballGameBM> lastGamesForUpdate) { foreach (var game in lastGamesForUpdate) { this.db.ChangeTracker.AutoDetectChangesEnabled = false; // Add home team to the DB and to current game var homeTeam = this.db .Teams .Where(t => t.UniqueName == game.HomeTeam.UniqueName) .FirstOrDefault(); if (homeTeam == null) { homeTeam = new Team { Name = game.HomeTeam.Name, UniqueName = game.HomeTeam.UniqueName }; this.db.AddRange(homeTeam); this.db.SaveChanges(); } // Add away team to the DB and to current game var awayTeam = this.db .Teams .Where(t => t.UniqueName == game.AwayTeam.UniqueName) .FirstOrDefault(); if (awayTeam == null) { awayTeam = new Team { Name = game.AwayTeam.Name, UniqueName = game.AwayTeam.UniqueName }; this.db.AddRange(awayTeam); this.db.SaveChanges(); } // Add league to the DB and to current game var league = this.db .Leagues .Where(l => l.UniqueName == game.League.UniqueName) .FirstOrDefault(); if (league == null) { league = new League { Name = game.League.Name, Country = game.League.Country, Year = game.League.Year, Stage = game.League.Stage, Type = game.League.Type, UniqueName = game.League.UniqueName }; this.db.AddRange(league); this.db.SaveChanges(); } GameResult fullTimeResult = null; if (game.FullTimeResult != null) { fullTimeResult = new GameResult { Result = game.FullTimeResult.Result, HomeTeamGoals = game.FullTimeResult.HomeTeamGoals, AwayTeamGoals = game.FullTimeResult.AwayTeamGoals }; this.db.AddRange(fullTimeResult); this.db.SaveChanges(); } GameResult firstHalf = null; // Add first time result to the DB and to current game if (game.FirstHalfResult != null) { firstHalf = new GameResult { Result = game.FirstHalfResult.Result, HomeTeamGoals = game.FirstHalfResult.HomeTeamGoals, AwayTeamGoals = game.FirstHalfResult.AwayTeamGoals }; this.db.AddRange(firstHalf); this.db.SaveChanges(); } GameStatistic gameStatistic = null; // Add game statistic to the DB and to current game if (game.GameStatistic != null) { gameStatistic = new GameStatistic { HomeTeamCorners = game.GameStatistic.HomeTeamCorners, AwayTeamCorners = game.GameStatistic.AwayTeamCorners, HomeTeamShotsOnTarget = game.GameStatistic.HomeTeamShotsOnTarget, AwayTeamShotsOnTarget = game.GameStatistic.AwayTeamShotsOnTarget, HomeTeamShotsWide = game.GameStatistic.HomeTeamShotsWide, AwayTeamShotsWide = game.GameStatistic.AwayTeamShotsWide, HomeTeamFouls = game.GameStatistic.HomeTeamFouls, AwayTeamFouls = game.GameStatistic.AwayTeamFouls, HomeTeamOffsides = game.GameStatistic.HomeTeamOffsides, AwayTeamOffsides = game.GameStatistic.AwayTeamOffsides }; this.db.AddRange(gameStatistic); this.db.SaveChanges(); } // Add current game var existGame = new FootballGame { MatchDate = game.MatchDate, League = league, HomeTeam = homeTeam, AwayTeam = awayTeam, FullTimeResult = fullTimeResult, FirstHalfResult = firstHalf, GameStatistic = gameStatistic }; this.db.AddRange(existGame); this.db.SaveChanges(); // Add full time result to the DB and to current game this.db.SaveChanges(); } }
public void AddStatsForEachPlayers(GameStatistic gameStatsData) { _context.GameStatistics.Add(gameStatsData); _context.SaveChanges(); }
public async Task <IActionResult> GetMatchData(string url, int id, int team1Id, int team2Id, int TournamentId, int TournamentLevel) { // ------------------------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------------------------ // --------------------- Test pobieranie spreparowanego pliku json, o nazwie game(url).json [url od 1 do 28] -------------------- // -------------------------------------- https://localhost:44344/PreparedGames/game1.json -------------------------------------- // ------------------------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------------------------ //var cuttedUrl = url.Substring(69, 10); //var matchId = Int32.Parse(cuttedUrl); //int liczbaGraczy = 10; var cuttedUrl = url; var matchId = Int32.Parse(cuttedUrl); int liczbaGraczy = 2; if (_matchRepository.Matches.Where(m => m.gameid == matchId).Any()) { // Mecz o tym id znajduje się już w bazie. return(RedirectToAction("Index")); } MatchDto result = null; // mecze testowe przyjmują wartość ID nie większą niż 2k, reszta to dane z RiotGamesAPI if (matchId > 1000 && matchId < 20000) { // Wygenerowanie losowych wartości dla meczu x, z druzyna 1 i 2 result = _riotApiService.CreateAndReturnMatchDataBasedOnId(matchId, team1Id, team2Id); } else { // pobranie danych z RiotGamesAPI result = await _riotApiService.GetMatchDataBasedOnId(Int32.Parse(cuttedUrl)); } // musze to wrzucić do interfejsu, potem przemapowane dane {tylko intersujące nas dane} są zapisywane w bazie // mimo to i tak potem jeszcze rozdzielam je dla drużyn i graczy MatchSelectedData newMatch5v5 = new MatchSelectedData { gameid = result.gameid, seasonId = result.seasonId, queueId = result.queueId, gameType = result.gameType, participantIdentities = result.participantIdentities .Select(i => new ParticipantIdentity { participantId = i.participantId, playerInfo = new PlayerInfo { participantId = i.participantId, summonerName = i.player.summonerName, platformId = i.player.platformId, currentAccountId = i.player.currentAccountId, summonerId = i.player.summonerId, accountId = i.player.accountId } }).ToList(), gameDuration = result.gameDuration, gameMode = result.gameMode, mapId = result.mapId, participants = result.participants .Select(p => new Participant { participantId = p.participantId, teamId = p.teamId, highestAchievedSeasonTier = p.highestAchievedSeasonTier, championId = p.championId, spell1Id = p.spell1Id, spell2Id = p.spell2Id, stats = new Stats { ParticipantId = p.stats.ParticipantId, Kills = p.stats.Kills, Deaths = p.stats.Deaths, Assists = p.stats.Assists, Win = p.stats.Win } }).ToList() }; //zapisywanie danych pobranych z RiotAPI do lokalnej bazy, musze się zastanowić czy to jest mi wogole potrzebne na stałe w bazie czy nie lepiej cały czas pytać o to api _matchRepository.SaveMatch(newMatch5v5); // Pętla uaktualniająca baze dla wszystkich graczy biorących udział w grze for (int INDEX = 1; INDEX <= liczbaGraczy; INDEX++) { long SummonerId = newMatch5v5.participantIdentities.Where(p => p.participantId == INDEX) .Select(p => p.playerInfo.summonerId) .FirstOrDefault(); int ParticipantId = newMatch5v5.participantIdentities .Where(p => p.participantId == INDEX) .Where(p => p.playerInfo.summonerId == SummonerId) .Select(p => p.participantId) .FirstOrDefault(); GameStatistic gameStatistic = new GameStatistic { MatchSelectedData = _matchRepository.Matches .Where(m => m.Id == newMatch5v5.Id).First(), Win = newMatch5v5.participants .Where(p => p.participantId == ParticipantId) .Select(p => p.stats.Win).First(), SummonerName = newMatch5v5.participantIdentities .Where(p => p.participantId == ParticipantId) .Select(p => p.playerInfo.summonerName).First(), SummonerId = newMatch5v5.participantIdentities .Where(p => p.participantId == ParticipantId) .Select(p => p.playerInfo.summonerId).First(), AccountId = newMatch5v5.participantIdentities .Where(p => p.participantId == ParticipantId) .Select(p => p.playerInfo.accountId).First(), Summoner = _repository.SummonerInfos .Where(p => p.id == newMatch5v5.participantIdentities .Where(m => m.participantId == ParticipantId) .Select(s => s.playerInfo.summonerId).First()) .First(), Kills = newMatch5v5.participants .Where(p => p.participantId == ParticipantId) .Select(p => p.stats.Kills).First(), Deaths = newMatch5v5.participants .Where(p => p.participantId == ParticipantId) .Select(p => p.stats.Deaths).First(), Assists = newMatch5v5.participants .Where(p => p.participantId == ParticipantId) .Select(p => p.stats.Assists).First(), ChampionId = newMatch5v5.participants .Where(p => p.participantId == ParticipantId) .Select(p => p.championId).First(), TeamId = newMatch5v5.participants .Where(p => p.participantId == ParticipantId) .Select(p => p.teamId).First(), GameMode = newMatch5v5.gameMode, GameId = newMatch5v5.gameid, GameDuration = newMatch5v5.gameDuration, DatePlayed = DateTime.Now }; //iteracyjne dodawanie statystyk dla każdego gracza biorącego udział w meczu, posiadającego konto w LOLHaven _matchRepository.AddStatsForEachPlayers(gameStatistic); } //Przekierowanie do akcji aktualizującej statystyki return(RedirectToAction("UploadGameStats", "Tournament", new { id, team1Id, team2Id, TournamentId, TournamentLevel })); }