"""
Sample soccer data
==================

This example shows SampleSoccerStats and SampleSoccerOdds, the sample data that ships with the library.
"""

# Author: Georgios Douzas <gdouzas@icloud.com>
# Licence: MIT

import matplotlib.pyplot as plt

from sportsbet.dataloaders import DataLoader
from sportsbet.sources import SampleSoccerOdds, SampleSoccerStats

# %%
# What the sample carries
# -----------------------
#
# It is a real season of the English and Spanish first divisions, taken from football-data.co.uk and frozen. It needs
# no key and reaches no network. That is why the examples and the tests use it.

stats = SampleSoccerStats()
stats.name, stats.kind, stats.sport

# %%
# It ships with the library, so it knows what it publishes without reading anything.

stats.list_available_params()

# %%
# Extracting the data
# -------------------
#
# It is an ordinary source, so you use it like any other. Give it to a dataloader beside an odds source. Extracting
# reads the bundled files off your disk. That costs nothing and touches no network.

dataloader = DataLoader(param_grid={'league': ['England']}, stats=stats, odds=SampleSoccerOdds())
X_train, Y_train, O_train = dataloader.extract_train_data(odds_type='market_average')

# %%
# The input data:
X_train

# %%
# The multi-output targets:
Y_train

# %%
# The odds:
O_train

# %%
# It has no fixtures
# ------------------
#
# The season is finished, so every match in it has been played. A fixture is a match that has not been played. The
# sample has none, so `extract_fixtures_data` returns an empty frame with the training columns.
#
# To bet on something, you need a source that is still publishing matches. See [Football-Data](plot_football_data.md).
# The sample is for learning the interface, not for betting.

X_fix, _, O_fix = dataloader.extract_fixtures_data()
len(X_fix)

# %%
# A picture of it
# ---------------
#
# This shows how the season ended. Home wins lead. That lead is the home advantage the odds always price in.

outcomes = Y_train.sum()
outcomes.index = outcomes.index.str.split('__').str[0]

fig, ax = plt.subplots()
ax.bar(outcomes.index, outcomes.to_numpy(), color=['tab:green', 'tab:grey', 'tab:red'])
ax.set_title('How the sample season ended, by outcome')
ax.set_ylabel('matches')
