def get_heating_period(heat_level, day_period, current_temp, base_level, circuit_data):
    """
    Calculates the length in seconds to heat the specific circuit
    :param heat_level: The heat level (0-1) from the external temperature
    :param day_period: The heating period - 1 (night) or 2 (day)
    :param current_temp: The current circuit temperature
    :param base_level: The base temperature for circuit (to be reached for heat_level=0)
    :param circuit_data: The structure with circuit definition, containing maxTemp, the heating characteristics
           of the circuit - table of dictionary elements each with 'tempMax' and 'heatFactor' defining the heating
           function in the specific segment
    :return: Heating length in seconds to reach desired temperature, desired temperature
    """
    max_temp = circuit_data['maxTemp']
    try:
        base_level = circuit_data['tempBaseLevel']
    except KeyError:
        pass
    adjust_value = 1
    try:
        if day_period == 1:
            adjust_value += circuit_data['nightAdjust']
        elif day_period == 2:
            adjust_value += circuit_data['dayAdjust']
    except KeyError:
        pass
    heat_level *= adjust_value
    if heat_level > 1:
        heat_level = 1
    elif heat_level < 0:
        heat_level = 0
    desired_temp = base_level + (max_temp - base_level) * heat_level
    diff = desired_temp - current_temp
    if diff <= 0:
        return 0, 0.0
    heat_period = 0
    heat_characteristics = circuit_data['heatCharacteristics']
    n = len(heat_characteristics) - 2
    while n >= 0:
        elem_a = heat_characteristics[n]
        elem_b = heat_characteristics[n + 1]
        temp_max_a = elem_a['tempMax']
        temp_max_b = elem_b['tempMax']
        heat_factor = elem_b['heatFactor']
        if desired_temp >= temp_max_a and current_temp < temp_max_b:
            tb = min(desired_temp, temp_max_b)
            ta = max(current_temp, temp_max_a)
            heat_period += (tb - ta) / heat_factor
        n -= 1
    temp_max_b = heat_characteristics[0]['tempMax']
    heat_factor = heat_characteristics[0]['heatFactor']
    if current_temp < heat_characteristics[0]['tempMax']:
        heat_period += (temp_max_b - current_temp) / heat_factor
    return heat_period, desired_temp