Ejemplo n.º 1
0
def test_club_match_action_insert(session, club_match_lineup):
    club, match, lineups = club_match_lineup

    events = [
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  period=1,
                                                  period_secs=0),
                         type=enums.ActionType.start_period),
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  period=1,
                                                  period_secs=2902),
                         type=enums.ActionType.end_period)
    ]
    session.add_all(events)
    session.commit()

    event_from_db = session.query(mc.ClubMatchEvents)
    assert event_from_db.count() == 2

    start_event = session.query(
        mce.MatchActions).filter_by(type=enums.ActionType.start_period).one()
    assert start_event.event == events[0].event
    assert start_event.lineup_id is None

    end_event = session.query(
        mce.MatchActions).filter_by(type=enums.ActionType.end_period).one()
    assert end_event.event == events[1].event
    assert end_event.lineup_id is None

    non_touch_events = session.query(mce.MatchActions).join(mc.ClubMatchEvents)\
        .filter(mc.ClubMatchEvents.x.is_(None), mc.ClubMatchEvents.y.is_(None))
    assert non_touch_events.count() == 2
    assert set([rec.type for rec in non_touch_events]) == {
        enums.ActionType.start_period, enums.ActionType.end_period
    }
Ejemplo n.º 2
0
    def events(self, data_frame):
        event_set = set()
        event_records = []
        remote_ids = []
        local_ids = []
        fields = ['timestamp', 'period', 'period_secs', 'x', 'y', 'match_id', 'team_id', 'remote_id']
        for _, row in data_frame.iterrows():
            event_set.add(tuple([(field, row[field]) for field in fields
                                 if field in row and row[field] is not None]))
        logger.info("{} unique events".format(len(event_set)))
        for indx, elements in enumerate(event_set):
            if indx and indx % 100 == 0:
                logger.info("Processing {} events".format(indx))
            event_dict = dict(elements)
            remote_id = event_dict.pop('remote_id')
            if 'team_id' not in event_dict:
                # if not self.record_exists(mce.MatchEvents, **event_dict):
                event_dict.update(id=uuid.uuid4())
                event_records.append(mce.MatchEvents(**event_dict))
                remote_ids.append(remote_id)
                local_ids.append(event_dict['id'])
            else:
                # if not self.record_exists(mc.ClubMatchEvents, **event_dict):
                event_dict.update(id=uuid.uuid4())
                event_records.append(mc.ClubMatchEvents(**event_dict))
                remote_ids.append(remote_id)
                local_ids.append(event_dict['id'])
        self.session.bulk_save_objects(event_records)

        map_records = [mcs.MatchEventMap(id=local_id, remote_id=remote_id, supplier_id=self.supplier_id)
                       for remote_id, local_id in zip(remote_ids, local_ids) if remote_id]
        self.session.bulk_save_objects(map_records)
        self.session.commit()
Ejemplo n.º 3
0
def test_club_missed_pass_event(session, club_match_lineup, modifiers):
    club, match, lineups = club_match_lineup

    modifier_objs = [
        mce.Modifiers(type=enums.ModifierType.from_string(record['modifier']),
                      category=enums.ModifierCategoryType.from_string(
                          record['category'])) for record in modifiers
    ]
    session.add_all(modifier_objs)
    session.commit()

    events = [
        mce.MatchActions(
            event=mc.ClubMatchEvents(match_id=match.id,
                                     team_id=club.id,
                                     period=1,
                                     period_secs=921,
                                     x=75.3,
                                     y=98.4),
            type=enums.ActionType.ball_pass,
            lineup_id=lineups[0].id,
            x_end=82.2,
            y_end=75.0,
        ),
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  team_id=club.id,
                                                  period=1,
                                                  period_secs=1143,
                                                  x=67.3,
                                                  y=62.1),
                         type=enums.ActionType.ball_pass,
                         lineup_id=lineups[0].id,
                         x_end=82.2,
                         y_end=50.0,
                         is_success=False)
    ]
    session.add_all(events)
    session.commit()

    pass_actions = session.query(mce.MatchActions).join(mc.ClubMatchEvents).\
        filter(mce.MatchActions.type == enums.ActionType.ball_pass)
    assert pass_actions.count() == 2

    missed_passes = pass_actions.filter(
        mce.MatchActions.is_success.in_([False]))
    assert missed_passes.count() == 1
