generated from jupyterlite/demo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
23,892 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
content/data-labyrinth/not fixed yet/advanced-basketball/advanced-basketball.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"![Data Dunkers Banner](https://github.com/PS43Foundation/data-dunkers/blob/main/docs/top-banner.jpg?raw=true)\n", | ||
"\n", | ||
"<a href=\"https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fcallysto%2Fdata-labyrinth&branch=main&subPath=advanced-basketball/advanced-basketball.ipynb&depth=1\" target=\"_parent\"><img src=\"https://raw.githubusercontent.com/callysto/curriculum-notebooks/master/open-in-callysto-button.svg?sanitize=true\" width=\"123\" height=\"24\" alt=\"Open in Callysto\"/></a>\n", | ||
"\n", | ||
"<a target=\"_parent\" href=\"https://2i2c.callysto.ca/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fcallysto%2Fdata-labyrinth&branch=main&subPath=advanced-basketball/advanced-basketball.ipynb&depth=1\"><img src=\"https://2i2c.org/media/logo.svg\" width=\"30\" height=\"30\" alt=\"Open in 2i2c Hub\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Advanced Basketball Labyrinth\n", | ||
"\n", | ||
"Welcome to the [Data Dunkers](https://ps43foundation.github.io/data-dunkers) Advanced Basketball Labyrinth. This uses a Jupyter notebook and [NBA API](https://github.com/swar/nba_api) data to navigate through advanced data science challenges.\n", | ||
"\n", | ||
"You will receive a key word to initiate this labyrinth. Type your key between the `''` in the code cell below (e.g. `key = 'abc'`) and then click the `▶Run` button to get started." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"key = 'learning'\n", | ||
"\n", | ||
"import requests\n", | ||
"from IPython import get_ipython\n", | ||
"import pandas as pd\n", | ||
"import plotly.express as px\n", | ||
"n = 0\n", | ||
"def check(query):\n", | ||
" try:\n", | ||
" global n\n", | ||
" r = requests.get(f'https://script.google.com/macros/s/AKfycbwHXTIqC41OSUmvnW9qVawU1fPhamC6FiruDmC4j9ltdJR82HfN84z4wyJvEizEgxF1/exec?room=advanced-basketball&query={str(query)}&n={str(n)}')\n", | ||
" response = r.json()\n", | ||
" n = response['n']\n", | ||
" get_ipython().run_cell_magic('markdown', '', response['markdown'])\n", | ||
" get_ipython().set_next_input(response['code'])\n", | ||
" except:\n", | ||
" print('Make sure you have entered the key correctly.')\n", | ||
" get_ipython().set_next_input(\"key = ''\\ncheck(key)\")\n", | ||
"\n", | ||
"check(key)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
67 changes: 67 additions & 0 deletions
67
content/data-labyrinth/not fixed yet/advanced-basketball/data/abbadge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
def get_badge(name): | ||
""" | ||
Returns a badge image with the name of the person who completed the labyrinth. | ||
""" | ||
import requests | ||
from PIL import Image, ImageDraw, ImageFont | ||
import datetime | ||
now = datetime.datetime.now() | ||
date = now.strftime("%Y-%m-%d") | ||
|
||
line1_text = name | ||
line2_text = 'completed the' | ||
line3_text = 'Data Dunkers' | ||
line4_text = 'Advanced Labyrinth' | ||
font_size = 44 | ||
|
||
try: | ||
logo = 'images/bball-logo.jpg' | ||
except: | ||
from io import BytesIO | ||
logo_url = 'https://github.com/callysto/data-labyrinth/blob/main/basketball/images/bball-logo.jpg?raw=true' | ||
logo = BytesIO(requests.get(logo_url, allow_redirects=True).content) | ||
|
||
width, height = 400, 450 | ||
background_color = (0, 0, 0) | ||
image = Image.new('RGB', (width, height), background_color) | ||
draw = ImageDraw.Draw(image) | ||
|
||
# draw the border | ||
draw.line((10, 10, 390, 10), fill=(242, 103, 34), width=3) | ||
draw.line((10, 10, 10, 440), fill=(242, 103, 34), width=3) | ||
draw.line((390, 10, 390, 440), fill=(242, 103, 34), width=3) | ||
draw.line((10, 440, 390, 440), fill=(242, 103, 34), width=3) | ||
|
||
# get the image | ||
image_to_embed = Image.open(logo).resize((374, 150)) | ||
image.paste(image_to_embed, (13, 20+font_size*2+20)) | ||
|
||
# get the font | ||
import requests | ||
import io | ||
r = requests.get('https://raw.githubusercontent.com/googlefonts/roboto/main/src/hinted/RobotoCondensed-Regular.ttf', allow_redirects=True) | ||
font = ImageFont.truetype(io.BytesIO(r.content), size=font_size) | ||
|
||
# text positions | ||
line1_size = draw.textlength(line1_text, font=font) | ||
line2_size = draw.textlength(line2_text, font=font) | ||
line3_size = draw.textlength(line3_text, font=font) | ||
line4_size = draw.textlength(line4_text, font=font) | ||
line1_position = ((width - line1_size) // 2, 20) | ||
line2_position = ((width - line2_size) // 2, 20+font_size) | ||
line3_position = ((width - line3_size) // 2, 20+font_size*2+10+150) | ||
line4_position = ((width - line4_size) // 2, 20+font_size*3+10+150) | ||
|
||
# Draw the text on the image | ||
draw.text(line1_position, line1_text, fill=(111, 74, 158), font=font) | ||
draw.text(line2_position, line2_text, fill=(111, 74, 158), font=font) | ||
draw.text(line3_position, line3_text, fill=(200, 168, 208), font=font) | ||
draw.text(line4_position, line4_text, fill=(142, 162, 161), font=font) | ||
# add date | ||
draw.text((21, 20+font_size*4+12+180), date, fill=(242, 103, 34), font=ImageFont.truetype(io.BytesIO(r.content), size=20)) | ||
# add hashtags | ||
draw.text((150, 20+font_size*4+12+180), '#datadunkers', fill=(242, 103, 34), font=ImageFont.truetype(io.BytesIO(r.content), size=20)) | ||
draw.text((300, 20+font_size*4+12+180), '#callysto', fill=(242, 103, 34), font=ImageFont.truetype(io.BytesIO(r.content), size=20)) | ||
|
||
#return(image.resize((200, 225))) | ||
return(image) |
Oops, something went wrong.