<commit_before>import json
import logging

from google.appengine.api import taskqueue
from google.appengine.ext import ndb

from helpers.cache_clearer import CacheClearer
from helpers.firebase.firebase_pusher import FirebasePusher
from helpers.gcm_message_helper import GCMMessageHelper
from helpers.manipulator_base import ManipulatorBase


class MatchManipulator(ManipulatorBase):
    """
    Handle Match database writes.
    """
    @classmethod
    def getCacheKeysAndControllers(cls, affected_refs):
        return CacheClearer.get_match_cache_keys_and_controllers(affected_refs)

    @classmethod
    def postUpdateHook(cls, matches):
        '''
        To run after the match has been updated.
        Send push notifications to subscribed users
        '''
        for match in matches:
            logging.info("Sending push notifications for "+match.key_name)
            try:
                GCMMessageHelper.send_match_score_update(match)
            except exception:
                logging.error("Error sending match updates: "+str(exception))

        '''<commit_msg>Only send match score updates during an active event<commit_after>import json
import logging

from google.appengine.api import taskqueue
from google.appengine.ext import ndb

from helpers.cache_clearer import CacheClearer
from helpers.firebase.firebase_pusher import FirebasePusher
from helpers.gcm_message_helper import GCMMessageHelper
from helpers.manipulator_base import ManipulatorBase

from models.event import Event


class MatchManipulator(ManipulatorBase):
    """
    Handle Match database writes.
    """
    @classmethod
    def getCacheKeysAndControllers(cls, affected_refs):
        return CacheClearer.get_match_cache_keys_and_controllers(affected_refs)

    @classmethod
    def postUpdateHook(cls, matches):
        '''
        To run after the match has been updated.
        Send push notifications to subscribed users
        Only if the match is part of an active event
        '''
        for match in matches:
            if match.event.get().now:
                logging.info("Sending push notifications for "+match.key_name)
                try:
                    GCMMessageHelper.send_match_score_update(match)
                except exception:
                    logging.error("Error sending match updates: "+str(exception))

        '''
{'fraction_non_alphanumeric': 0.05994897959183673, 'fraction_numerical': 0.0, 'mean_word_length': 3.0709342560553634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1853096', 'n_tokens_mistral': 629, 'n_tokens_neox': 609, 'n_words': 176}