Skip to content

Commit

Permalink
Merge pull request #8 from scazzumvivendi/main
Browse files Browse the repository at this point in the history
feat: add columns for translations if present, removed nan for numpy compatibility
  • Loading branch information
napo authored Oct 16, 2024
2 parents ae6165e + 5f15897 commit 831e340
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
27 changes: 26 additions & 1 deletion datavolley/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ def get_teams(rows_list):
visiting_team = rows_list[teams_index + 2].strip()
return home_team, visiting_team

def get_attack_combinations(rows_list):
# Find the index of [3ATTACKCOMBINATION]
attack_combinations_index = rows_list.index('[3ATTACKCOMBINATION]\n')
# Extract attack_combinations
attack_combinations = {}
for idx in range(1, len(rows_list)):
if rows_list[attack_combinations_index + idx] == '[3SETTERCALL]\n':
break
splitted_combinations = rows_list[attack_combinations_index + idx + 1].strip().split(";")
attack_combinations[splitted_combinations[0]] = splitted_combinations[4] if len(splitted_combinations) > 4 else None
return attack_combinations

def get_setter_calls(rows_list):
# Find the index of [3SETTERCALL]
setter_calls_index = rows_list.index('[3SETTERCALL]\n')
# Extract setter_calls
setter_calls = {}
for idx in range(1, len(rows_list)):
if rows_list[setter_calls_index + idx] == '[3WINNINGSYMBOLS]\n':
break
splitted_calls = rows_list[setter_calls_index + idx + 1].strip().split(";")
setter_calls[splitted_calls[0]] = splitted_calls[2] if len(splitted_calls) > 2 else None
return setter_calls

def get_match(rows_list):
# Find the index of [3MATCH]

Expand Down Expand Up @@ -98,7 +122,8 @@ def calculate_skill(row):
'home_player_id5', 'home_player_id6', 'visiting_player_id1', 'visiting_player_id2', 'visiting_player_id3',
'visiting_player_id4', 'visiting_player_id5', 'visiting_player_id6', 'set_number', 'home_team','visiting_team',
'home_team_id', 'visiting_team_id', 'team_id', 'point_won_by', 'winning_attack', 'serving_team', 'receiving_team',
'phase', 'home_score_start_of_point', 'visiting_score_start_of_point', 'rally_number', "possesion_number"
'phase', 'home_score_start_of_point', 'visiting_score_start_of_point', 'rally_number', "possesion_number",
"attack_description", "set_description", 'skill_type'
]

def dv_index2xy(i):
Expand Down
16 changes: 14 additions & 2 deletions datavolley/read_dv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
import numpy as np
from .get_players_from_md import read_players
from .helpers import get_match, get_set, get_teams, calculate_skill, skill_map, eval_codes, desired_order, add_xy
from .helpers import get_match, get_set, get_teams, calculate_skill, skill_map, eval_codes, desired_order, add_xy, get_setter_calls, get_attack_combinations
from charset_normalizer import from_path

class DataVolley:
Expand Down Expand Up @@ -264,7 +264,7 @@ def replace_coordinates(coord):
plays['point_phase'] = np.where((plays['serving_team'] == plays['team']), 'Serve', 'Reception')

# Create attack_phase
plays['attack_phase'] = np.where((plays['skill'] == 'Attack') & (plays['skill'].shift(2) == 'Reception') & (plays['skill'].shift(1) == 'Set') & (plays['team'].shift(2) == plays['team']),'Reception', np.NaN)
plays['attack_phase'] = np.where((plays['skill'] == 'Attack') & (plays['skill'].shift(2) == 'Reception') & (plays['skill'].shift(1) == 'Set') & (plays['team'].shift(2) == plays['team']),'Reception', np.nan)
plays['attack_phase'] = np.where((plays['skill'] == 'Attack') & (plays['skill'].shift(2) != 'Reception') & (plays['skill'].shift(1) == 'Set') & (plays['serving_team'] != plays['team']) & (plays['team'].shift(2) == plays['team']),'SO-Transition',plays['attack_phase'])
plays['attack_phase'] = np.where((plays['skill'] == 'Attack') & (plays['skill'].shift(2) != 'Reception') & (plays['skill'].shift(1) == 'Set') & (plays['serving_team'] == plays['team']) & (plays['team'].shift(2) == plays['team']),'BP-Transition',plays['attack_phase'])

Expand Down Expand Up @@ -314,6 +314,18 @@ def replace_coordinates(coord):
# Aggiunta della colonna "evaluation"
plays['evaluation'] = plays.apply(lambda row: evaluation_mapping.get(row['skill'], {}).get(row['evaluation_code'], ""), axis=1)

# Add shoot type
plays["skill_type "] = plays.apply(lambda row: row['code'][4] if len(row['code']) > 4 else None, axis=1)

# Add attack combinations
attack_combinations = get_attack_combinations(rows)
plays['attack_description'] = plays.apply(lambda row: attack_combinations.get(row['attack_code'], ""), axis=1)

# Add setter calls
setter_calls = get_setter_calls(rows)
plays['set_description'] = plays.apply(lambda row: setter_calls.get(row['set_code'], ""), axis=1)


# Reorder columns
existing_columns = [col for col in desired_order if col in plays.columns]
plays = plays[existing_columns]
Expand Down

0 comments on commit 831e340

Please sign in to comment.