Facebook
From Anorexic Penguin, 4 Years ago, written in Python.
This paste is a reply to RankVsDelta from P.Alizadeh - view diff
Embed
Download Paste or View Raw
Hits: 272
  1. # python3
  2. import requests
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6.  
  7. cf = "http://codeforces.com/api/"
  8.  
  9.  
  10. def call(method, params):
  11.     url = f"{cf}{method}"
  12.     req = requests.get(url, params=params)
  13.     if req.status_code == 200:
  14.         return req.json()
  15.  
  16.  
  17. """
  18. Some Contests' id:
  19.    Good Bye 2019 : 1270
  20.    Edu 79        : 1279
  21.    Global 6      : 1266
  22.    Div3 #611     : 1283
  23.    Div2 #608     : 1271
  24.    Div1 #609     : 1268
  25.    Codefest 19   : 1208
  26. """
  27.  
  28. rating = [[1200, "gray"],
  29.           [1400, "green"],
  30.           [1600, "#03a89e"],
  31.           [1900, "blue"],
  32.           [2100, "#aa00aa"],
  33.           [2400, "orange"],
  34.           [3000, "red"],
  35.           [9999, "black"]]
  36.  
  37. data = call("contest.ratingChanges", {"contestId": "1208"})["result"]
  38. title = data[0]["contestName"]
  39. print(title)
  40.  
  41. delta = np.zeros((len(data),), dtype=np.int64)
  42. color = []
  43. for i in range(len(data)):
  44.     delta[i] = data[i]["newRating"] - data[i]["oldRating"]
  45.     for j in range(len(rating)):
  46.         if data[i]["oldRating"] < rating[j][0]:
  47.             color.append(rating[j][1])
  48.             break
  49.  
  50. plt.figure(figsize=(8, 6))
  51. plt.title(title)
  52. plt.xlabel("Rank")
  53. plt.ylabel("Delta Rate")
  54. plt.yticks(np.arange(-300, 301, 50))
  55. plt.ylim(-300, 300)
  56. plt.grid()
  57. plt.scatter(np.arange(len(delta)), delta, s=0.5, c=color)
  58. plt.show()
  59.