agregator.py
def _detect_if_error_and_recompute_if_necessary(self, time):
        """
        Detect if an error is detected. If the error is too big, we recompute the decision operation

        :param time: The time of operation
        """

        #
        # Compute the error
        # difference between optimal temperature computed and real temperature
        #
        self.error = \
            self.temperature_optimal[time - self.delta_time] - \
            units.value(units.convert(units(self.thermal_process.temperature, units.kelvin), units.celsius))
        self.error = self.error if abs(self.error) >= 1e-10 else 0.0
        self.absolute_error = abs(self.error)
        self.total_error += self.error
        self.total_absolute_error += abs(self.error)
        self.count_error += 1

        #
        # Historic
        #
        self._outside_process.set_time(time * units.second)
        self._historic_for_correction.append((
            time,
            self.old_temperature,
            self.temperature_optimal[time - self.delta_time],
            units.value(units.convert(units(self.thermal_process.temperature, units.kelvin), units.celsius)),
            self._outside_temperature_forecast[time],
            units.value(units.convert(self._outside_process.temperature, units.celsius)),
            self._power_on[time - self.delta_time]))
        #
        # Determine if we need to consider the error
        #
        if self.absolute_error >= ForecastController.MAX_REAL_TIME_ERROR \
                and self.absolute_error > 2 * abs(self.total_error / self.count_error):

            debug("| + current error too big {}".format(self.error))
            if self.__is_delta_temperature_error():

                #
                # Recompute according to the difference of temperature regarding to the forecast
                #
                self.__recompute_with_temperature_error(time)
                self._historic_for_correction = []

            else:
                #
                # Error due to a human behavior, must recompute
                #
                self._power_on, self.temperature_optimal = self.__optimize(
                    cost=self._cost,
                    first_decision=self._power_on[int(time)],
                    correction=self._current_correction)

                self.countOptimization += 1
                self._historic_for_correction = []

            self.total_absolute_error = 0.0
            self.total_error = 0.0
            self.count_error = 0

        elif abs(self.total_error) / self.count_error >= ForecastController.MAX_TOTAL_ERROR \
                and len(self._historic_for_correction) >= ForecastController.MAX_DAY_HISTORIC:

            debug("| + total error too big {}".format(self.total_error))

            if self.__is_delta_temperature_error():

                #
                # Recompute according to the difference of temperature
                #
                self.__recompute_with_temperature_error(time)
                self._historic_for_correction = []

            else:
                #
                # Compute correction due to adjacency room
                # Use only in the case of placing an adjacency room with a coupling to the main room
                #
                self._current_correction, fountBetterCorrection = self.__check_correction()
                if fountBetterCorrection:
                    #
                    # Re-optimize with corrections
                    #
                    self._historic_for_correction = []
                    self._power_on, self.temperature_optimal = self.__optimize(
                        cost=self._cost,
                        correction=self._current_correction)
                    self.countOptimization += 1

            self.total_absolute_error = 0.0
            self.total_error = 0.0
            self.count_error = 0

            #
            # Recompute in real time ?
            ###############################################################################################################

        Detect if an error is detected. If the error is too big, we recompute the decision operation

        :param time: The time of operation
        
