<commit_before>"""MPF plugin which uses lights to represent Game functions. Typically in an
EM machine"""

import logging

from mpf.devices.led import Led


class InfoLights(object):

    def __init__(self, machine):
        self.log = logging.getLogger('infolights')
        self.machine = machine

        try:
            self.config = self.machine.config['info_lights']
        except KeyError:
            self.machine.log.debug('"info_lights:" section not found in machine '
                                   'configuration, so the Info Lights plugin '
                                   'will not be used.')
            return

        self.machine.events.add_handler('machine_reset_phase_3', self._initialize)

    def _initialize(self):
        # convert any light names we find to objects
        for key, value in self.config.items():
            if 'light' in value:
                if value['light'] in self.machine.lights:
                    self.config[key]['light'] = self.machine.lights[value['light']]
                elif value['light'] in self.machine.leds:
                    self.config[key]['light'] = self.machine.leds[value['light']]
                else:
                    raise AssertionError("Invalid light or led {}".format(value['light']))

        self.machine.events.add_handler('ball_started', self.ball_started)
        self.machine.events.add_handler('game_ended', self.game_ended)
        self.machine.events.add_handler('game_starting', self.game_starting)
        self.machine.events.add_handler('player_add_success', self.player_added)
        self.machine.events.add_handler('tilt', self.tilt)
        self.machine.events.add_handler('match', self.match)

        self.game_ended()  # set the initial lights to the game ended state

    def reset_game_lights(self):
        self.log.debug("reset_game_lights")
        # turn off the game-specific lights (player, ball & match)
        for key, value in self.config.items():
            if key.startswith('ball_'):
                value['light'].off()
            if key.startswith('player_'):
                value['light'].off()
            if key.startswith('match_'):
                value['light'].off()

    def ball_started(self, **kwargs):
        del kwargs
        self.log.debug("ball_started")
        # turn off all the ball lights
        for key, value in self.config.items():
            if key.startswith('ball_'):
                value['light'].off()

        # turn on this current ball's light
        ball_light = 'ball_' + str(self.machine.game.player.ball)
        if ball_light in self.config:
            self.config[ball_light]['light'].on()

        # turn off the tilt light
        if 'tilt' in self.config:
            self.config['tilt']['light'].off()

    def game_ended(self, **kwargs):
        del kwargs
        self.log.debug("game_ended")
        self.reset_game_lights()

        # turn on game over
        if 'game_over' in self.config:
            if isinstance(self.config['game_over']['light'], Led):
                self.machine.shows['flash'].play(
                    show_tokens=dict(leds=self.config['game_over']['light']),
                    key='infolights_game_over')
            else:
                self.machine.shows['flash'].play(
                    show_tokens=dict(lights=self.config['game_over']['light']),
                    key='infolights_game_over')

    def game_starting(self, **kwargs):
        del kwargs
        self.log.debug("game_starting")
        self.reset_game_lights()
        if self.machine.show_controller.get_running_shows('infolights_game_over'):
            self.machine.show_controller.get_running_shows('infolights_game_over')[0].stop()

    def player_added(self, player, **kwargs):
        del kwargs
        self.log.debug("player_added. player=%s", player)
        player_str = 'player_' + str(player.number)
        self.log.debug("player_str: %s", player_str)
        if player_str in self.config:
            self.config[player_str]['light'].on()<commit_msg>no more keys in shows<commit_after>"""MPF plugin which uses lights to represent Game functions. Typically in an
EM machine"""

import logging

from mpf.devices.led import Led


class InfoLights(object):

    def __init__(self, machine):
        self.log = logging.getLogger('infolights')
        self.machine = machine
        self.game_over_show = None

        try:
            self.config = self.machine.config['info_lights']
        except KeyError:
            self.machine.log.debug('"info_lights:" section not found in machine '
                                   'configuration, so the Info Lights plugin '
                                   'will not be used.')
            return

        self.machine.events.add_handler('machine_reset_phase_3', self._initialize)

    def _initialize(self):
        # convert any light names we find to objects
        for key, value in self.config.items():
            if 'light' in value:
                if value['light'] in self.machine.lights:
                    self.config[key]['light'] = self.machine.lights[value['light']]
                elif value['light'] in self.machine.leds:
                    self.config[key]['light'] = self.machine.leds[value['light']]
                else:
                    raise AssertionError("Invalid light or led {}".format(value['light']))

        self.machine.events.add_handler('ball_started', self.ball_started)
        self.machine.events.add_handler('game_ended', self.game_ended)
        self.machine.events.add_handler('game_starting', self.game_starting)
        self.machine.events.add_handler('player_add_success', self.player_added)
        self.machine.events.add_handler('tilt', self.tilt)
        self.machine.events.add_handler('match', self.match)

        self.game_ended()  # set the initial lights to the game ended state

    def reset_game_lights(self):
        self.log.debug("reset_game_lights")
        # turn off the game-specific lights (player, ball & match)
        for key, value in self.config.items():
            if key.startswith('ball_'):
                value['light'].off()
            if key.startswith('player_'):
                value['light'].off()
            if key.startswith('match_'):
                value['light'].off()

    def ball_started(self, **kwargs):
        del kwargs
        self.log.debug("ball_started")
        # turn off all the ball lights
        for key, value in self.config.items():
            if key.startswith('ball_'):
                value['light'].off()

        # turn on this current ball's light
        ball_light = 'ball_' + str(self.machine.game.player.ball)
        if ball_light in self.config:
            self.config[ball_light]['light'].on()

        # turn off the tilt light
        if 'tilt' in self.config:
            self.config['tilt']['light'].off()

    def game_ended(self, **kwargs):
        del kwargs
        self.log.debug("game_ended")
        self.reset_game_lights()

        # turn on game over
        if 'game_over' in self.config:
            if self.game_over_show:
                self.game_over_show.stop()
            if isinstance(self.config['game_over']['light'], Led):
                self.game_over_show = self.machine.shows['flash'].play(
                    show_tokens=dict(leds=self.config['game_over']['light']))
            else:
                self.game_over_show = self.machine.shows['flash'].play(
                    show_tokens=dict(lights=self.config['game_over']['light']))

    def game_starting(self, **kwargs):
        del kwargs
        self.log.debug("game_starting")
        self.reset_game_lights()
        if self.game_over_show:
            self.game_over_show.stop()

    def player_added(self, player, **kwargs):
        del kwargs
        self.log.debug("player_added. player=%s", player)
        player_str = 'player_' + str(player.number)
        self.log.debug("player_str: %s", player_str)
        if player_str in self.config:
            self.config[player_str]['light'].on()
{'fraction_non_alphanumeric': 0.12110683707656036, 'fraction_numerical': 0.0003722546221615585, 'mean_word_length': 2.189552829442026, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798248', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2209, 'n_words': 482}