예제 #1
0
def test_event_for_efficiency_stats_when_events_out_of_order():
    ft = {
        "EVENTMSGTYPE": 3,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Free Throw 1 of 1",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 1,
    }
    order = 1
    ft_event = StatsFreeThrow(ft, order)
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 6,
        "VISITORDESCRIPTION": "Away From Play Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 2,
        "PLAYER2_ID": 1,
    }
    order = 1
    foul_event = StatsFoul(foul, order)

    ft_event.previous_event = None
    ft_event.next_event = foul_event
    foul_event.previous_event = ft_event
    foul_event.next_event = None
    assert ft_event.event_for_efficiency_stats == foul_event
예제 #2
0
def test_flagrant_free_throw_type():
    foul = {
        "EVENTNUM": 609,
        "PCTIMESTRING": "0:25",
        "VISITORDESCRIPTION": "Griffin Flagrant Foul (P5.PN) (M.Davis)",
        "EVENTMSGACTIONTYPE": 14,
        "EVENTMSGTYPE": 6,
        "PLAYER1_ID": 201933,
        "PLAYER1_TEAM_ID": 1610612765,
        "PLAYER2_ID": 203078,
        "PLAYER2_TEAM_ID": 1610612764,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    ft_1_of_2 = {
        "EVENTNUM": 611,
        "PCTIMESTRING": "0:25",
        "HOMEDESCRIPTION": "Beal Free Throw Flagrant 1 of 2 (32 PTS)",
        "EVENTMSGACTIONTYPE": 11,
        "EVENTMSGTYPE": 3,
        "PLAYER1_ID": 203078,
        "PLAYER1_TEAM_ID": 1610612764,
        "PLAYER2_ID": None,
        "PLAYER2_TEAM_ID": None,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    ft_1_of_2_event = StatsFreeThrow(ft_1_of_2, order)
    ft_2_of_2 = {
        "EVENTNUM": 611,
        "PCTIMESTRING": "0:25",
        "HOMEDESCRIPTION": "Beal Free Throw Flagrant 2 of 2 (32 PTS)",
        "EVENTMSGACTIONTYPE": 12,
        "EVENTMSGTYPE": 3,
        "PLAYER1_ID": 203078,
        "PLAYER1_TEAM_ID": 1610612764,
        "PLAYER2_ID": None,
        "PLAYER2_TEAM_ID": None,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    ft_2_of_2_event = StatsFreeThrow(ft_2_of_2, order)

    foul_event.previous_event = None
    foul_event.next_event = ft_1_of_2_event
    ft_1_of_2_event.previous_event = foul_event
    ft_1_of_2_event.next_event = ft_2_of_2_event
    ft_2_of_2_event.previous_event = ft_1_of_2_event
    ft_2_of_2_event.next_event = None

    assert ft_1_of_2_event.free_throw_type == "2 Shot Flagrant"
예제 #3
0
def test_is_make_that_does_not_end_possession_with_lane_violation_true():
    make = {
        "EVENTMSGTYPE": 1,
        "EVENTMSGACTIONTYPE": 10,
        "PLAYER1_ID": 15,
        "PLAYER1_TEAM_ID": 1,
        "HOMEDESCRIPTION": "Made Shot",
        "PCTIMESTRING": "0:45",
        "EVENTNUM": 1,
    }
    order = 1
    make_event = StatsFieldGoal(make, order)
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 2,
        "VISITORDESCRIPTION": "Shooting Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 12,
        "PLAYER2_ID": 15,
        "EVENTNUM": 2,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    lane_violation = {
        "EVENTMSGTYPE": 5,
        "EVENTMSGACTIONTYPE": 17,
        "HOMEDESCRIPTION": "Lane Violation Turnover",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 15,
        "PLAYER2_ID": None,
        "EVENTNUM": 3,
    }
    order = 1
    lane_violation_event = StatsTurnover(lane_violation, order)
    make_event.previous_event = None
    make_event.next_event = foul_event
    foul_event.previous_event = make_event
    foul_event.next_event = lane_violation_event
    lane_violation_event.previous_event = foul_event
    lane_violation_event.next_event = None
    assert make_event.is_make_that_does_not_end_possession is True
예제 #4
0
def test_is_make_that_does_not_end_possession_with_foul_out_of_order_true():
    make = {
        "EVENTMSGTYPE": 1,
        "EVENTMSGACTIONTYPE": 10,
        "PLAYER1_ID": 15,
        "PLAYER1_TEAM_ID": 1,
        "HOMEDESCRIPTION": "Made Shot",
        "PCTIMESTRING": "0:45",
        "EVENTNUM": 1,
    }
    order = 1
    make_event = StatsFieldGoal(make, order)
    ft = {
        "EVENTMSGTYPE": 3,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Free Throw 1 of 1",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 15,
        "EVENTNUM": 2,
    }
    order = 1
    ft_event = StatsFreeThrow(ft, order)
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 2,
        "VISITORDESCRIPTION": "Shooting Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 12,
        "PLAYER2_ID": 15,
        "EVENTNUM": 3,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    make_event.previous_event = None
    make_event.next_event = ft_event
    ft_event.previous_event = make_event
    ft_event.next_event = foul_event
    foul_event.previous_event = ft_event
    foul_event.next_event = None
    assert make_event.is_make_that_does_not_end_possession is True
예제 #5
0
def test_foul_on_made_shot_by_team_that_didnt_get_fouled_is_away_from_play_ft(
):
    ft = {
        "EVENTMSGTYPE": 3,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Free Throw 1 of 1",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 1,
    }
    order = 1
    ft_event = StatsFreeThrow(ft, order)
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 6,
        "VISITORDESCRIPTION": "Away From Play Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 2,
        "PLAYER2_ID": 1,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    make = {
        "EVENTMSGTYPE": 1,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Made Shot by team that got fouled",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 3,
    }
    order = 1
    make_event = StatsFieldGoal(make, order)
    ft_event.previous_event = None
    ft_event.next_event = foul_event
    foul_event.previous_event = ft_event
    foul_event.next_event = make_event
    make_event.previous_event = foul_event
    make_event.next_event = None
    assert ft_event.is_away_from_play_ft is True
예제 #6
0
def test_away_from_play_free_throw_type():
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 6,
        "VISITORDESCRIPTION": "Away From Play Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 2,
        "PLAYER2_ID": 1,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    ft = {
        "EVENTMSGTYPE": 3,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Free Throw 1 of 1",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 1,
    }
    order = 1
    ft_event = StatsFreeThrow(ft, order)
    make = {
        "EVENTMSGTYPE": 1,
        "EVENTMSGACTIONTYPE": 10,
        "VISITORDESCRIPTION": "Made Shot by team that got fouled",
        "PCTIMESTRING": "0:35",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 21,
    }
    order = 1
    make_event = StatsFieldGoal(make, order)
    foul_event.previous_event = None
    foul_event.next_event = ft_event
    ft_event.previous_event = foul_event
    ft_event.next_event = make_event
    make_event.previous_event = ft_event
    make_event.next_event = None
    assert ft_event.free_throw_type == "1 Shot Away From Play"
예제 #7
0
def test_inbound_foul_ft_true():
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 5,
        "VISITORDESCRIPTION": "Inbound Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    ft = {
        "EVENTMSGTYPE": 3,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Free Throw 1 of 1",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
    }
    order = 1
    ft_event = StatsFreeThrow(ft, order)
    foul_event.previous_event = None
    foul_event.next_event = ft_event
    ft_event.previous_event = foul_event
    ft_event.next_event = None
    assert ft_event.is_inbound_foul_ft is True
예제 #8
0
def test_foul_on_made_ft_by_team_that_didnt_get_fouled_is_away_from_play_ft():
    ft_2_of_2 = {
        "EVENTNUM": 607,
        "PCTIMESTRING": "0:25",
        "VISITORDESCRIPTION": "Jackson Free Throw 2 of 2 (16 PTS)",
        "EVENTMSGACTIONTYPE": 12,
        "EVENTMSGTYPE": 3,
        "PLAYER1_ID": 202704,
        "PLAYER1_TEAM_ID": 1610612765,
        "PLAYER2_ID": None,
        "PLAYER2_TEAM_ID": None,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    ft_2_of_2_event = StatsFreeThrow(ft_2_of_2, order)
    foul = {
        "EVENTNUM": 609,
        "PCTIMESTRING": "0:25",
        "VISITORDESCRIPTION": "Griffin AWAY.FROM.PLAY.FOUL (P5.PN) (M.Davis)",
        "EVENTMSGACTIONTYPE": 6,
        "EVENTMSGTYPE": 6,
        "PLAYER1_ID": 201933,
        "PLAYER1_TEAM_ID": 1610612765,
        "PLAYER2_ID": 201145,
        "PLAYER2_TEAM_ID": 1610612764,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    ft_1_of_1 = {
        "EVENTNUM": 611,
        "PCTIMESTRING": "0:25",
        "HOMEDESCRIPTION": "Beal Free Throw 1 of 1 (32 PTS)",
        "EVENTMSGACTIONTYPE": 10,
        "EVENTMSGTYPE": 3,
        "PLAYER1_ID": 203078,
        "PLAYER1_TEAM_ID": 1610612764,
        "PLAYER2_ID": None,
        "PLAYER2_TEAM_ID": None,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    ft_1_of_1_event = StatsFreeThrow(ft_1_of_1, order)
    fg = {
        "EVENTNUM": 612,
        "PCTIMESTRING": "0:24",
        "VISITORDESCRIPTION": "MISS Green 27' 3PT Jump Shot",
        "EVENTMSGACTIONTYPE": 1,
        "EVENTMSGTYPE": 2,
        "PLAYER1_ID": 201145,
        "PLAYER1_TEAM_ID": 1610612764,
        "PLAYER2_ID": None,
        "PLAYER2_TEAM_ID": None,
        "PLAYER3_ID": None,
        "PLAYER3_TEAM_ID": None,
    }
    order = 1
    fg_event = StatsFieldGoal(fg, order)
    ft_2_of_2_event.previous_event = None
    ft_2_of_2_event.next_event = foul_event
    foul_event.previous_event = ft_2_of_2_event
    foul_event.next_event = ft_1_of_1_event
    ft_1_of_1_event.previous_event = foul_event
    ft_1_of_1_event.next_event = fg_event
    fg_event.previous_event = ft_1_of_1_event
    fg_event.next_event = None
    assert ft_1_of_1_event.is_away_from_play_ft is True
예제 #9
0
def test_is_make_that_does_not_end_possession_shot_at_time_of_and1_ft_is_false(
):
    make = {
        "EVENTMSGTYPE": 1,
        "EVENTMSGACTIONTYPE": 10,
        "PLAYER1_ID": 15,
        "PLAYER1_TEAM_ID": 1,
        "HOMEDESCRIPTION": "Made Shot",
        "PCTIMESTRING": "0:45",
        "EVENTNUM": 1,
    }
    order = 1
    make_event = StatsFieldGoal(make, order)
    foul = {
        "EVENTMSGTYPE": 6,
        "EVENTMSGACTIONTYPE": 2,
        "VISITORDESCRIPTION": "Shooting Foul",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 2,
        "PLAYER1_ID": 12,
        "PLAYER2_ID": 15,
        "EVENTNUM": 2,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    ft = {
        "EVENTMSGTYPE": 3,
        "EVENTMSGACTIONTYPE": 10,
        "HOMEDESCRIPTION": "Free Throw 1 of 1",
        "PCTIMESTRING": "0:45",
        "PLAYER1_TEAM_ID": 1,
        "PLAYER1_ID": 15,
        "EVENTNUM": 3,
    }
    order = 1
    ft_event = StatsFreeThrow(ft, order)
    rebound = {
        "EVENTMSGTYPE": 4,
        "EVENTMSGACTIONTYPE": 0,
        "PLAYER1_ID": 17,
        "PLAYER1_TEAM_ID": 1,
        "HOMEDESCRIPTION": "Rebound",
        "PCTIMESTRING": "0:45",
        "EVENTNUM": 4,
    }
    order = 2
    rebound_event = StatsRebound(rebound, order)
    tip = {
        "EVENTMSGTYPE": 1,
        "EVENTMSGACTIONTYPE": 10,
        "PLAYER1_ID": 17,
        "PLAYER1_TEAM_ID": 1,
        "HOMEDESCRIPTION": "Made Shot",
        "PCTIMESTRING": "0:45",
        "EVENTNUM": 5,
    }
    order = 1
    tip_event = StatsFieldGoal(tip, order)
    make_event.previous_event = None
    make_event.next_event = foul_event
    foul_event.previous_event = make_event
    foul_event.next_event = ft_event
    ft_event.previous_event = foul_event
    ft_event.next_event = rebound_event
    rebound_event.previous_event = ft_event
    rebound_event.next_event = tip_event
    tip_event.previous_event = rebound_event
    tip_event.next_event = None
    assert make_event.is_make_that_does_not_end_possession is True
    assert tip_event.is_make_that_does_not_end_possession is False
예제 #10
0
def test_jump_ball_foul_turnover_next_event_not_possession_change():
    shot = {
        "GAME_ID": "0021900510",
        "EVENTNUM": 225,
        "PCTIMESTRING": "6:40",
        "VISITORDESCRIPTION": "MISS Lowry  3PT Jump Shot",
        "EVENTMSGACTIONTYPE": 1,
        "EVENTMSGTYPE": 2,
        "PLAYER1_ID": 200768,
        "PLAYER1_TEAM_ID": 1610612761,
    }
    order = 1
    shot_event = StatsFieldGoal(shot, order)
    rebound = {
        "GAME_ID": "0021900510",
        "EVENTNUM": 226,
        "PCTIMESTRING": "6:38",
        "HOMEDESCRIPTION": "Silva REBOUND (Off:0 Def:1)",
        "EVENTMSGACTIONTYPE": 0,
        "EVENTMSGTYPE": 4,
        "PLAYER1_ID": 1629735,
        "PLAYER1_TEAM_ID": 1610612748,
    }
    order = 1
    rebound_event = StatsRebound(rebound, order)
    jump_ball = {
        "GAME_ID": "0021900510",
        "EVENTNUM": 228,
        "PCTIMESTRING": "6:29",
        "HOMEDESCRIPTION": "Jump Ball Silva vs. Boucher: Tip to Johnson",
        "EVENTMSGACTIONTYPE": 0,
        "EVENTMSGTYPE": 10,
        "PLAYER1_ID": 1629735,
        "PLAYER1_TEAM_ID": 1610612748,
        "PLAYER2_ID": 1628449,
        "PLAYER2_TEAM_ID": 1610612761,
        "PLAYER3_ID": 1626169,
        "PLAYER3_TEAM_ID": 1610612761,
    }
    order = 1
    jump_ball_event = StatsJumpBall(jump_ball, order)
    foul = {
        "GAME_ID": "0021900510",
        "EVENTNUM": 233,
        "PCTIMESTRING": "6:29",
        "HOMEDESCRIPTION": "Silva P.FOUL",
        "EVENTMSGACTIONTYPE": 1,
        "EVENTMSGTYPE": 6,
        "PLAYER1_ID": 1629735,
        "PLAYER1_TEAM_ID": 1610612748,
        "PLAYER2_ID": 1628449,
        "PLAYER2_TEAM_ID": 1610612761,
    }
    order = 1
    foul_event = StatsFoul(foul, order)
    turnover = {
        "GAME_ID": "0021900510",
        "EVENTNUM": 233,
        "PCTIMESTRING": "6:29",
        "HOMEDESCRIPTION": "Silva Foul Turnover",
        "EVENTMSGACTIONTYPE": 37,
        "EVENTMSGTYPE": 5,
        "PLAYER1_ID": 1629735,
        "PLAYER1_TEAM_ID": 1610612748,
    }
    order = 1
    turnover_event = StatsTurnover(turnover, order)

    shot_event.previous_event = None
    shot_event.next_event = rebound_event
    rebound_event.previous_event = shot_event
    rebound_event.next_event = jump_ball_event
    jump_ball_event.previous_event = rebound_event
    jump_ball_event.next_event = foul_event
    foul_event.previous_event = jump_ball_event
    foul_event.next_event = turnover_event
    turnover_event.previous_event = foul_event
    turnover_event.next_event = None

    jump_ball_event.possession_changing_override = False
    jump_ball_event.non_possession_changing_override = False

    assert jump_ball_event.is_possession_ending_event is False