Detect if an error is detected. If the error is too big, we recompute the decision operation
Detect if an error is detected . If the error is too big we recompute the decision operation
def _detect_if_error_and_recompute_if_necessary(self, time):
         Compute the error
         difference between optimal temperature computed and real temperature
        self.error = \
            self.temperature_optimal[time - self.delta_time] - \
            units.value(units.convert(units(self.thermal_process.temperature, units.kelvin), units.celsius))
        self.error = self.error if abs(self.error) >= 1e-10 else 0.0
        self.absolute_error = abs(self.error)
        self.total_error += self.error
        self.total_absolute_error += abs(self.error)
        self.count_error += 1
         Historic
        self._outside_process.set_time(time * units.second)
        self._historic_for_correction.append((
            time,
            self.old_temperature,
            self.temperature_optimal[time - self.delta_time],
            units.value(units.convert(units(self.thermal_process.temperature, units.kelvin), units.celsius)),
            self._outside_temperature_forecast[time],
            units.value(units.convert(self._outside_process.temperature, units.celsius)),
            self._power_on[time - self.delta_time]))
         Determine if we need to consider the error
        if self.absolute_error >= ForecastController.MAX_REAL_TIME_ERROR \
                and self.absolute_error > 2 * abs(self.total_error / self.count_error):
            debug("| + current error too big {}".format(self.error))
            if self.__is_delta_temperature_error():
                 Recompute according to the difference of temperature regarding to the forecast
                self.__recompute_with_temperature_error(time)
                self._historic_for_correction = []
            else:
                 Error due to a human behavior, must recompute
                self._power_on, self.temperature_optimal = self.__optimize(
                    cost=self._cost,
                    first_decision=self._power_on[int(time)],
                    correction=self._current_correction)
                self.countOptimization += 1
                self._historic_for_correction = []
            self.total_absolute_error = 0.0
            self.total_error = 0.0
            self.count_error = 0
        elif abs(self.total_error) / self.count_error >= ForecastController.MAX_TOTAL_ERROR \
                and len(self._historic_for_correction) >= ForecastController.MAX_DAY_HISTORIC:
            debug("| + total error too big {}".format(self.total_error))
            if self.__is_delta_temperature_error():
                 Recompute according to the difference of temperature
                self.__recompute_with_temperature_error(time)
                self._historic_for_correction = []
            else:
                 Compute correction due to adjacency room
                 Use only in the case of placing an adjacency room with a coupling to the main room
                self._current_correction, fountBetterCorrection = self.__check_correction()
                if fountBetterCorrection:
                     Re-optimize with corrections
                    self._historic_for_correction = []
                    self._power_on, self.temperature_optimal = self.__optimize(
                        cost=self._cost,
                        correction=self._current_correction)
                    self.countOptimization += 1
            self.total_absolute_error = 0.0
            self.total_error = 0.0
            self.count_error = 0
             Recompute in real time ?
def _detect_if_error_and_recompute_if_necessary ( self , time ) : self . error = self . temperature_optimal [ time - self . delta_time ] - units . value ( units . convert ( units ( self . thermal_process . temperature , units . kelvin ) , units . celsius ) ) self . error = self . error if abs ( self . error ) >= 1e-10 else 0.0 self . absolute_error = abs ( self . error ) self . total_error += self . error self . total_absolute_error += abs ( self . error ) self . count_error += 1 self . _outside_process . set_time ( time * units . second ) self . _historic_for_correction . append ( ( time , self . old_temperature , self . temperature_optimal [ time - self . delta_time ] , units . value ( units . convert ( units ( self . thermal_process . temperature , units . kelvin ) , units . celsius ) ) , self . _outside_temperature_forecast [ time ] , units . value ( units . convert ( self . _outside_process . temperature , units . celsius ) ) , self . _power_on [ time - self . delta_time ] ) ) if self . absolute_error >= ForecastController . MAX_REAL_TIME_ERROR and self . absolute_error > 2 * abs ( self . total_error / self . count_error ) : debug ( "| + current error too big {}" . format ( self . error ) ) if self . __is_delta_temperature_error ( ) : self . __recompute_with_temperature_error ( time ) self . _historic_for_correction = [ ] else : self . _power_on , self . temperature_optimal = self . __optimize ( cost = self . _cost , first_decision = self . _power_on [ int ( time ) ] , correction = self . _current_correction ) self . countOptimization += 1 self . _historic_for_correction = [ ] self . total_absolute_error = 0.0 self . total_error = 0.0 self . count_error = 0 elif abs ( self . total_error ) / self . count_error >= ForecastController . MAX_TOTAL_ERROR and len ( self . _historic_for_correction ) >= ForecastController . MAX_DAY_HISTORIC : debug ( "| + total error too big {}" . format ( self . total_error ) ) if self . __is_delta_temperature_error ( ) : self . __recompute_with_temperature_error ( time ) self . _historic_for_correction = [ ] else : self . _current_correction , fountBetterCorrection = self . __check_correction ( ) if fountBetterCorrection : self . _historic_for_correction = [ ] self . _power_on , self . temperature_optimal = self . __optimize ( cost = self . _cost , correction = self . _current_correction ) self . countOptimization += 1 self . total_absolute_error = 0.0 self . total_error = 0.0 self . count_error = 0
Detect if an error is detected.
Detect if an error is detected .
"""
        Detect if an error is detected. If the error is too big, we recompute the decision operation

        :param time: The time of operation
        """ # # Compute the error # difference between optimal temperature computed and real temperature # # # Historic # # # Determine if we need to consider the error # # # Recompute according to the difference of temperature regarding to the forecast # # # Error due to a human behavior, must recompute # # # Recompute according to the difference of temperature # # # Compute correction due to adjacency room # Use only in the case of placing an adjacency room with a coupling to the main room # # # Re-optimize with corrections # # # Recompute in real time ? ###############################################################################################################
self
time
The time of operation
The time of operation