<commit_before>import blinkypattern

# TBD: TrapezoidalFade vs SinusoidalFade?
class Fade(blinkypattern.BlinkyPattern):
    def __init__(self, blinkytape, color_list, period_sec):
        super(Fade, self).__init__(blinkytape)
        self._animated = True
        self._index = 0
        self._profile = self._make_fade_profile(color_list, period_sec)

    def animate(self):
        super(Fade, self).setup()
        pixels = [self._profile[self._index]] * self._blinkytape.pixel_count
        self._blinkytape.set_pixels(pixels)
        self._blinkytape.update()
        self._index = (self._index + 1) % len(self._profile)

    def _make_fade_profile(self, color_list, period_sec):
        steps_per_period = period_sec / self._timebase_sec
        profile = []
        for color in color_list:
            profile.extend([color] * int(steps_per_period))
        return profile<commit_msg>Refactor fade logic a bit to isolate ramp production<commit_after>import blinkypattern
import itertools

# TBD: TrapezoidalFade vs SinusoidalFade?
class Fade(blinkypattern.BlinkyPattern):
    def __init__(self, blinkytape, color_list, period_sec):
        super(Fade, self).__init__(blinkytape)
        self._animated = True
        self._index = 0
        self._profile = self._make_fade_profile(color_list, period_sec)

    def animate(self):
        super(Fade, self).setup()
        pixels = [self._profile[self._index]] * self._blinkytape.pixel_count
        self._blinkytape.set_pixels(pixels)
        self._blinkytape.update()
        self._index = (self._index + 1) % len(self._profile)

    def _make_fade_profile(self, color_list, period_sec):
        steps_per_period = int(period_sec / self._timebase_sec)
        circular_color_list = color_list + [color_list[0]]
        profile = []
        for this_color, next_color in self._pairwise(circular_color_list):
            ramp = self._make_color_ramp(this_color, next_color, steps_per_period)
            constant = self._make_constant_color(next_color, steps_per_period)
            profile.extend(ramp + constant)
        return profile

    def _make_constant_color(self, color, count):
        return [color] * count

    def _make_color_ramp(self, first_color, second_color, step_count):
        return []

    def _pairwise(self, iterable):
        this_iter, next_iter = itertools.tee(iterable)
        next(next_iter)
        return itertools.izip(this_iter, next_iter)
{'fraction_non_alphanumeric': 0.093711467324291, 'fraction_numerical': 0.002055076037813399, 'mean_word_length': 3.2256944444444446, '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': '4594701', 'n_tokens_mistral': 793, 'n_tokens_neox': 779, 'n_words': 145}