Skip to content

Commit

Permalink
added juypter notebook formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yer1k committed Nov 6, 2022
1 parent d6372d7 commit 9ffb4d9
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test:
python -m pytest -vv *.py

format:
black *.py
black *.py *.ipynb

lint:
pylint --disable=R,C --ignore-patterns=test_.*?py *.py
Expand Down
4 changes: 3 additions & 1 deletion create_sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
cursor = db.cursor()

# Create a table
cursor.execute("CREATE TABLE games (Game_Date,Game_Day,Distance,Game_Number,Game_Number1,FULL_GAME,Distance_From_Home,Time,Game_Type,Level,Competition_System,Stage,Site,Team_Home_vs_Away,Poisition,Other_Officials,Color_Home_vs_Away,Score,Score_Time_Home ,Score_Time_Away,Kick_off,Attack_Direction,Duration,Ball_Size,Number_of_Players,Weather,Temperature_Celsius,Report,YC_Count,YCs_Count,RC_Count);")
cursor.execute(
"CREATE TABLE games (Game_Date,Game_Day,Distance,Game_Number,Game_Number1,FULL_GAME,Distance_From_Home,Time,Game_Type,Level,Competition_System,Stage,Site,Team_Home_vs_Away,Poisition,Other_Officials,Color_Home_vs_Away,Score,Score_Time_Home ,Score_Time_Away,Kick_off,Attack_Direction,Duration,Ball_Size,Number_of_Players,Weather,Temperature_Celsius,Report,YC_Count,YCs_Count,RC_Count);"
)

