BenFradet / RiotSharp

C# wrapper for the Riot Games API
http://benfradet.github.io/RiotSharp/
MIT License
300 stars 145 forks source link

Most Played Champion in ranked #81

Closed Coltsbro closed 9 years ago

Coltsbro commented 10 years ago

Hi.

I'm having issues with getting the most played champion in ranked and displaying it. Could you help me out here? I know its kind of a mess, but I've been trying to play around with the api and found myself stuck and honestly don't know how to do it. Thanks.

    private void mostPlayed()
    {
        string input = txtSummonerName.Text;
        var api = RiotApi.GetInstance(devKey);
        var champion = api.GetChampions(RiotSharp.Region.na);
        var most = 0;
        var champid = 0;
        int count = 0;
        bool finished = false;

        try
        {
            var playerStats = api.GetStatsRanked(RiotSharp.Region.na, player.id , RiotSharp.StatsEndpoint.Season.Season4);
            foreach (var stat in playerStats)
            {
                int champcount = champion.Count();
                stat.ChampionId = 0;

                if(finished == true)
                {
                    break;
                }
                foreach (var champ in champion)
                {
                    if (count > champcount)
                    {
                        finished = true;
                        break;
                    }

                    var rankedGamesPlayed = stat.Stats.RankedSoloGamesPlayed + stat.Stats.RankedPremadeGamesPlayed;

                    if (rankedGamesPlayed < most)
                    {
                        champid = stat.ChampionId;
                    }

                    else
                    {
                        most = rankedGamesPlayed;
                        stat.ChampionId++;
                        count++;
                    }

                }

                txtMostPlayed.Text = champid.ToString();
                lstShow.Items.Add(stat.Stats.ToString());

            }

        }
        catch(RiotSharpException ex)
        {
            MessageBox.Show(ex.Message);
            return;
        }
    }
BenFradet commented 10 years ago

Sure, I'll have a look in the morning. In the meantime, have a look at linq, it should help you with what you're trying to accomplish.

Coltsbro commented 10 years ago

I'm also having problems getting a player summary. Here's what I have so far.

    private void statSummary()
    {
        var api = RiotApi.GetInstance(devKey);
        string input = txtSummonerName.Text;
        var summoner = api.GetSummoner(RiotSharp.Region.na, input);
        var rankedGamesPlayed = api.GetStatsRanked(RiotSharp.Region.na, summoner.Id, RiotSharp.StatsEndpoint.Season.Season4);

        foreach(var played in rankedGamesPlayed)
        {

            lstShow.Items.Add(played.Stats.RankedSoloGamesPlayed).ToString();
        }
        //summoner.GetStatsRanked();
        var playerLeague = summoner.GetLeagues();

    }

Whenever I run it, and go for the ranked games played, it always shows up as 0 (which is false). Also, I have no idea how to display the player league in the list box. Thanks so much for the help, and sorry if I'm bugging you. I'm trying to (re)teach myself C# and getting used to using API's and all that.

Coltsbro commented 10 years ago

Hey, this worked! Thanks so much! Any idea on why I'm getting 0's for ranked stats in my second post?

BenFradet commented 10 years ago

I'm not sure the previous solution was working properly. I'm working on a new solution.

Coltsbro commented 10 years ago

Yea, I actually just tested it and it was showing the wrong champion as the most played, but it's more than I had before lol.

BenFradet commented 10 years ago
var championIds = new List<int>();
for (int i = 0; i < 30; i += 15)
{
    var matches = api.GetMatchHistory(Region.euw, id, i, i + 15, null,
        new List<Queue>() { Queue.RankedSolo5x5 });
    foreach (var match in matches)
    {
        championIds.Add(match.Participants[0].ChampionId);
    }
}
var mostPlayedChampId = championIds.
    GroupBy(c => c).
    OrderByDescending(g => g.Count()).
    FirstOrDefault().Key;
var mostPlayedChamp = staticApi.GetChampion(Region.euw, mostPlayedChampId);
Console.WriteLine(mostPlayedChamp.Name);

The problem is you can only go so far in the history, for me it was around 40, so it's only the most played champ during the last 40 games.

Coltsbro commented 10 years ago

It is working! I'm still struggling with actually getting ranked stats to show though. Everytime I try it just shows all stats as 0. Is it also an issue with only being able to go back 40 games or so?

BenFradet commented 10 years ago

I don't have any issues with ranked stats, I'll check back later during the day.

Coltsbro commented 10 years ago

Ok. Here's what I'm using to pull the stats for the most played champ:

            var mostPlayedStats = api.GetStatsRanked(RiotSharp.Region.na, player.id, RiotSharp.StatsEndpoint.Season.Season4);
            var mostPlayedStatsSeason3 = api.GetStatsRanked(RiotSharp.Region.na, player.id, RiotSharp.StatsEndpoint.Season.Season3);

            foreach(var c in mostPlayedStats)
            {
                if(c.ChampionId == mostPlayedChampId)
                {
                    lstShow.Items.Add(c.Stats.AverageChampionsKilled.ToString());
                    lstShow.Items.Add(c.Stats.AverageNumDeaths.ToString());
                    lstShow.Items.Add(c.Stats.AverageAssists.ToString());

                    int kda = 0;
                        if(c.Stats.AverageNumDeaths == 0)
                        {
                            kda = (c.Stats.AverageChampionsKilled + c.Stats.AverageAssists);
                        }
                        else
                            kda = (c.Stats.AverageChampionsKilled + c.Stats.AverageAssists) / c.Stats.AverageNumDeaths;

                    lstShow.Items.Add(kda.ToString());
                    break;
                }

            }

Thanks again!

BenFradet commented 9 years ago

I'm looking at the number of RankedSoloGamesPlayed and I have been able to reproduce the issue, I'm looking into it right now.

BenFradet commented 9 years ago

Yeah, as I thought it always gives back 0 because it's either not present in the data being retrieved or is actually zero. So, it doesn't come from the wrapper but from Riot.

Coltsbro commented 9 years ago

Hmmm, so there's really no solution to this problem then? Because I can assure you people I tested with this do not have 0 ranked games played.

BenFradet commented 9 years ago

Compare what you would get from the API directly with what you get from the wrapper but personnally I get the exact same results.

Coltsbro commented 9 years ago

I figured it out. I looked at the documentation and saw that the AverageKills, AverageDeaths, etc were from Dominion only, so I wouldn't have any data from that. Thanks a lot for your help!

BenFradet commented 9 years ago

No problem.