def transform_to_range(val, old_min, old_max, new_min, new_max):
    """
    Transform a value from an old range to a new range
    :return: scaled value
    """
    old_range = (old_max - old_min)
    new_range = (new_max - new_min)
    new_val = (((val - old_min) * new_range) / old_range) + new_min
    return new_val