Initial commit
This commit is contained in:
commit
7aeb189308
167
.ipynb_checkpoints/Wizualizacja-checkpoint.ipynb
Normal file
167
.ipynb_checkpoints/Wizualizacja-checkpoint.ipynb
Normal file
@ -0,0 +1,167 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 67,
|
||||
"id": "9d832900",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import re\n",
|
||||
"\n",
|
||||
"pd.set_option('display.max_rows', 10000)\n",
|
||||
"pd.set_option('display.max_columns', 10000)\n",
|
||||
"\n",
|
||||
"file_path = 'games.csv'\n",
|
||||
"\n",
|
||||
"data = pd.read_csv(file_path) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 84,
|
||||
"id": "84d9af06",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"['Qd1', 'Qc2', 'Qc3', 'Qb3', 'Qb7+', 'Qxd7#']\n",
|
||||
"['Qd1', 'Qxd4', 'Qd1', 'Qa4', 'Qh4', 'Qxg5', 'Qg3', 'Qxg6']\n",
|
||||
"Square names from list1: ['d1', 'c2', 'c3', 'b3', 'b7', 'd7']\n",
|
||||
"Square names from list2: ['d1', 'd4', 'd1', 'a4', 'h4', 'g5', 'g3', 'g6']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"\n",
|
||||
"def extract_square_names(moves_list):\n",
|
||||
" square_names = []\n",
|
||||
"\n",
|
||||
" for move in moves_list:\n",
|
||||
" # Use a regular expression to match the chess square name\n",
|
||||
" match = re.search(r'[a-h][1-8]', move)\n",
|
||||
" if match:\n",
|
||||
" square_names.append(match.group())\n",
|
||||
"\n",
|
||||
" return square_names"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 85,
|
||||
"id": "1f11b18c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"['Qd1', 'Qxd4', 'Qd1', 'Qa4', 'Qh4', 'Qxg5', 'Qg3', 'Qxg6']\n",
|
||||
"White queen moves: ['d1', 'd4', 'd1', 'a4', 'h4', 'g5', 'g3', 'g6']\n",
|
||||
"['Qd8', 'Qe7', 'Qc7', 'Qg7', 'Qxg6']\n",
|
||||
"Black queen moves: ['d8', 'e7', 'c7', 'g7', 'g6']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"opening_number_of_games = data['opening_name'].value_counts()\n",
|
||||
"opening_number_of_games.head(10)\n",
|
||||
"# openings = ['Sicilian Defense', 'Old Benoni Defense', \"Queen's Pawn Game: Mason Attack\"]\n",
|
||||
"\n",
|
||||
"old_benoni_games = data[data['opening_name'].str.contains('Old Benoni Defense', case = False)]\n",
|
||||
"old_benoni_count = len(old_benoni_games)\n",
|
||||
"\n",
|
||||
"for text in old_benoni_games.head(1)['moves']:\n",
|
||||
" moves = text.split()\n",
|
||||
" white_queen_moves = ['Qd1']\n",
|
||||
" black_queen_moves = ['Qd8']\n",
|
||||
" for idx, move in enumerate(moves):\n",
|
||||
" if move.startswith(\"Q\"):\n",
|
||||
" if idx % 2 == 0:\n",
|
||||
" white_queen_moves.append(move)\n",
|
||||
" if idx % 2 == 1:\n",
|
||||
" black_queen_moves.append(move)\n",
|
||||
"# print(f'White queen moves: {white_queen_moves}')\n",
|
||||
"# print(f'Black queen moves: {black_queen_moves}')\n",
|
||||
" print(f'White queen moves: {extract_square_names(white_queen_moves)}')\n",
|
||||
" print(f'Black queen moves: {extract_square_names(black_queen_moves)}')\n",
|
||||
"# list1 = ['Qd1', 'Qc2', 'Qc3', 'Qb3', 'Qb7+', 'Qxd7#']\n",
|
||||
"# list2 = ['Qd1', 'Qxd4', 'Qd1', 'Qa4', 'Qh4', 'Qxg5', 'Qg3', 'Qxg6']\n",
|
||||
"# print(white_queen_moves)\n",
|
||||
"# print(list1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "e0e4858a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"opening_name\n",
|
||||
"Alekhine Defense: Exchange Variation 9.0\n",
|
||||
"Anderssen Opening 1.0\n",
|
||||
"Benko Gambit Accepted | Fully Accepted Variation 9.0\n",
|
||||
"Benko Gambit Declined | Quiet Line 7.0\n",
|
||||
"Benoni Defense: Benoni-Indian Defense 4.0\n",
|
||||
" ... \n",
|
||||
"Trompowsky Attack 3.0\n",
|
||||
"Van Geet Opening: Dunst-Perrenet Gambit 5.0\n",
|
||||
"Vienna Game #2 6.0\n",
|
||||
"Vienna Game: Vienna Gambit | Main Line 6.0\n",
|
||||
"Yusupov-Rubinstein System 5.0\n",
|
||||
"Name: opening_ply, Length: 112, dtype: float64\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/var/folders/lm/cbc3n48n4x94zd3vf6zbbly40000gn/T/ipykernel_2729/977498901.py:12: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
|
||||
" filtered_data = data[data['white_rating'] > 2200][data['black_rating'] > 2200]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# Filtrowanie danych dla elo > 2200\n",
|
||||
"filtered_data = data[data['white_rating'] > 2200][data['black_rating'] > 2200]\n",
|
||||
"\n",
|
||||
"# Oblicz średnią opening_ply dla każdej unikalnej wartości w kolumnie 'opening'\n",
|
||||
"average_opening_ply = filtered_data.groupby('opening_name')['opening_ply'].mean()\n",
|
||||
"\n",
|
||||
"# Wyświetl średnie opening_ply dla każdej opening, dla elo > 2200\n",
|
||||
"print(average_opening_ply)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
150
wizualizacja/Wizualizacja.ipynb
Normal file
150
wizualizacja/Wizualizacja.ipynb
Normal file
@ -0,0 +1,150 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 86,
|
||||
"id": "e4b28b2f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import re\n",
|
||||
"\n",
|
||||
"pd.set_option('display.max_rows', 10000)\n",
|
||||
"pd.set_option('display.max_columns', 10000)\n",
|
||||
"\n",
|
||||
"file_path = 'games.csv'\n",
|
||||
"\n",
|
||||
"data = pd.read_csv(file_path) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 87,
|
||||
"id": "e7264e32",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"\n",
|
||||
"def extract_square_names(moves_list):\n",
|
||||
" square_names = []\n",
|
||||
"\n",
|
||||
" for move in moves_list:\n",
|
||||
" # Use a regular expression to match the chess square name\n",
|
||||
" match = re.search(r'[a-h][1-8]', move)\n",
|
||||
" if match:\n",
|
||||
" square_names.append(match.group())\n",
|
||||
"\n",
|
||||
" return square_names"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 88,
|
||||
"id": "d3157e88",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"White queen squares: ['d1', 'd4', 'd1', 'a4', 'h4', 'g5', 'g3', 'g6']\n",
|
||||
"Black queen squares: ['d8', 'e7', 'c7', 'g7', 'g6']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"opening_number_of_games = data['opening_name'].value_counts()\n",
|
||||
"opening_number_of_games.head(10)\n",
|
||||
"# openings = ['Sicilian Defense', 'Old Benoni Defense', \"Queen's Pawn Game: Mason Attack\"]\n",
|
||||
"\n",
|
||||
"old_benoni_games = data[data['opening_name'].str.contains('Old Benoni Defense', case = False)]\n",
|
||||
"old_benoni_count = len(old_benoni_games)\n",
|
||||
"\n",
|
||||
"for text in old_benoni_games.head(1)['moves']:\n",
|
||||
" moves = text.split()\n",
|
||||
" white_queen_moves = ['Qd1']\n",
|
||||
" black_queen_moves = ['Qd8']\n",
|
||||
" for idx, move in enumerate(moves):\n",
|
||||
" if move.startswith(\"Q\"):\n",
|
||||
" if idx % 2 == 0:\n",
|
||||
" white_queen_moves.append(move)\n",
|
||||
" if idx % 2 == 1:\n",
|
||||
" black_queen_moves.append(move)\n",
|
||||
" white_queen_squares = extract_square_names(white_queen_moves)\n",
|
||||
" black_queen_squares = extract_square_names(black_queen_moves)\n",
|
||||
" print(f'White queen squares: {white_queen_squares}')\n",
|
||||
" print(f'Black queen squares: {black_queen_squares}')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "fdd92a15",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"opening_name\n",
|
||||
"Alekhine Defense: Exchange Variation 9.0\n",
|
||||
"Anderssen Opening 1.0\n",
|
||||
"Benko Gambit Accepted | Fully Accepted Variation 9.0\n",
|
||||
"Benko Gambit Declined | Quiet Line 7.0\n",
|
||||
"Benoni Defense: Benoni-Indian Defense 4.0\n",
|
||||
" ... \n",
|
||||
"Trompowsky Attack 3.0\n",
|
||||
"Van Geet Opening: Dunst-Perrenet Gambit 5.0\n",
|
||||
"Vienna Game #2 6.0\n",
|
||||
"Vienna Game: Vienna Gambit | Main Line 6.0\n",
|
||||
"Yusupov-Rubinstein System 5.0\n",
|
||||
"Name: opening_ply, Length: 112, dtype: float64\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/var/folders/lm/cbc3n48n4x94zd3vf6zbbly40000gn/T/ipykernel_2729/977498901.py:12: UserWarning: Boolean Series key will be reindexed to match DataFrame index.\n",
|
||||
" filtered_data = data[data['white_rating'] > 2200][data['black_rating'] > 2200]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# Filtrowanie danych dla elo > 2200\n",
|
||||
"filtered_data = data[data['white_rating'] > 2200][data['black_rating'] > 2200]\n",
|
||||
"\n",
|
||||
"# Oblicz średnią opening_ply dla każdej unikalnej wartości w kolumnie 'opening'\n",
|
||||
"average_opening_ply = filtered_data.groupby('opening_name')['opening_ply'].mean()\n",
|
||||
"\n",
|
||||
"# Wyświetl średnie opening_ply dla każdej opening, dla elo > 2200\n",
|
||||
"print(average_opening_ply)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
20059
wizualizacja/games.csv
Normal file
20059
wizualizacja/games.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user