# Path: socceraction/atomic/vaep/base.py
# class AtomicVAEP(VAEP):
#     """
#     An implementation of the VAEP framework for atomic actions.
# 
#     In contrast to the original VAEP framework [1]_ this extension
#     distinguishes the contribution of the player who initiates the action
#     (e.g., gives the pass) and the player who completes the action (e.g.,
#     receives the pass) [2]_.
# 
#     Parameters
#     ----------
#     xfns : list
#         List of feature transformers (see :mod:`socceraction.atomic.vaep.features`)
#         used to describe the game states. Uses :attr:`~socceraction.vaep.base.xfns_default`
#         if None.
#     nb_prev_actions : int, default=3
#         Number of previous actions used to decscribe the game state.
# 
#     See Also
#     --------
#     :class:`socceraction.vaep.VAEP` : Implementation of the original VAEP framework.
# 
#     References
#     ----------
#     .. [1] Tom Decroos, Lotte Bransen, Jan Van Haaren, and Jesse Davis.
#         "Actions speak louder than goals: Valuing player actions in soccer." In
#         Proceedings of the 25th ACM SIGKDD International Conference on Knowledge
#         Discovery & Data Mining, pp. 1851-1861. 2019.
#     .. [2] Tom Decroos, Pieter Robberechts and Jesse Davis.
#         "Introducing Atomic-SPADL: A New Way to Represent Event Stream Data".
#         DTAI Sports Analytics Blog. https://dtai.cs.kuleuven.be/sports/blog/introducing-atomic-spadl:-a-new-way-to-represent-event-stream-data  # noqa
#         May 2020.
#     """
# 
#     _spadlcfg = spadlcfg
#     _lab = lab
#     _fs = fs
#     _vaep = vaep
# 
#     def __init__(
#         self,
#         xfns: Optional[List[fs.FeatureTransfomer]] = None,
#         nb_prev_actions: int = 3,
#     ) -> None:
#         xfns = xfns_default if xfns is None else xfns
#         super().__init__(xfns, nb_prev_actions)
# 
# Path: socceraction/atomic/vaep/features.py
# def feature_column_names(fs: List[FeatureTransfomer], nb_prev_actions: int = 3) -> List[str]:
# def play_left_to_right(gamestates: GameStates, home_team_id: int) -> GameStates:
# def actiontype_onehot(actions: Actions) -> Features:
# def location(actions: Actions) -> Features:
# def polar(actions: Actions) -> Features:
# def movement_polar(actions: Actions) -> Features:
# def direction(actions: Actions) -> Features:
# def goalscore(gamestates: GameStates) -> Features:
#     X = pd.DataFrame()


import pandas as pd
import pytest
import socceraction.atomic.spadl as atomicspadl
import socceraction.atomic.spadl.config as spadlconfig
import socceraction.atomic.vaep.labels as lab
from socceraction.atomic.vaep import AtomicVAEP
from socceraction.atomic.vaep import features as fs
        [spadlconfig.actiontypes.index('shot'), spadlconfig.actiontypes.index('goal')],
        columns=['type_id'],
    )


def test_atomic_goal_from_shot_label(test_goal_df: pd.DataFrame) -> None:
    assert (lab.goal_from_shot(test_goal_df) == pd.DataFrame([[True], [False]], columns=['goal']))[
        'goal'
    ].all()


@pytest.mark.e2e
def test_predict(sb_worldcup_data: pd.HDFStore) -> None:
    # Convert to atomic actions
    games = sb_worldcup_data['games']
    atomic_actions = {
        game.game_id: atomicspadl.convert_to_atomic(
            sb_worldcup_data[f'actions/game_{game.game_id}']
        )
        for game in games.itertuples()
    }
    # Test the vAEP framework on the StatsBomb World Cup data
    model = AtomicVAEP(nb_prev_actions=1)
    # comppute features and labels
    features = pd.concat(
        [
            model.compute_features(game, atomic_actions[game.game_id])
            for game in games.iloc[:-1].itertuples()
        ]
    )

