private void GetPlayers(SpreadsheetsService service, SpreadsheetEntry entry, WorksheetFeed wsFeed)
        {
            int cellID = 0;
            Players = new List<Player>();

            List<CellFeed> cellFeeds = DoCellQuery(service, wsFeed, 2, 2, 2);

            for (int i = 0; i < cellFeeds.Count; i++)
            {
                CellFeed currentCellFeed = cellFeeds[i];

                if (currentCellFeed != null)
                {
                    foreach (CellEntry cell in currentCellFeed.Entries)
                    {
                        string playerList = cell.InputValue;
                        string[] playerNames = null;

                        if (!String.IsNullOrWhiteSpace(playerList))
                        {
                            playerNames = playerList.Split(',').Select(sValue => sValue.Trim()).ToArray();
                        }
                        else
                        {
                            break;
                        }

                        foreach (string playerName in playerNames)
                        {
                            if (!Players.Exists(player => player.Name == playerName))
                            {
                                Players.Add(new Player() { Name = playerName });
                            }

                            Player myPlayer = new Player();
                            myPlayer = Players.Find(player => player.Name == playerName);
                            myPlayer.GamesPlayed += 1;

                            foreach (GameEvent gameEvent in GamesPlayed)
                            {
                                if (gameEvent.Name == wsFeed.Entries[i].Title.Text && gameEvent.ID == cellID)
                                {
                                    if (gameEvent.Participants == null)
                                    {
                                        gameEvent.Participants = new List<Player>();
                                    }

                                    gameEvent.Participants.Add(myPlayer);
                                }
                            }
                        }

                        cellID++;
                    }
                }
            }

            GetWins(service, entry, wsFeed, Players);
        }
        private void GetWins(SpreadsheetsService service, SpreadsheetEntry entry, WorksheetFeed wsFeed, List<Player> Players)
        {
            int cellID = 0;
            List<CellFeed> cellFeeds = DoCellQuery(service, wsFeed, 2, 3, 3);

            for (int i = 0; i < cellFeeds.Count; i++)
            {
                CellFeed currentCellFeed = cellFeeds[i];

                if (currentCellFeed != null)
                {
                    foreach (CellEntry cell in currentCellFeed.Entries)
                    {
                        string playerList = cell.InputValue;
                        string[] playerNames = null;

                        if (!String.IsNullOrWhiteSpace(playerList))
                        {
                            playerNames = playerList.Split(',').Select(sValue => sValue.Trim()).ToArray();
                        }
                        else
                        {
                            break;
                        }

                        foreach (string playerName in playerNames)
                        {
                            string placement = null;
                            string playerNameTrimmed = null;

                            if (playerName.Contains("("))
                            {
                                placement = Regex.Match(playerName, @"\(([^)]*)\)").Groups[1].Value;
                                playerNameTrimmed = playerName.Remove(playerName.Length - 4);
                            }
                            else
                            {
                                playerNameTrimmed = playerName;
                            }

                            if (Players.Exists(player => player.Name == playerNameTrimmed))
                            {
                                Player myPlayer = new Player();
                                myPlayer = Players.Find(player => player.Name == playerNameTrimmed);
                                myPlayer.Wins += 1;

                                if (placement != null)
                                {
                                    if (myPlayer.Placement == null)
                                    {
                                        myPlayer.Placement = new List<int>();
                                    }

                                    myPlayer.Placement.Add(Int32.Parse(placement));
                                }

                                foreach (GameEvent gameEvent in GamesPlayed)
                                {
                                    if (gameEvent.Name == wsFeed.Entries[i].Title.Text && gameEvent.ID == cellID)
                                    {
                                        if (gameEvent.Winners == null)
                                        {
                                            gameEvent.Winners = new List<Player>();
                                        }

                                        gameEvent.Winners.Add(myPlayer);
                                    }
                                }
                            }
                        }

                        cellID++;
                    }
                }
            }

            foreach (Player player in Players)
            {
                player.WinPercentage = player.GetWinPercentage();
            }

            GetLosses(service, entry, wsFeed, Players);
        }
        public PlayerWindow(Player selectedPlayer, List<GameEvent> GamesPlayed)
        {
            InitializeComponent();

            string packUri = "pack://application:,,,/BoardGameStats;component/Resources/Images/";
            if (selectedPlayer.Wins >= 5 && selectedPlayer.Wins < 10)
            {
                packUri += "knight.png";
            }
            else if (selectedPlayer.Wins >= 10 && selectedPlayer.Wins < 15)
            {
                packUri += "bishop.png";
            }
            else if (selectedPlayer.Wins >= 15 && selectedPlayer.Wins < 25)
            {
                packUri += "rook.png";
            }
            else if (selectedPlayer.Wins >= 25 && selectedPlayer.Wins < 50)
            {
                packUri += "queen.png";
            }
            else if (selectedPlayer.Wins > 50)
            {
                packUri += "king.png";
            }
            else
            {
                packUri += "pawn.png";
            }

            PlayerImage.Source = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource;
            PlayerName.Text = selectedPlayer.Name;
            PlayerWins.Text = selectedPlayer.Wins.ToString();
            PlayerLosses.Text = selectedPlayer.Losses.ToString();
            PlayerGamesPlayed.Text = selectedPlayer.GamesPlayed.ToString();
            PlayerAveragePlacement.Text = selectedPlayer.AveragePlacement.ToString();
            PlayerWinPercentage.Text = selectedPlayer.WinPercentage.ToString("P");

            BestGameComboBox.SelectedIndex = 0;
            LimitComboBox.SelectedIndex = 2;
            Dictionary<string, int> winDictionary = new Dictionary<string, int>();
            Dictionary<string, int> lossDictionary = new Dictionary<string, int>();
            PlayedDictionary = new Dictionary<string, int>();

            foreach (GameEvent gameEvent in GamesPlayed)
            {
                if (gameEvent.Participants.Exists(player => player.Name == selectedPlayer.Name))
                {
                    if (!PlayedDictionary.ContainsKey(gameEvent.Name))
                    {
                        PlayedDictionary.Add(gameEvent.Name, 1);
                    }
                    else
                    {
                        PlayedDictionary[gameEvent.Name]++;
                    }
                }

                if (gameEvent.Winners != null)
                {
                    if (gameEvent.Winners.Exists(player => player.Name == selectedPlayer.Name))
                    {
                        if (!winDictionary.ContainsKey(gameEvent.Name))
                        {
                            winDictionary.Add(gameEvent.Name, 1);
                        }
                        else
                        {
                            winDictionary[gameEvent.Name]++;
                        }
                    }
                }

                if (gameEvent.Losers != null)
                {
                    if (gameEvent.Losers.Exists(player => player.Name == selectedPlayer.Name))
                    {
                        if (!lossDictionary.ContainsKey(gameEvent.Name))
                        {
                            lossDictionary.Add(gameEvent.Name, 1);
                        }
                        else
                        {
                            lossDictionary[gameEvent.Name]++;
                        }
                    }
                }

                WinPercentageDict = new Dictionary<string, double>();
                LossPercentageDict = new Dictionary<string, double>();

                foreach (KeyValuePair<string, int> gamePlayed in PlayedDictionary)
                {
                    int gameWins = 0;
                    int gameLosses = 0;
                    int gamePlayedNum = PlayedDictionary[gamePlayed.Key];
                    double gameWinPercentage = 0.0;
                    double gameLossPercentage = 0.0;

                    if (winDictionary.ContainsKey(gamePlayed.Key))
                    {
                        gameWins = winDictionary[gamePlayed.Key];
                    }
                    else
                    {
                        if (lossDictionary.ContainsKey(gamePlayed.Key))
                        {
                            gameLosses = lossDictionary[gamePlayed.Key];
                        }

                    }

                    gameWinPercentage = Math.Round((double)gameWins / (double)gamePlayedNum, 4);
                    WinPercentageDict.Add(gamePlayed.Key, gameWinPercentage);
                    gameLossPercentage = Math.Round((double)gameLosses / (double)gamePlayedNum, 4);
                    LossPercentageDict.Add(gamePlayed.Key, gameLossPercentage);
                }
            }

            CalculateGames(winDictionary, lossDictionary);

            CollectionView bestView = (CollectionView)CollectionViewSource.GetDefaultView(BestGame.ItemsSource);
            CollectionView worstView = (CollectionView)CollectionViewSource.GetDefaultView(WorstGame.ItemsSource);
            bestView.Filter = TimesPlayedFilter;
            worstView.Filter = TimesPlayedFilter;
        }