Exemplo n.º 1
0
def get_mix_and_color(color_by_category, airport):
    """
    Gets the proportion of color mixes (dark to NIGHT, NIGHT to color) and the final color to render.

    Arguments:
        color_by_category {tuple} -- the initial color decided upon by weather.
        airport {string} -- The station identifier.

    Returns:
        tuple -- proportion, color to render
    """

    color_to_render = color_by_category
    proportions = weather.get_twilight_transition(airport)

    if configuration.get_night_lights():
        if proportions[0] <= 0.0 and proportions[1] <= 0.0:
            color_to_render = colors[weather.DARK_YELLOW]
        # Do not allow color mixing for standard LEDs
        # Instead if we are going to render NIGHT then
        # have the NIGHT color represent that the station
        # is in a twilight period.
        elif configuration.get_mode() == configuration.STANDARD:
            if proportions[0] > 0.0 or proportions[1] < 1.0:
                color_to_render = color_by_rules[weather.NIGHT]
            elif proportions[0] <= 0.0 and proportions[1] <= 0.0:
                color_to_render = colors[weather.DARK_YELLOW]
        elif proportions[0] > 0.0:
            color_to_render = colors_lib.get_color_mix(
                colors[weather.DARK_YELLOW], color_by_rules[weather.NIGHT], proportions[0])
        elif proportions[1] > 0.0:
            color_to_render = colors_lib.get_color_mix(
                color_by_rules[weather.NIGHT], color_by_category, proportions[1])
    return proportions, color_to_render
Exemplo n.º 2
0
def __get_rgb_night_color_to_render__(
    color_by_category,
    proportions
):
    target_night_color = colors_lib.get_color_mix(
        color_by_category,
        colors[weather.OFF],
        configuration.get_night_category_proportion())

    # For the scenario where we simply dim the LED to account for sunrise/sunset
    # then only use the period between sunset/sunrise start and civil twilight
    if proportions[0] > 0.0:
        color_to_render = colors_lib.get_color_mix(
            color_by_category,
            target_night_color,
            proportions[0])
    elif proportions[1] > 0.0:
        color_to_render = colors_lib.get_color_mix(
            target_night_color,
            color_by_category,
            proportions[1])
    else:
        color_to_render = target_night_color

    return color_to_render
Exemplo n.º 3
0
def get_color_by_pressure(inches_of_mercury: float) -> list:
    """
    Given a barometer reading, return a RGB color to show on the map.

    Args:
        inches_of_mercury (float): The barometer reading from a metar in inHg.

    Returns:
        list: The RGB color to show on the map for the station.
    """

    colors_by_name = colors_lib.get_colors()

    if inches_of_mercury is None:
        return colors_by_name[colors_lib.OFF]

    if inches_of_mercury < LOW_PRESSURE:
        return colors_by_name[colors_lib.RED]

    if inches_of_mercury > HIGH_PRESSURE:
        return colors_by_name[colors_lib.BLUE]

    if inches_of_mercury > STANDARD_PRESSURE:
        return colors_lib.get_color_mix(
            colors_by_name[colors_lib.LIGHT_BLUE],
            colors_by_name[colors_lib.BLUE],
            get_proportion_between_floats(STANDARD_PRESSURE, inches_of_mercury,
                                          HIGH_PRESSURE))

    return colors_lib.get_color_mix(
        colors_by_name[colors_lib.RED], colors_by_name[colors_lib.LIGHT_RED],
        get_proportion_between_floats(LOW_PRESSURE, inches_of_mercury,
                                      STANDARD_PRESSURE))
Exemplo n.º 4
0
def __get_night_color_to_render__(
    color_by_category: list,
    proportions: list
) -> list:
    """
    Calculate the color an airport should be based on the day/night cycle.
    Based on the configuration mixes the color with "Night Yellow" or dims the LEDs.
    A station that is in full daylight will be its normal color.
    A station that is in full darkness with be Night Yellow or dimmed to the night level.
    A station that is in sunset or sunrise will be mixed appropriately.

    Arguments:
        color_by_category {list} -- [description]
        proportions {list} -- [description]

    Returns:
        list -- [description]
    """

    color_to_render = weather.INOP

    if proportions[0] <= 0.0 and proportions[1] <= 0.0:
        if configuration.get_night_populated_yellow():
            color_to_render = colors[weather.DARK_YELLOW]
        else:
            color_to_render = __get_rgb_night_color_to_render__(
                color_by_category,
                proportions)
    # Do not allow color mixing for standard LEDs
    # Instead if we are going to render NIGHT then
    # have the NIGHT color represent that the station
    # is in a twilight period.
    elif configuration.get_mode() == configuration.STANDARD:
        if proportions[0] > 0.0 or proportions[1] < 1.0:
            color_to_render = color_by_rules[weather.NIGHT]
        elif proportions[0] <= 0.0 and proportions[1] <= 0.0:
            color_to_render = colors[weather.DARK_YELLOW]
    elif not configuration.get_night_populated_yellow():
        color_to_render = __get_rgb_night_color_to_render__(
            color_by_category,
            proportions)
    elif proportions[0] > 0.0:
        color_to_render = colors_lib.get_color_mix(
            colors[weather.DARK_YELLOW],
            color_by_rules[weather.NIGHT],
            proportions[0])
    elif proportions[1] > 0.0:
        color_to_render = colors_lib.get_color_mix(
            color_by_rules[weather.NIGHT],
            color_by_category,
            proportions[1])

    return color_to_render
