import functools


def build_run_time_transformers(ranges, buckets=250):
  """ Build a dict of functions to transform from a timestamp into a relative

    offset.  E.g.
    input: {'v17': (1234567890, 1235567879) ... }
    output: {'v17': lambda t: (t - min) * (1/max) ... }
  """

  funcs = {}

  def f(t, min_, max_):
    # return "%0.2f" % ((t-min_) * (1/(max_-min_)))
    key = (t - min_) * (1 / (max_ - min_))
    return "%0.3f" % (int(buckets * key) / (buckets / 100.0))

  for run, range_ in ranges.items():
    funcs[run] = functools.partial(f, min_=range_[0], max_=range_[1])

  return funcs