Untitled
import math class GHICalculator: # Dew point ranges and their corresponding comfort levels and colors COMFORT_RANGES = [ {'max': 10, 'label': 'dry', 'color': '#5ECBFC'}, {'max': 15, 'label': 'very comfortable', 'color': '#62FF3B'}, {'max': 18, 'label': 'comfortable', 'color': '#CBFF73'}, {'max': 20, 'label': 'alright', 'color': '#FFFF9E'}, {'max': 24, 'label': 'uncomfortable', 'color': '#FFD239'}, {'max': 26, 'label': 'very uncomfortable', 'color': '#FF981E'}, {'max': float('inf'), 'label': 'severely uncomfortable', 'color': '#FF6610'} ] @staticmethod def calculate_ghi(dew_point: float) -> dict: """ Calculate the Global Humidity Index (GHI) based on dew point. Args: dew_point (float): Dew point temperature in Celsius Returns: dict: Contains normalized GHI value (0-100), comfort level label, and color code """ # Normalize dew point to 0-100 scale normalized_ghi = math.ceil((dew_point / 38) * 100) normalized_ghi = max(0, min(100, normalized_ghi)) # Ensure it's between 0-100 # Determine comfort level and color based on dew point comfort_info = None for range_info in GHICalculator.COMFORT_RANGES: if dew_point <= range_info['max']: comfort_info = range_info break return { 'ghi': normalized_ghi, 'comfort_level': comfort_info['label'], 'color': comfort_info['color'] }
Leave a Comment