Skip to content

Instantly share code, notes, and snippets.

@mheidari98
Created January 16, 2024 10:49
Show Gist options
  • Save mheidari98/b7a6993a0cab4d01f6041303e9ef16de to your computer and use it in GitHub Desktop.
Save mheidari98/b7a6993a0cab4d01f6041303e9ef16de to your computer and use it in GitHub Desktop.
CTFTIME Comparing the distribution of points
import requests
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
def getPoint(event_id, topN=50):
headers = { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"}
r = requests.get(f"https://ctftime.org/event/{event_id}", headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
title = soup.find('div', class_="page-header").text.strip()
teams = soup.find_all('tr')[1:]
points = [*map(lambda x:float(x.find_all('td')[-1].text), teams)]
points = points[:topN] # top N
maxPoint = points[0]
points = [*map(lambda x: (x/maxPoint)*100, points)] # scale
return title, points
t1, p1 = getPoint(1953) # ASIS CTF Finals 2023
t2, p2 = getPoint(1850) # Insomni'hack 2023
plt.bar(range(len(p1)), p1, width=0.5, color='g', label=t1)
plt.bar(range(len(p2)), p2, width=0.5, color='r', label=t2, align='edge')
plt.legend()
plt.xlabel('rank')
plt.ylabel('Rating points')
plt.title('Comparing the distribution of points')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment