import math


def calculate_avg_ext_temperature(current_temperature, hist_temp_array):
    """
    Calculates the average external temperature removing the oldest
    measure from list (if full 1440 measurements are available) and adds current one on top of the list
    :param current_temperature: the current measured external temperature
    :param hist_temp_array: the list with the previous external temperatures to compute avg
    :return: The average temperature
    """
    if len(hist_temp_array) >= 1440:
        del hist_temp_array[0]
    hist_temp_array.append(current_temperature)
    return math.fsum(hist_temp_array) / len(hist_temp_array)