# Path: socceraction/atomic/vaep/base.py
# class AtomicVAEP(VAEP):
#     """
#     An implementation of the VAEP framework for atomic actions.
# 
#     In contrast to the original VAEP framework [1]_ this extension
#     distinguishes the contribution of the player who initiates the action
#     (e.g., gives the pass) and the player who completes the action (e.g.,
#     receives the pass) [2]_.
# 
#     Parameters
#     ----------
#     xfns : list
#         List of feature transformers (see :mod:`socceraction.atomic.vaep.features`)
#         used to describe the game states. Uses :attr:`~socceraction.vaep.base.xfns_default`
#         if None.
#     nb_prev_actions : int, default=3
#         Number of previous actions used to decscribe the game state.
# 
#     See Also
#     --------
#     :class:`socceraction.vaep.VAEP` : Implementation of the original VAEP framework.
# 
#     References
#     ----------
#     .. [1] Tom Decroos, Lotte Bransen, Jan Van Haaren, and Jesse Davis.
#         "Actions speak louder than goals: Valuing player actions in soccer." In
#         Proceedings of the 25th ACM SIGKDD International Conference on Knowledge
#         Discovery & Data Mining, pp. 1851-1861. 2019.
#     .. [2] Tom Decroos, Pieter Robberechts and Jesse Davis.
#         "Introducing Atomic-SPADL: A New Way to Represent Event Stream Data".
#         DTAI Sports Analytics Blog. https://dtai.cs.kuleuven.be/sports/blog/introducing-atomic-spadl:-a-new-way-to-represent-event-stream-data  # noqa
#         May 2020.
#     """
# 
#     _spadlcfg = spadlcfg
#     _lab = lab
#     _fs = fs
#     _vaep = vaep
# 
#     def __init__(
#         self,
#         xfns: Optional[List[fs.FeatureTransfomer]] = None,
#         nb_prev_actions: int = 3,
#     ) -> None:
#         xfns = xfns_default if xfns is None else xfns
#         super().__init__(xfns, nb_prev_actions)
# 
# Path: socceraction/atomic/vaep/features.py
# def feature_column_names(fs: List[FeatureTransfomer], nb_prev_actions: int = 3) -> List[str]:
# def play_left_to_right(gamestates: GameStates, home_team_id: int) -> GameStates:
# def actiontype_onehot(actions: Actions) -> Features:
# def location(actions: Actions) -> Features:
# def polar(actions: Actions) -> Features:
# def movement_polar(actions: Actions) -> Features:
# def direction(actions: Actions) -> Features:
# def goalscore(gamestates: GameStates) -> Features:
#     X = pd.DataFrame()


# Path: tests/atomic/test_atomic_vaep.py
import pandas as pd
import pytest
import socceraction.atomic.spadl as atomicspadl
import socceraction.atomic.spadl.config as spadlconfig
import socceraction.atomic.vaep.labels as lab
from socceraction.atomic.vaep import AtomicVAEP
from socceraction.atomic.vaep import features as fs

        [spadlconfig.actiontypes.index('shot'), spadlconfig.actiontypes.index('goal')],
        columns=['type_id'],
    )


def test_atomic_goal_from_shot_label(test_goal_df: pd.DataFrame) -> None:
    assert (lab.goal_from_shot(test_goal_df) == pd.DataFrame([[True], [False]], columns=['goal']))[
        'goal'
    ].all()


@pytest.mark.e2e
def test_predict(sb_worldcup_data: pd.HDFStore) -> None:
    # Convert to atomic actions
    games = sb_worldcup_data['games']
    atomic_actions = {
        game.game_id: atomicspadl.convert_to_atomic(
            sb_worldcup_data[f'actions/game_{game.game_id}']
        )
        for game in games.itertuples()
    }
    # Test the vAEP framework on the StatsBomb World Cup data
    model = AtomicVAEP(nb_prev_actions=1)
    # comppute features and labels
    features = pd.concat(
        [
            model.compute_features(game, atomic_actions[game.game_id])
            for game in games.iloc[:-1].itertuples()
        ]
    )

    expected_features = set(fs.feature_column_names(model.xfns, model.nb_prev_actions))