forked from openvolley/pydatavolley
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreading_files.qmd
81 lines (62 loc) · 2.48 KB
/
reading_files.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
---
title: "Reading plays - dvw files"
---
## DVW files
The data project scouting software, [data volley 4](https://www.dataproject.com/Products/EN/en/Volleyball/DataVolley4) produces .dvw files. These files are similar to a text file. If your interested in some example files, you can find them [here](https://mevza.volleynet.at/Download/59).
## Python - Reading plays from one dvw file
The provided example file is used. You would typically fill in the `None` with the actual path of your dvw files.
```{python}
#| tbl-pyex: Example python reading data
from datavolley import read_dv
import pandas as pd
from IPython.display import Markdown
pd.set_option('display.max_colwidth', 1000)
dv_instance = read_dv.DataVolley(None) # Replace `None` with path of your dvw file
df = dv_instance.get_plays()
df = df[df['skill'].notna()]
df = df.head(5)
Markdown(df.to_markdown(index = False, tablefmt="github", maxcolwidths=[None]))
```
## Python - Reading plays from multiple files
```{python}
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)
match_count = combined_df[['match_id']].drop_duplicates()
Markdown(match_count.to_markdown(index = False))
```
------------------------------------------------------------------------
## R - Reading plays from one dvw file
The provided example file is used. You would typically fill in the `None` with the actual path of your dvw files.
```{r}
#| warning: FALSE
library(datavolley)
library(tidyverse)
x <- dv_read("datavolley//example_data.dvw") # Example data from python
px <- x$plays
px <- px %>% filter(!is.na(skill))
px <- head(px, 5)
knitr::kable(px)
```
## R - Reading plays from multiple files
```{r}
#| warning: FALSE
dvw_path_folder <- path.expand("~/dvws")
d <- dir(dvw_path_folder, pattern = "dvw$", full.names = TRUE)
lx <- lapply(d, dv_read, insert_technical_timeouts = FALSE)
px <- bind_rows(lapply(lx, plays))
match_count <- px %>% distinct(match_id)
knitr::kable(match_count)
```