Example #1
0
        // Stores personal history in a dictionary.
        public void StorePersonalHistory(String summonerName, TextBox status)
        {
            String summonerIdUrl  = Coder.GetSummonerIdUrl(region, summonerName);
            String summonerIdJson = reader.Request(summonerIdUrl);
            String summonerId     = Parser.GetSummonerId(summonerIdJson);

            int matchNumber = 0;

            // loops until there is no more match history
            while (true)
            {
                String matchHistoryUrl  = Coder.GetMatchHistoryUrl(region, summonerId, matchNumber, matchNumber + MATCH_SEARCH_LIMIT);
                String matchHistoryJson = reader.Request(matchHistoryUrl);

                // there is no more match history
                if (matchHistoryJson.Equals("{}") | matchHistoryJson.Equals(""))
                {
                    break;
                }

                MatchHistory matchHistory = Parser.ParseMatchHistory(matchHistoryJson);

                status.Text = (matchNumber + matchHistory.matches.Count) + " games found";
                status.Refresh();

                foreach (MatchHistoryNameSpace.Match match in matchHistory.matches)
                {
                    MatchHistoryNameSpace.Participant participant = match.participants[0];
                    personalHistory[match.matchId] = new PersonalParticipant(match.participants[0].teamId, participant.stats.winner, participant.championId);
                }

                matchNumber += MATCH_SEARCH_LIMIT;
            }
        }
Example #2
0
        // Event: go is clicked. Gets data for summoner and region and displays
        //        it in data.
        private void go_Click(object sender, EventArgs e)
        {
            personalWin.Text = String.Empty;
            personalWin.Refresh();

            status.Text = String.Empty;
            status.Refresh();

            data.DataSource = null;
            data.Refresh();

            int n;
            int minGamesInt = (int.TryParse(minGames.Text, out n)) ? n : MIN_GAME_DEFAULT;

            minGames.Text = minGamesInt.ToString();
            minGames.Refresh();

            String regionLower = region.Text.ToLower();

            model = new Model(regionLower);
            String summonerIdUrl = Coder.GetSummonerIdUrl(regionLower, summoner.Text);

            // invalid summoner name and or region
            if (model.reader.Request(summonerIdUrl).Equals(String.Empty))
            {
                System.Windows.Forms.MessageBox.Show("invalid summoner name and or region");
                return;
            }

            String summonerIdJson = model.reader.Request(summonerIdUrl);

            model.StorePersonalHistory(summoner.Text, status);
            model.StoreGlobalHistory(status);
            model.CalcChampionStats();
            model.CalcWinRates();
            isLoaded = true;
            minGames_KeyPress(String.Empty, new KeyPressEventArgs((char)ENTER));

            double personalWinRate = model.CalcPersonalWinRate();

            if (double.IsNaN(personalWinRate))
            {
                personalWin.Text = "no ranked games played";
            }
            else
            {
                personalWin.Text = "personal win rate: " + personalWinRate.ToString("0.#") + "%";
            }

            personalWin.Refresh();

            status.Text = "done with " + model.CountMatches() + " games";
            status.Refresh();
        }