<commit_before>""" The various classes relating to animations """
from __future__ import print_function
from __future__ import division

import math

from random import randint
import time

class Animation(object):
    """The base class for any animation. An animation is a state machine that produces frames.
       Keep calling get_frame until is_complete returns true.
    """
    def __init__(self, milliseconds=None):
        """ Animation base class initializer """
        object.__init__(self)
        if milliseconds is None:
            self._milliseconds = lambda: int(round(time.time() * 1000))
        else:
            self._milliseconds = milliseconds

    def get_frame(self):
        """Return an array of tuples (r,g,b) i.e. the frame for the current state of the animation"""
        raise RuntimeError("GetFrame should only be called in derived classes")

    def is_complete(self):
        """True if this animation is complete and can be removed"""
        return False

class FireAnimation(Animation):
    """ Fire animation """
    def __init__(self):
        Animation.__init__(self)
        self._lights = []
        self._r = 255
        self._g = 255 - 40
        self._b = 40
        self._end = 0

    def get_frame(self):
        if self._milliseconds() > self._end:
            self._end = self._milliseconds() + 50
            self._lights = []
            for i in range(0, 88):
                flicker = randint(0, 150)
                r1 = self._r - flicker
                g1 = self._g - flicker
                b1 = self._b - flicker
                if r1 < 0:
                    r1 = 0
                if g1 < 0:
                    g1 = 0
                if b1 < 0:
                    b1 = 0
                self._lights.append((r1, g1, b1))
        return self._lights

    def is_complete(self):
        return False

class BeatAnimation(Animation):
    """Lights up on a specific beat"""
    def __init__(self, width, bpm, milliseconds=None):
        Animation.__init__(self, milliseconds=None)
        self._ms_per_beat = 1000 / (bpm / 60) 
        self._current_pulse_time = self._milliseconds()
        self._width = width
        self._bell_curve = BeatAnimation.create_bell_curve(width)

    @classmethod
    def create_bell_curve(cls, width):<commit_msg>Add animation that runs side to side.<commit_after>""" The various classes relating to animations """
from __future__ import print_function
from __future__ import division

import math

from random import randint
import time

class Animation(object):
    """The base class for any animation. An animation is a state machine that produces frames.
       Keep calling get_frame until is_complete returns true.
    """
    def __init__(self, milliseconds=None):
        """ Animation base class initializer

        Parameters
        ----------
        milliseconds : function, optional
            Optional function that returns the number of milliseconds elapsed. A default implementation
            is provided that uses the system time. Provide an alternative function if time must be
            externally controlled. This is useful in unit testing scenarios.
        """
        object.__init__(self)
        if milliseconds is None:
            self._milliseconds = lambda: int(round(time.time() * 1000))
        else:
            self._milliseconds = milliseconds

    def get_frame(self):
        """Return an array of tuples (r,g,b) i.e. the frame for the current state of the animation"""
        raise RuntimeError("GetFrame should only be called in derived classes")

    def is_complete(self):
        """True if this animation is complete and can be removed"""
        return False

class LeftRightAnimation(Animation):
    """ Light runs side to side """
    def __init__(self, milliseconds, length, frames_per_second):
        """
        Parameters
        ----------
        length : integer
        The number of lights in the animation
        """
        Animation.__init__(self, milliseconds)
        self._ = [length]
        self._index = 0
        self._last_frame_time = 0
        self._milliseconds_per_frame = 1000 / frames_per_second
        self._direction = 1

    def get_frame(self):
        now = self._milliseconds()
        if now - self._last_frame_time > self._milliseconds_per_frame:
            self._last_frame_time = now
            self._index += self._direction
            leds = [(0, 0, 0)] * 88

        return self._lights


class FireAnimation(Animation):
    """ Fire animation """
    def __init__(self):
        Animation.__init__(self)
        self._lights = []
        self._r = 255
        self._g = 255 - 40
        self._b = 40
        self._end = 0

    def get_frame(self):
        if self._milliseconds() > self._end:
            self._end = self._milliseconds() + 50
            self._lights = []
            for _ in range(0, 88):
                flicker = randint(0, 150)
                r1 = self._r - flicker
                g1 = self._g - flicker
                b1 = self._b - flicker
                if r1 < 0:
                    r1 = 0
                if g1 < 0:
                    g1 = 0
                if b1 < 0:
                    b1 = 0
                self._lights.append((r1, g1, b1))
        return self._lights

    def is_complete(self):
        return False

class BeatAnimation(Animation):
    """Lights up on a specific beat"""
    def __init__(self, width, bpm, milliseconds=None):
        Animation.__init__(self, milliseconds=None)
        self._ms_per_beat = 1000 / (bpm / 60) 
        self._current_pulse_time = self._milliseconds()
        self._width = width
        self._bell_curve = BeatAnimation.create_bell_curve(width)

    @classmethod
    def create_bell_curve(cls, width):
{'fraction_non_alphanumeric': 0.08773144142585222, 'fraction_numerical': 0.01868835438657207, 'mean_word_length': 1.9595494111623144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, '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': '5968853', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1491, 'n_words': 504}