Exemplo n.º 5
0
def get_color_by_temperature_celsius(temperature_celsius: float) -> list:
    """
    Given a temperature (in Celsius), return the color
    that should represent that temp on the map.

    These colors were decided based on weather temperature maps
    and thermometer markings.

    Args:
        temperature_celsius (float): A temperature in metric.

    Returns:
        list: The RGB color to show on the map.
    """
    colors_by_name = colors_lib.get_colors()

    if temperature_celsius is None:
        return colors_by_name[colors_lib.OFF]

    temperature_fahrenheit = celsius_to_fahrenheit(temperature_celsius)

    if temperature_fahrenheit < 0:
        return colors_by_name[colors_lib.PURPLE]

    if temperature_fahrenheit < 20:
        return colors_lib.get_color_mix(
            colors_by_name[colors_lib.PURPLE], colors_by_name[colors_lib.BLUE],
            get_proportion_between_floats(0, temperature_fahrenheit, 20))

    if temperature_fahrenheit < 40:
        return colors_lib.get_color_mix(
            colors_by_name[colors_lib.BLUE], colors_by_name[colors_lib.GREEN],
            get_proportion_between_floats(20, temperature_fahrenheit, 40))

    if temperature_fahrenheit < 60:
        return colors_lib.get_color_mix(
            colors_by_name[colors_lib.GREEN],
            colors_by_name[colors_lib.YELLOW],
            get_proportion_between_floats(40, temperature_fahrenheit, 60))

    if temperature_fahrenheit < 80:
        return colors_lib.get_color_mix(
            colors_by_name[colors_lib.YELLOW],
            colors_by_name[colors_lib.ORANGE],
            get_proportion_between_floats(60, temperature_fahrenheit, 80))

    if temperature_fahrenheit < 100:
        return colors_lib.get_color_mix(
            colors_by_name[colors_lib.ORANGE], colors_by_name[colors_lib.RED],
            get_proportion_between_floats(80, temperature_fahrenheit, 100))

    return colors_by_name[colors_lib.RED]
Exemplo n.º 6
0
    def __get_card_color__(self, time_since_last_report):
        """
        Gets the color the card should be based on how long it has been
        since the traffic has had a report.

        Arguments:
            time_since_last_report {float} -- The number of seconds since the last traffic report.

        Returns:
            float[] -- The RGB tuple/array of the color the target card should be.
        """

        try:
            card_color = YELLOW

            if time_since_last_report > self.start_fade_threshold:
                max_distance = (
                    configuration.CONFIGURATION.max_minutes_before_removal * 60.0) - self.start_fade_threshold
                proportion = (time_since_last_report -
                              self.start_fade_threshold) / max_distance

                card_color = colors.get_color_mix(YELLOW, BLACK, proportion)

            return card_color
        except:
            return YELLOW
Exemplo n.º 7
0
def get_color_by_precipitation(precipitation: str,
                               pulse_interval: float = 2.0
                               ) -> Tuple[list, bool]:
    """
    Given a precipitation category, return a color
    to show on the map.

    Args:
        precipitation (str): The precipitation category.

    Returns:
        (list, bool): A tuple of the RGB color AND if the station should be blinking
    """

    colors_by_name = colors_lib.get_colors()

    no_precip = colors_by_name[colors_lib.GRAY]
    snow_precip = colors_by_name[colors_lib.WHITE]

    if precipitation is None:
        return (no_precip, False)

    if precipitation is weather.DRIZZLE:
        return (colors_by_name[colors_lib.LIGHT_BLUE], False)

    if weather.RAIN in precipitation:
        return (colors_by_name[colors_lib.BLUE],
                precipitation is weather.HEAVY_RAIN)

    if precipitation is weather.SNOW:
        # We want to make snow pulse
        # So lets interpolate the color
        # between "nothing" and snow
        # such that we use the seconds
        if configuration.get_snow_twinkle():
            proportion = get_twinkle_proportion()
        elif configuration.get_snow_pulse():
            proportion = get_pulse_interval_proportion(datetime.utcnow(),
                                                       pulse_interval)
        else:
            proportion = 1.0

        color = colors_lib.get_color_mix(no_precip, snow_precip, proportion)

        return (color, False)

    if precipitation is weather.ICE:
        return (colors_by_name[colors_lib.LIGHT_GRAY], True)

    if precipitation is weather.UNKNOWN:
        return (colors_by_name[colors_lib.PURPLE], False)

    return (colors_by_name[colors_lib.GRAY], False)
Exemplo n.º 8
0
def get_cpu_temp_text_color(temperature):
    color = GREEN

    if temperature > REDLINE_TEMP:
        color = RED
    elif temperature > NORMAL_TEMP:
        delta = float(temperature - NORMAL_TEMP)
        temp_range = float(REDLINE_TEMP - NORMAL_TEMP)
        delta = colors.clamp(0.0, delta, temp_range)
        proportion = delta / temp_range
        color = colors.get_color_mix(GREEN, RED, proportion)

    return color