public void CalculateNonTeam(List <PlayerStats> opponentsList, playerSearch opponent, playerSearch Self) { var opponentUpdate = opponentsList.FirstOrDefault(x => x.Name == opponent.Name); if (opponent.Winner == null && Self.Winner == null) { return; } else if (opponent.Winner.Value && Self.Winner.Value) { opponentUpdate.Ties = ++opponentUpdate.Ties; } else if (!opponent.Winner.Value && Self.Winner.Value) { opponentUpdate.Losses = ++opponentUpdate.Losses; } else if (opponent.Winner.Value && !Self.Winner.Value) { opponentUpdate.Wins = ++opponentUpdate.Wins; } else { opponentUpdate.SharedLoss = ++opponentUpdate.SharedLoss; } }
private static void GetPlayerValues(List <Player> playerSearch, List <playerSearch> pSearchResults) { foreach (var player in playerSearch) { var addMe = new playerSearch(player.Id, player.Name); pSearchResults.Add(addMe); } }
private static void PlayerSearchExtraction(List <Player> playerSearch, List <playerSearch> pSearchResults) { foreach (var player in playerSearch) { playerSearch addMe = new playerSearch(player.Id, player.Name); pSearchResults.Add(addMe); } }
public ActionResult GetPlayerStats(int id) { try { var searchplayer = db.Players.FirstOrDefault(x => x.Id == id); playerSearch playerRequest = new playerSearch(searchplayer.Id, searchplayer.Name); var PlayerStats = GetPlaySessionsByPlayer(id); List <PlaySessionData> ReturnedStats = ExtractPlaySessionsData(PlayerStats, playerRequest); var PSStatsList = Stats.AnalyzePlayStats(ReturnedStats, playerRequest); var PlayerRelations = Stats.RelationsLabler(PSStatsList); var BGStatsList = Stats.CalculateBGStats(ReturnedStats, playerRequest); var BGRecords = Stats.PlayerBoardGameAwards(BGStatsList); return(Json(new { PSStatsList, BGStatsList, BGRecords, PlayerRelations }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "failed finding stats" + e)); } }
public void CalculateNemisis(List <PlayerStats> opponentsList, playerSearch opponent) { if (opponent.Winner == null) { return; } if (opponent.Winner.Value) { var opponentUpdate = opponentsList.FirstOrDefault(x => x.Name == opponent.Name); opponentUpdate.Wins = ++opponentUpdate.Wins; opponentUpdate.OpponentWin = ++opponentUpdate.OpponentWin; } else { var opponentUpdate = opponentsList.FirstOrDefault(x => x.Name == opponent.Name); opponentUpdate.Losses = ++opponentUpdate.Losses; opponentUpdate.OpponentLoss = ++opponentUpdate.OpponentLoss; } }
public void ParsePlayersIntoTeams(playerSearch teamMate, List <Team> teams) { if (teams.Count == 0) { Team addTeam = new Team(); List <playerSearch> startPlayerList = new List <playerSearch>(); startPlayerList.Add(teamMate); if (teamMate.Team.HasValue) { addTeam.Name = teamMate.Team.Value; } addTeam.TeamMates = startPlayerList; if (teamMate.Winner.HasValue) { addTeam.Winner = teamMate.Winner.Value; } teams.Add(addTeam); return; } foreach (var team in teams) { if (team.Name == teamMate.Team) { List <playerSearch> curTeam = team.TeamMates; curTeam.Add(teamMate); team.TeamMates = curTeam; return; } } Team nonExsistantTeam = new Team(); List <playerSearch> nonExsistantPlayerList = new List <playerSearch>(); if (teamMate.Winner.HasValue) { nonExsistantTeam.Winner = teamMate.Winner.Value; } nonExsistantPlayerList.Add(teamMate); nonExsistantTeam.TeamMates = nonExsistantPlayerList; nonExsistantTeam.Winner = teamMate.Winner.Value; teams.Add(nonExsistantTeam); return; }
public List <playerSearch> GetPlayersSearch(List <Participant> participants) { List <playerSearch> playerSearchList = new List <playerSearch>(); foreach (var participant in participants) { var currPlayer = db.Players.Where(x => x.Id == participant.Player_Id).FirstOrDefault(); playerSearch newPlayer = new playerSearch(currPlayer.Id, currPlayer.Name); if (participant.Winner.HasValue) { newPlayer.Winner = participant.Winner.Value; } if (participant.Team.HasValue) { newPlayer.Team = participant.Team.Value; } playerSearchList.Add(newPlayer); } return(playerSearchList); }
public List <PlayerStats> AnalyzeBGPlayStats(List <PlaySessionData> playSessions, playerSearch self) { List <PlayerStats> statsList = new List <PlayerStats>(); foreach (var playSession in playSessions) { var selfPS = new playerSearch(self.Id, self.Name); selfPS.Team = 0; selfPS.Winner = playSession.Participants.Where(x => x.Name == self.Name).Select(x => x.Winner) .FirstOrDefault(); var playerTeam = playSession.Participants.Where(x => x.Name == self.Name).Select(x => x.Team).FirstOrDefault(); var players = playSession.Participants; foreach (var player in players) { if (player.Name == self.Name) { var newStats = new PlayerStats(player.Id, player.Name); statsList.Add(newStats); } if (!statsList.Any(x => x.Name == player.Name)) { continue; } var opponentUpdate = statsList.FirstOrDefault(x => x.Name == player.Name); opponentUpdate.Plays = ++opponentUpdate.Plays; if (playerTeam == 0) { CalculateNonTeam(statsList, player, selfPS); } else if (playerTeam != player.Team) { CalculateNemisis(statsList, player); } else { CalculateAlly(statsList, player); } } } return(statsList); }
public ActionResult GetBGPlayStats(int GameId) { try { var myId = GetUserId(); var selfData = db.Players.FirstOrDefault(x => x.AspNetUser_Id == myId); playerSearch Self = new playerSearch(selfData.Id, selfData.Name); List <PlaySession> relatedPlayers = db.PlaySessions.Where(x => x.BoardGameId == GameId).ToList(); List <PlaySessionData> ReturnedStats = ExtractPlaySessionsData(relatedPlayers, Self); var playerStats = Stats.AnalyzePlayStats(ReturnedStats, Self); var nulPlayer = new playerSearch(0, null); var SelfBGStats = Stats.AnalyzePlayStats(ReturnedStats, Self); var BGRecordStats = Stats.AnalyzePlayStats(ReturnedStats, nulPlayer); var BGPlayerRelations = Stats.RelationsLabler(BGRecordStats); var totalPlays = ReturnedStats.Count; return(Json(new { SelfBGStats, ReturnedStats, totalPlays, BGPlayerRelations }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "failed finding stats" + e)); } }
public List <PlaySessionData> ExtractPlaySessionsData(List <PlaySession> PlayerStats, playerSearch player) { List <PlaySessionData> ReturnedStats = new List <PlaySessionData>(); foreach (var evalPlaySession in PlayerStats) { var Participants = db.Participants.Where(x => x.PlaySession_Id == evalPlaySession.Id).ToList(); var players = GetPlayersSearch(Participants); if (evalPlaySession.BoardGame == null) { evalPlaySession.BoardGame = db.BoardGames.FirstOrDefault(x => x.Id == evalPlaySession.BoardGameId); } PlaySessionData currPlaysession = new PlaySessionData(evalPlaySession.BoardGame, players, evalPlaySession.PlayTime, evalPlaySession.DatePlayed.ToString()); if (evalPlaySession.BoardGame.Teams != null) { List <Team> psTeams = new List <Team>(); foreach (var teamMates in players) { ParsePlayersIntoTeams(teamMates, psTeams); currPlaysession.Teams = psTeams; } } ReturnedStats.Add(currPlaysession); } return(ReturnedStats); }
public List <BGStats> CalculateBGStats(List <PlaySessionData> PlaySessionsStats, playerSearch Player) { var BGStatsList = new List <BGStats>(); foreach (var currPlaySessionData in PlaySessionsStats) { if (!BGStatsList.Any(x => x.Id == currPlaySessionData.BoardGame.Id)) { var newBGSTATS = new BGStats(currPlaySessionData.BoardGame.Id, currPlaySessionData.BoardGame.Name); BGStatsList.Add(newBGSTATS); } List <PlaySessionData> singletonSearch = new List <PlaySessionData>(); singletonSearch.Add(currPlaySessionData); var Sorted = AnalyzeBGPlayStats(singletonSearch, Player); if (Sorted.Count == 1) { RecordBGUpdate(BGStatsList, Sorted[0], currPlaySessionData.BoardGame.Id); } } return(BGStatsList); }