示例#1
0
def test_fit_cards():
    with test_past_data_session_scope() as ts:
        df_cards = fit_card_points(gameweek=1, season="1819", dbsession=ts)
        assert isinstance(df_cards, pd.Series)
        assert len(df_cards) > 0
        assert all(df_cards <= 0)
        assert all(df_cards >= -3)
def test_get_fitted_player_model():
    pm = get_player_model()
    assert isinstance(pm, pystan.model.StanModel)
    with test_past_data_session_scope() as ts:
        fpm = get_fitted_player_model(pm, "FWD", "1819", 12, ts)
        assert isinstance(fpm, pd.DataFrame)
        assert len(fpm) > 0
示例#3
0
def test_get_ratings_dict():
    with test_past_data_session_scope() as ts:
        rd = get_result_dict("1819", 10, ts)
        teams = set(rd["home_team"]) | set(rd["away_team"])
        d = get_ratings_dict("1819", teams, ts)
        assert isinstance(d, dict)
        assert len(d) >= 20
示例#4
0
def test_fit_bonus():
    with test_past_data_session_scope() as ts:
        df_bonus = fit_bonus_points(gameweek=1, season="1819", dbsession=ts)
        assert len(df_bonus) == 2
        for df in df_bonus:
            assert isinstance(df, pd.Series)
            assert len(df) > 0
            assert all(df <= 3)
            assert all(df >= 0)
示例#5
0
def test_get_fitted_player_model():
    pm = NumpyroPlayerModel()
    assert isinstance(pm, NumpyroPlayerModel)
    cpm = ConjugatePlayerModel()
    assert isinstance(cpm, ConjugatePlayerModel)
    with test_past_data_session_scope() as ts:
        fpm = fit_player_data("FWD", "1819", 12, model=pm, dbsession=ts)
        assert isinstance(fpm, pd.DataFrame)
        assert len(fpm) > 0
        fcpm = fit_player_data("FWD", "1819", 12, model=cpm, dbsession=ts)
        assert isinstance(fcpm, pd.DataFrame)
        assert len(fcpm) > 0
示例#6
0
def test_get_player_history_df():
    """
    test that we only consider gameweeks up to the specified gameweek
    (gw 12 in 1819 season).
    """
    with test_past_data_session_scope() as ts:
        df = get_player_history_df(season="1819", gameweek=12, dbsession=ts)
        assert len(df) > 0
        result_ids = df.match_id.unique()
        for result_id in result_ids:
            if result_id == 0:
                continue
            fixture_id = (ts.query(Result).filter_by(
                result_id=int(result_id)).first().fixture_id)
            fixture = ts.query(Fixture).filter_by(
                fixture_id=fixture_id).first()
            assert fixture.season in ["1718", "1819"]
            if fixture.season == "1819":
                assert fixture.gameweek < 12
示例#7
0
def test_get_player_scores():
    """Test utility function used by fit bonus, save and card points to get player
    scores rows filtered by season, gameweek and minutese played values"""
    with test_past_data_session_scope() as ts:
        df = get_player_scores(season="1819", gameweek=12, dbsession=ts)
        # check type and columns
        assert len(df) > 0
        assert isinstance(df, pd.DataFrame)
        req_cols = [
            "player_id",
            "minutes",
            "saves",
            "bonus",
            "yellow_cards",
            "red_cards",
        ]
        for col in req_cols:
            assert col in df.columns
        # test player scores correctly filtered by gameweek and season
        for _, row in df.iterrows():
            assert row["season"] in ["1718", "1819"]
            if row["season"] == "1819":
                assert row["gameweek"] < 12
        # test filtering on min minutes
        df = get_player_scores(season="1819",
                               gameweek=12,
                               min_minutes=10,
                               dbsession=ts)
        assert len(df) > 0
        assert all(df["minutes"] >= 10)
        # test filtering on max minutes
        df = get_player_scores(season="1819",
                               gameweek=12,
                               max_minutes=10,
                               dbsession=ts)
        assert len(df) > 0
        assert all(df["minutes"] <= 10)
示例#8
0
def test_fixture_probabilities():
    with test_past_data_session_scope() as ts:
        df = fixture_probabilities(20, "1819", dbsession=ts)
        assert isinstance(df, pd.DataFrame)
        assert len(df) == 10
示例#9
0
def test_get_fitted_team_model():
    with test_past_data_session_scope() as ts:
        model_team = get_fitted_team_model("1819", 10, ts)
        assert isinstance(
            model_team,
            bpl.extended_dixon_coles.ExtendedDixonColesMatchPredictor)
示例#10
0
def test_get_result_dict():
    with test_past_data_session_scope() as ts:
        d = get_result_dict("1819", 10, ts)
        assert isinstance(d, dict)
        assert len(d) > 0
示例#11
0
def test_get_fitted_team_model():
    with test_past_data_session_scope() as ts:
        model_team = get_fitted_team_model("1819", 10, ts)
        assert isinstance(model_team, bpl.models.BPLModel)
示例#12
0
def test_get_ratings_df():
    with test_past_data_session_scope() as ts:
        df = get_ratings_df("1819", ts)
        assert isinstance(df, pd.DataFrame)
        assert len(df) >= 20