# Read the CSV file
with open("Game Report.csv", "r") as f:
Expand Down
126 changes: 96 additions & 30 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -13,17 +13,17 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# create a connection to a database\n",
"db = sqlite3.connect('games.db')"
"db = sqlite3.connect(\"games.db\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,16 +33,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x7fe2e60417c0>"
"<sqlite3.Cursor at 0x7f10fa1712c0>"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -93,7 +93,7 @@
" '1')"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -105,16 +105,16 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sqlite3.Cursor at 0x7fe2e60417c0>"
"<sqlite3.Cursor at 0x7f10fa1712c0>"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -126,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -165,7 +165,7 @@
" (30, 'RC_Count', '', 0, None, 0)]"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -177,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -192,12 +192,14 @@
"# select the game played as 11 vs 11\n",
"cursor.execute(\"select * from games where Number_of_Players == '11';\")\n",
"game11v11 = cursor.fetchall()\n",
"print(f\"I have officiated {len(game11v11)} 11 vs 11 games from January 2021 to July 2022.\")"
"print(\n",
" f\"I have officiated {len(game11v11)} 11 vs 11 games from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -217,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -237,7 +239,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -252,12 +254,14 @@
"# select the game officiated as assistant referee\n",
"cursor.execute(\"select * from games where Poisition like 'AR%';\")\n",
"AR = cursor.fetchall()\n",
"print(f\"I have officiated {len(AR)} games as assistant referee from January 2021 to July 2022.\")"
"print(\n",
" f\"I have officiated {len(AR)} games as assistant referee from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -272,12 +276,14 @@
"# select the game officiated as 4th official\n",
"cursor.execute(\"select * from games where Poisition == '4th O';\")\n",
"fourthO = cursor.fetchall()\n",
"print(f\"I have officiated {len(fourthO)} games as 4th official from January 2021 to July 2022.\")"
"print(\n",
" f\"I have officiated {len(fourthO)} games as 4th official from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -292,12 +298,14 @@
"# How many Yellow Cards have I given as a referee?\n",
"cursor.execute(\"select sum(YC_Count) from games where Poisition == 'RR';\")\n",
"YC = cursor.fetchall()\n",
"print(f\"I have given {YC[0][0]:.0f} Yellow Cards as a referee from January 2021 to July 2022.\")"
"print(\n",
" f\"I have given {YC[0][0]:.0f} Yellow Cards as a referee from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -312,12 +320,14 @@
"# How many Red Cards have I given as a referee?\n",
"cursor.execute(\"select sum(RC_Count) from games where Poisition == 'RR';\")\n",
"RC = cursor.fetchall()\n",
"print(f\"I have given {RC[0][0]:.0f} Red Cards as a referee from January 2021 to July 2022.\")"
"print(\n",
" f\"I have given {RC[0][0]:.0f} Red Cards as a referee from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -332,12 +342,14 @@
"# How many Yellow Cards per game as a referee?\n",
"cursor.execute(\"select avg(YC_Count) from games where Poisition == 'RR';\")\n",
"YC_per_game = cursor.fetchall()\n",
"print(f\"I have given {YC_per_game[0][0]:.2f} Yellow Cards per game as a referee from January 2021 to July 2022.\")"
"print(\n",
" f\"I have given {YC_per_game[0][0]:.2f} Yellow Cards per game as a referee from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -352,7 +364,61 @@
"# How many Red Cards per game as a referee?\n",
"cursor.execute(\"select avg(RC_Count) from games where Poisition == 'RR';\")\n",
"RC_per_game = cursor.fetchall()\n",
"print(f\"I have given {RC_per_game[0][0]:.2f} Red Cards per game as a referee from January 2021 to July 2022.\")"
"print(\n",
" f\"I have given {RC_per_game[0][0]:.2f} Red Cards per game as a referee from January 2021 to July 2022.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The most cards shown in a game as a referee was 11, (YC: 9, 2nd YC: 2, and RC: 2), 成都龙耀 v 德驰娱乐 (Score:1:2, 成甲总Semi-Final) on 1/16/22 at 锦江仁德 A4.\n",
"My running distance was 8.13 kilometers. Other officials were: 秦立港、李阳、李飞.\n"
]
}
],
"source": [
"# The most cards shown in a game as a referee\n",
"cursor.execute(\n",
" \"select Game_Date, YC_Count, YCs_Count, RC_Count, max(YC_Count + RC_Count) as Cards_Max, Team_Home_vs_Away, Game_Type, Stage, Site, Score, Distance, Other_Officials from games where Poisition == 'RR';\"\n",
")\n",
"Cards_Max = cursor.fetchall()\n",
"print(\n",
" f\"The most cards shown in a game as a referee was {Cards_Max[0][4]:.0f}, (YC: {Cards_Max[0][1]}, 2nd YC: {Cards_Max[0][2]}, and RC: {Cards_Max[0][3]}), {Cards_Max[0][5]} (Score:{Cards_Max[0][9]}, {Cards_Max[0][6]}{Cards_Max[0][7]}) on {Cards_Max[0][0]} at {Cards_Max[0][8]}.\"\n",
")\n",
"print(\n",
" f\"My running distance was {Cards_Max[0][10]} kilometers. Other officials were: {Cards_Max[0][11]}.\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The most distance covered in a game as a referee was 9.90 kilometers, 成都之己 v 成都大学 (Score:2:2, 成超 22 Season YC: 2, 2nd YC: 0, and RC: 0) on 7/3/22 at 城东体育公园.\n"
]
}
],
"source": [
"# The most distanced covered in a game as a referee\n",
"cursor.execute(\n",
" \"select Game_Date, YC_Count, YCs_Count, RC_Count, max(Distance) as Distance_Max, Team_Home_vs_Away, Game_Type, Stage, Site, Score, Other_Officials from games where Poisition == 'RR';\"\n",
")\n",
"Distance_Max = cursor.fetchall()\n",
"print(\n",
" f\"The most distance covered in a game as a referee was {Distance_Max[0][4]} kilometers, {Distance_Max[0][5]} (Score:{Distance_Max[0][9]}, {Distance_Max[0][6]} 22 {Distance_Max[0][7]} YC: {Distance_Max[0][1]}, 2nd YC: {Distance_Max[0][2]}, and RC: {Distance_Max[0][3]}) on {Distance_Max[0][0]} at {Distance_Max[0][8]}.\"\n",
")"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest
pylint
click
pandas
pandas
black[jupyter]

0 comments on commit 9ffb4d9

Please sign in to comment.