# Path: app/utils.py
# def rgb_to_hex(r, g, b):
#     return '#%02x%02x%02x' % (int(r * 255), int(g * 255), int(b * 255))


from colorsys import hsv_to_rgb
from app.utils import rgb_to_hex



def calculate_color(value, interval_length):
    assert interval_length >= 0
    
    if interval_length == 0:
        return rgb_to_hex(1, 0, 0)
    
    hue = 240 - 240 * value / interval_length

# Path: app/utils.py
# def rgb_to_hex(r, g, b):
#     return '#%02x%02x%02x' % (int(r * 255), int(g * 255), int(b * 255))


# Path: app/services/temperature_map.py
from colorsys import hsv_to_rgb
from app.utils import rgb_to_hex




def calculate_color(value, interval_length):
    assert interval_length >= 0
    
    if interval_length == 0:
        return rgb_to_hex(1, 0, 0)
    
    hue = 240 - 240 * value / interval_length

    return rgb_to_hex(*hsv_to_rgb(hue / 360, 1, 1))