Пример #1
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();
        }
Пример #2
0
        public Model(String region)
        {
            reader      = new Reader();
            this.region = region;

            // populate championNames
            String          champions   = reader.Request(Coder.GetChampionNamesUrl(region));
            Regex           regexId     = new Regex("\"id\":(\\d+)");
            MatchCollection idMatches   = regexId.Matches(champions);
            Regex           regexName   = new Regex("\"name\":\"([^\"]+)\"");
            MatchCollection nameMatches = regexName.Matches(champions);

            for (int i = 0; i < idMatches.Count; i++)
            {
                int    id   = Convert.ToInt32(idMatches[i].Groups[1].Value);
                String name = nameMatches[i].Groups[1].Value;
                championNames[id] = name;
            }
        }
Пример #3
0
        // Stores global history in a dictionary.
        public void StoreGlobalHistory(TextBox status)
        {
            int matchCount = 1;

            foreach (int matchId in personalHistory.Keys)
            {
                status.Text = "Found all games. Loading game data " + matchCount + "/" + personalHistory.Keys.Count + ".";
                status.Refresh();
                String    matchInfoUrl  = Coder.GetMatchInfoUrl(region, matchId);
                String    matchInfoJson = reader.Request(matchInfoUrl);
                MatchInfo matchInfo     = Parser.ParseMatchInfo(matchInfoJson);
                globalHistory[matchId] = new List <GlobalParticipant>();

                foreach (MatchInfoNameSpace.Participant participant in matchInfo.participants)
                {
                    globalHistory[matchId].Add(new GlobalParticipant(participant.teamId, participant.stats.winner, participant.championId));
                }

                matchCount += 1;
            }
        }