<commit_before>from collections import namedtuple
from toon.anim.easing import linear
from toon.anim.interpolators import lerp, select


class Track(object):
    def __init__(self, data, interpolator=lerp, easing=linear):
        # data is list of tuples
        self.data = data
        self.interpolator = interpolator
        self.easing = easing
        # if data is non-numeric, force user to use select
        if not isinstance(data[0][1], (float, int)):
            self.interpolator = select
            self.easing = linear

    def at(self, time):
        # find the two keyframes to interpolate between
        # rel_time is the time relative to the start
        try:
            index, goal = next((i, x) for i, x in enumerate(self.data) if x[0] > time)
        except StopIteration:
            # TODO: Extrapolation (currently equivalent to constant)
            return self.data[-1][1]
        # prev keyframe to check against
        reference = self.data[index - 1]
        # calculate time stuff
        goal_time = goal[0] - reference[0]
        new_time = time - reference[0]
        time_warp = self.easing(1 - ((goal_time - new_time)/goal_time))
        return self.interpolator(reference[1], goal[1], time_warp)

    def duration(self):
        # last time in keyframes
        return self.data[-1][0]
<commit_msg>Better behavior if track does not start at 0<commit_after>from collections import namedtuple
from toon.anim.easing import linear
from toon.anim.interpolators import lerp, select


class Track(object):
    def __init__(self, data, interpolator=lerp, easing=linear):
        # data is list of tuples
        self.data = data
        self.interpolator = interpolator
        self.easing = easing
        # if data is non-numeric, force user to use select
        if not isinstance(data[0][1], (float, int)):
            self.interpolator = select
            self.easing = linear

    def at(self, time):
        # find the two keyframes to interpolate between
        # rel_time is the time relative to the start
        if time < self.data[0][0]:
            # TODO: extrapolation (currently equivalent to constant)
            return self.data[0][1]
        try:
            index, goal = next((i, x) for i, x in enumerate(self.data) if x[0] > time)
        except StopIteration:
            # TODO: Extrapolation (currently equivalent to constant)
            return self.data[-1][1]
        # prev keyframe to check against
        reference = self.data[index - 1]
        # calculate time stuff
        goal_time = goal[0] - reference[0]
        new_time = time - reference[0]
        time_warp = self.easing(1 - ((goal_time - new_time)/goal_time))
        return self.interpolator(reference[1], goal[1], time_warp)

    def duration(self):
        # last time in keyframes
        return self.data[-1][0]

{'fraction_non_alphanumeric': 0.09199438202247191, 'fraction_numerical': 0.011587078651685394, 'mean_word_length': 2.3360655737704916, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '1260114', 'n_tokens_mistral': 840, 'n_tokens_neox': 809, 'n_words': 265}