Introduction

In a previous Notebook, we did an exploration of the Codingame LeaderBoard. After a discussion regarding programming languages, I wanted to take a look at the use of them on Codingame Contest. To do so, we will extract few datas from the last 8 contest and look at the use and score for languages.

Extraction

The Leaderbord API changed on Codingame not a long time ago and provide ranking by 1k player but there is no pâge anymore. To extract those datas, we will query the result for every league of the 9 last contest. This is beacuse there is never 1k person in a specific league.

In [69]:
import json
from bson import json_util

import numpy as np
import pandas as pd

import urllib

from collections import defaultdict

import matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

%matplotlib inline

cmap = matplotlib.cm.get_cmap('nipy_spectral')
In [2]:
challenges = [
    "code-of-kutulu",
    "code-royale",
    "botters-of-the-galaxy",
    "mean-max",
    "wondev-woman",
    "coders-of-the-caribbean",
    "ghost-in-the-cell",
    "hypersonic",
    "codebusters"
]

leagues = [
    "LEGEND",
    "gold",
    "silver",
    "bronze",
]

You can see below the json of 1 line of the leaderboard. We will keep on this only few information (some of them won't be used but will be available if needed).

In [3]:
url = "https://www.codingame.com/services/LeaderboardsRemoteService/getFilteredChallengeLeaderboard"
data = '["code-of-kutulu",null,"global",{"active":false,"column":"","filter":""}]'
data = data.encode('utf-8')
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
content = response.read()
parsed_content = json.loads(content)

parsed_content['success']["users"][0]
Out[3]:
{'agentId': 1929755,
 'codingamer': {'avatar': 19518608272427,
  'category': 'STUDENT',
  'countryId': 'SK',
  'enable': False,
  'level': 12,
  'pseudo': 'blasterpoard',
  'publicHandle': '47a1a3e98084996d79f00ad195cf67d57867752',
  'schoolId': 168,
  'userId': 2577687,
  'userValid': False},
 'creationTime': 1529868138876,
 'eligibleForPromotion': False,
 'inProgress': False,
 'league': {'divisionCount': 7, 'divisionIndex': 6, 'openingLeaguesCount': 0},
 'localRank': 1,
 'percentage': 100,
 'programmingLanguage': 'C++',
 'progress': 'EQUAL',
 'pseudo': 'blasterpoard',
 'rank': 1,
 'school': 'Masaryk University',
 'score': 34.35,
 'testSessionHandle': '11806064280972e101cb4be732d6364769a959b1',
 'updateTime': 1529941519894}
In [4]:
ranking = defaultdict(list)

for challenge in challenges:
    for league in leagues:
        url = "https://www.codingame.com/services/LeaderboardsRemoteService/getFilteredChallengeLeaderboard"
        data = '["'+challenge+'",null,"global",{"active":true,"column":"SLEAGUE","filter":"'+league+'"}]'
        data = data.encode('utf-8')
        print("Fetchind data from {} in league {}".format(challenge, league))
        req = urllib.request.Request(url, data)
        response = urllib.request.urlopen(req)
        content = response.read()
        parsed_content = json.loads(content)
        if "success" in parsed_content.keys():
            for user in parsed_content["success"]["users"]:
                ranking["challenge"].append(challenge)
                ranking["league"].append(league)
                ranking["agentId"].append( user.get("agentId", np.nan) )
                ranking["level"].append(user["codingamer"].get("level", np.nan))
                ranking["pseudo"].append(user["codingamer"].get("pseudo", np.nan))
                ranking["userId"].append(user["codingamer"].get("userId", np.nan))
                ranking["rank"].append(user.get("rank", np.nan))
                ranking["programmingLanguage"].append(user.get("programmingLanguage", np.nan))
                ranking["score"].append(user.get("score", np.nan))
        else:
            print("Error :(")
Fetchind data from code-of-kutulu in league LEGEND
Fetchind data from code-of-kutulu in league gold
Fetchind data from code-of-kutulu in league silver
Fetchind data from code-of-kutulu in league bronze
Fetchind data from code-royale in league LEGEND
Fetchind data from code-royale in league gold
Fetchind data from code-royale in league silver
Fetchind data from code-royale in league bronze
Fetchind data from botters-of-the-galaxy in league LEGEND
Fetchind data from botters-of-the-galaxy in league gold
Fetchind data from botters-of-the-galaxy in league silver
Fetchind data from botters-of-the-galaxy in league bronze
Fetchind data from mean-max in league LEGEND
Fetchind data from mean-max in league gold
Fetchind data from mean-max in league silver
Fetchind data from mean-max in league bronze
Fetchind data from wondev-woman in league LEGEND
Fetchind data from wondev-woman in league gold
Fetchind data from wondev-woman in league silver
Fetchind data from wondev-woman in league bronze
Fetchind data from coders-of-the-caribbean in league LEGEND
Fetchind data from coders-of-the-caribbean in league gold
Fetchind data from coders-of-the-caribbean in league silver
Fetchind data from coders-of-the-caribbean in league bronze
Fetchind data from ghost-in-the-cell in league LEGEND
Fetchind data from ghost-in-the-cell in league gold
Fetchind data from ghost-in-the-cell in league silver
Fetchind data from ghost-in-the-cell in league bronze
Fetchind data from hypersonic in league LEGEND
Fetchind data from hypersonic in league gold
Fetchind data from hypersonic in league silver
Fetchind data from hypersonic in league bronze
Fetchind data from codebusters in league LEGEND
Fetchind data from codebusters in league gold
Fetchind data from codebusters in league silver
Fetchind data from codebusters in league bronze

Now we can create the dataset and save it for exploration

In [5]:
df = pd.DataFrame(ranking)
df.to_csv("ranking.csv", index=False )
del ranking
In [6]:
df.head()
Out[6]:
agentId challenge league level programmingLanguage pseudo rank score userId
0 1929755 code-of-kutulu LEGEND 12 C++ blasterpoard 1 34.35 2577687
1 1932387 code-of-kutulu LEGEND 42 C++ Agade 2 33.53 735910
2 1929753 code-of-kutulu LEGEND 27 C++ y_kawano 3 32.89 610934
3 1929726 code-of-kutulu LEGEND 23 C# MSmits 4 32.46 2522090
4 1932175 code-of-kutulu LEGEND 35 C# Illedan 5 32.46 1378958

Exploration

In [9]:
df = pd.read_csv("ranking.csv")
In [10]:
df.head()
Out[10]:
agentId challenge league level programmingLanguage pseudo rank score userId
0 1929755 code-of-kutulu LEGEND 12 C++ blasterpoard 1 34.35 2577687
1 1932387 code-of-kutulu LEGEND 42 C++ Agade 2 33.53 735910
2 1929753 code-of-kutulu LEGEND 27 C++ y_kawano 3 32.89 610934
3 1929726 code-of-kutulu LEGEND 23 C# MSmits 4 32.46 2522090
4 1932175 code-of-kutulu LEGEND 35 C# Illedan 5 32.46 1378958

First, let's give a rank to each language by number of occurence in the dataset

In [11]:
order_Language = df.programmingLanguage.value_counts().index.tolist()
order_Language = { lang : rank+1 for rank, lang in enumerate(order_Language) }
df["rankingLanguage"] = df.programmingLanguage.apply(lambda x:order_Language[x])
df["league"] = df["league"].str.title()
df.head()
Out[11]:
agentId challenge league level programmingLanguage pseudo rank score userId rankingLanguage
0 1929755 code-of-kutulu Legend 12 C++ blasterpoard 1 34.35 2577687 1
1 1932387 code-of-kutulu Legend 42 C++ Agade 2 33.53 735910 1
2 1929753 code-of-kutulu Legend 27 C++ y_kawano 3 32.89 610934 1
3 1929726 code-of-kutulu Legend 23 C# MSmits 4 32.46 2522090 3
4 1932175 code-of-kutulu Legend 35 C# Illedan 5 32.46 1378958 3

Now we can plot the position for every challenge of every language. The color will reflect the league

In [13]:
for challenge in challenges:
    plt.figure(figsize=(20,12))
    sns.stripplot(x="rank", 
                  y="programmingLanguage", 
                  data=df[df.challenge == challenge], 
                  hue="league", 
                  jitter =0.1,
                  order=order_Language )
    plt.title(challenge)
    plt.show()