@@ -0,0 +1,1986 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Aimport logging%0A%0Alogger = logging.getLogger(__name__)%0A%0A%0Adef is_matching_event(play, event):%0A    %22%22%22%0A    Checks whether specified play (retrieved from json data) and database event%0A    match.%0A    %22%22%22%0A    if play%5B'play_type'%5D == 'PENL':%0A        return is_matching_penalty_event(event, play)%0A    # elif event.type in %5B'HIT', 'BLOCK', 'FAC'%5D:%0A    #     return is_matching_hit_block_faceoff_event(play, event)%0A    # elif event.type in %5B'GIVE', 'TAKE'%5D:%0A    #     return is_matching_giveaway_takeaway_event(play, event)    %0A    # elif event.type in %5B'SHOT', 'GOAL'%5D:%0A    #     return is_matching_shot_event(play, event)%0A    # elif event.type == 'MISS':%0A    #     return is_matching_miss_event(play, event)%0A%0A    return False%0A%0A%0Adef is_matching_penalty_event(penalty, play):%0A    %22%22%22%0A    Checks whether the given play retrieved from json data matches with the%0A    specified (penalty) event.%0A    %22%22%22%0A    print(%22%5Ctid %22, play%5B'active'%5D, penalty.player_id)%0A    print(%22%5Ctpim %22, play%5B'pim'%5D, penalty.pim)%0A    print(%22%5Ctinfraction%22, play%5B'infraction'%5D, penalty.infraction.lower())%0A%0A    if penalty.player_id is None:%0A        if (%0A            play%5B'pim'%5D, play%5B'infraction'%5D%0A        ) == (%0A            penalty.pim, penalty.infraction.lower()%0A        ):%0A            # TODO: logger.debug%0A            return True%0A    else:%0A        if play%5B'active'%5D is not None and play%5B'passive'%5D is not None:%0A            if (%0A                play%5B'active'%5D, play%5B'passive'%5D,%0A                play%5B'pim'%5D, play%5B'infraction'%5D%0A            ) == (%0A                penalty.player_id, penalty.drawn_player_id,%0A                penalty.pim, penalty.infraction.lower()%0A            ):%0A                return True%0A        elif play%5B'active'%5D is not None:%0A            if (%0A                play%5B'active'%5D, play%5B'pim'%5D, play%5B'infraction'%5D%0A            ) == (%0A                penalty.player_id, penalty.pim, penalty.infraction.lower()%0A            ):%0A                return True%0A%0A    return False%0A

Add utility functions to distinguish events with same type/time