Ejemplo n.º 4
0
def test_club_match_action_insert(session, club_match_lineup):
    club, match, lineups = club_match_lineup

    events = [
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  period=1,
                                                  period_secs=0),
                         type=enums.ActionType.start_period),
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  team_id=club.id,
                                                  period=1,
                                                  period_secs=1143,
                                                  x=67.3,
                                                  y=62.1),
                         type=enums.ActionType.ball_pass,
                         lineup_id=lineups[0].id,
                         x_end=82.2,
                         y_end=50.0),
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  team_id=club.id,
                                                  period=1,
                                                  period_secs=1150,
                                                  x=84.0,
                                                  y=48.8),
                         type=enums.ActionType.goal,
                         lineup_id=lineups[1].id,
                         x_end=100.0,
                         y_end=45.0,
                         z_end=10.0)
    ]
    session.add_all(events)
    session.commit()

    pass_actions = session.query(mce.MatchActions).join(mc.ClubMatchEvents).\
        filter(mce.MatchActions.type == enums.ActionType.ball_pass)
    assert pass_actions.count() == 1

    pass_event = session.query(mc.ClubMatchEvents).get(
        pass_actions[0].event_id)
    assert pass_event.period == 1
    assert pass_event.period_secs == 1143
    assert pass_event.x == 67.3
    assert pass_event.y == 62.1
Ejemplo n.º 5
0
def test_club_goal_event_view(session, club_match_lineup):
    club, match, lineups = club_match_lineup

    events = [
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  period=1,
                                                  period_secs=0),
                         type=enums.ActionType.start_period),
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  team_id=club.id,
                                                  period=1,
                                                  period_secs=1143,
                                                  x=67.3,
                                                  y=62.1),
                         type=enums.ActionType.ball_pass,
                         lineup_id=lineups[0].id,
                         x_end=82.2,
                         y_end=50.0),
        mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                  team_id=club.id,
                                                  period=1,
                                                  period_secs=1150,
                                                  x=84.0,
                                                  y=48.8),
                         type=enums.ActionType.goal,
                         lineup_id=lineups[1].id,
                         x_end=100.0,
                         y_end=45.0,
                         z_end=10.0)
    ]
    session.add_all(events)
    session.commit()

    goal_events = session.query(mc.ClubGoals)
    assert goal_events.count() == 1
    assert goal_events[0].match_id == match.id
    assert goal_events[0].lineup_id == lineups[1].id
    assert goal_events[0].team_id == lineups[1].team_id
    assert goal_events[0].period == 1
    assert goal_events[0].period_secs == 1150
    assert goal_events[0].x == 84.0
    assert goal_events[0].y == 48.8
Ejemplo n.º 6
0
def test_club_goal_modifier_insert(session, club_match_lineup, modifiers):
    club, match, lineups = club_match_lineup

    modifier_objs = [
        mce.Modifiers(type=enums.ModifierType.from_string(record['modifier']),
                      category=enums.ModifierCategoryType.from_string(
                          record['category'])) for record in modifiers
    ]
    session.add_all(modifier_objs)
    session.commit()

    goal_action = mce.MatchActions(event=mc.ClubMatchEvents(match_id=match.id,
                                                            team_id=club.id,
                                                            period=1,
                                                            period_secs=1150,
                                                            x=84.0,
                                                            y=48.8),
                                   type=enums.ActionType.goal,
                                   lineup_id=lineups[1].id,
                                   x_end=100.0,
                                   y_end=45.0,
                                   z_end=10.0)
    session.add(goal_action)
    session.commit()

    goal_modifiers = [
        mce.MatchActionModifiers(
            action_id=goal_action.id,
            modifier_id=session.query(mce.Modifiers.id).filter_by(
                type=enums.ModifierType.head).scalar()),
        mce.MatchActionModifiers(
            action_id=goal_action.id,
            modifier_id=session.query(mce.Modifiers.id).filter_by(
                type=enums.ModifierType.center_penalty_area).scalar()),
        mce.MatchActionModifiers(
            action_id=goal_action.id,
            modifier_id=session.query(mce.Modifiers.id).filter_by(
                type=enums.ModifierType.lower_right).scalar())
    ]
    session.add_all(goal_modifiers)
    session.commit()

    action_from_db = session.query(
        mc.ClubGoals).filter_by(action_id=goal_action.id).one()

    goal_body_part = session.query(mce.Modifiers).join(mce.MatchActionModifiers)\
        .filter(mce.MatchActionModifiers.action_id == action_from_db.action_id,
                mce.Modifiers.category == enums.ModifierCategoryType.bodypart)
    assert goal_body_part.count() == 1
    assert goal_body_part[0].type.value == "Head"

    goal_sector = session.query(mce.Modifiers).join(mce.MatchActionModifiers)\
        .filter(mce.MatchActionModifiers.action_id == action_from_db.action_id,
                mce.Modifiers.category == enums.ModifierCategoryType.field_sector)
    assert goal_sector.count() == 1
    assert goal_sector[0].type.value == "Central Penalty Area"

    goal_goal_region = session.query(mce.Modifiers).join(mce.MatchActionModifiers)\
        .filter(mce.MatchActionModifiers.action_id == action_from_db.action_id,
                mce.Modifiers.category == enums.ModifierCategoryType.goal_region)
    assert goal_goal_region.count() == 1
    assert goal_goal_region[0].type.value == "Lower Right"