-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.qmd
111 lines (86 loc) · 3.22 KB
/
README.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "pydatavolley"
format: gfm
---
A python package for reading volleyball scouting files in DataVolley format (\*.dvw).
<https://pydatavolley.openvolley.org/>
## Installation
```
pip install pydatavolley
```
## [Examples]{.underline}
#### Reading one file:
```{python}
# Using read_dv.DataVolley(None) will use example file
import pandas as pd
from datavolley import read_dv
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 400)
dv_instance = read_dv.DataVolley(None)
df = dv_instance.get_plays()
print(df.head(10))
```
------------------------------------------------------------------------
#### Reading multiple files - grouping for attacks and kills:
```{python}
import pandas as pd
from datavolley import read_dv
import os
# Assign path
dvw_path_folder = os.path.expanduser("~\\desktop\\dvws")
file_extension = ".dvw"
# Get a list of all files with the specified extension in the directory
file_list = [f for f in os.listdir(dvw_path_folder) if f.endswith(file_extension)]
# Initialize an empty DataFrame to store combined data
combined_df = pd.DataFrame()
def process_file(path):
dv_instance = read_dv.DataVolley(os.path.join(dvw_path_folder, path))
df = dv_instance.get_plays()
return df
# Loop through each file path
for file_name in file_list:
combined_df = pd.concat([combined_df, process_file(file_name)], ignore_index=True)
# Filter for attacks and print attacks
print(
combined_df[combined_df['skill'] == 'Attack']
.groupby(['player_name', 'team'])
.agg(Att=('skill', 'count'),
K=('evaluation_code', lambda x: x.eq('#').sum(skipna=True)),
K_pct=('evaluation_code', lambda x: round((x.eq('#').sum(skipna=True) / x.count()), 3)))
.reset_index()
.sort_values(by='K_pct', ascending=False)
.head(20)
.reset_index(drop=True)
.to_string()
)
```
------------------------------------------------------------------------
#### Plotting attacks -
```{python}
# Using read_dv.DataVolley(None) will use example file
import datavolley.pycourt as pycourt
from datavolley import read_dv
import glob
import matplotlib.pyplot as plt
import pandas as pd
dv_instance = read_dv.DataVolley(None)
df = dv_instance.get_plays()
atk_data = df[(df['skill'] == 'Attack') & (df['attack_code'] == 'X5')]
coordainte_df = atk_data[['start_coordinate_x',
'start_coordinate_y',
'end_coordinate_x',
'end_coordinate_y']]
def plot_coordinates(coordinates):
pycourt.pycourt()
# Plot the coordinates
plt.scatter(coordinates['start_coordinate_x'], coordinates['start_coordinate_y'], color='red')
plt.scatter(coordinates['end_coordinate_x'], coordinates['end_coordinate_y'], color='blue')
# Connect the coordinates with lines
for i in range(len(coordinates)):
start_point = (coordinates['start_coordinate_x'].iloc[i], coordinates['start_coordinate_y'].iloc[i])
end_point = (coordinates['end_coordinate_x'].iloc[i], coordinates['end_coordinate_y'].iloc[i])
plt.plot([start_point[0], end_point[0]], [start_point[1], end_point[1]], color='gray', linestyle='--', linewidth=1)
plt.show(block=True)
plot_coordinates(coordainte_df)
```