(self, step)
Output useful information to stdout and the log file if debugging is required.
        step: Print the corresponding step in the log
Output useful information to stdout and the log file if debugging is required.
        step: Print the corresponding step in the log
Output useful information to stdout and the log file if debugging is required . step : Print the corresponding step in the log
def _print_log(self, step):
        """
        Output useful information to stdout and the log file if debugging is required.
        step: Print the corresponding step in the log
        """
        
        # Set mode to append to log file
        mode = 'a'

        if step == 1:
            # Increment log counter for the class. Each instance of the class generates a new log.
            self.__class__.log_no += 1
             
            # Create a log file for the instance
            # Logs will be stored in ..\logs\Prophet Log <n>.txt
            self.logfile = os.path.join(os.getcwd(), 'logs', 'Prophet Log {}.txt'.format(self.log_no))
            
            # Output log header
            output = "ProphetForQlik Log: {0} \n\n".format(time.ctime(time.time()))
            # Set mode to write new log file
            mode = 'w'
        
        elif step == 2:
            # Output the request and input data frames
            output = "Prophet parameters: {0}\n\n".format(self.kwargs)
            output += "Instance creation parameters: {0}\n\n".format(self.prophet_kwargs)
            output += "Make future data frame parameters: {0}\n\n".format(self.make_kwargs)
            output += "Add seasonality parameters: {0}\n\n".format(self.add_seasonality_kwargs)
            output += "Fit parameters: {0}\n\n".format(self.fit_kwargs)
            if self.has_regressors and len(self.regressor_kwargs):
                output += "Additional regressor parameters: {0}\n\n".format(self.regressor_kwargs)
            output += "REQUEST DATA FRAME: {0} rows x cols\n\n".format(self.request_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.request_df.head(5).to_string(), self.request_df.tail(5).to_string())
            if len(self.NaT_df) > 0:
                output += "REQUEST NULL VALUES DATA FRAME: {0} rows x cols\n\n".format(self.NaT_df.shape)
                output += "{0} \n\n".format(self.NaT_df.to_string())
            output += "INPUT DATA FRAME: {0} rows x cols\n\n".format(self.input_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.input_df.head(5).to_string(), self.input_df.tail(5).to_string())
            if self.has_holidays:
                output += "HOLIDAYS DATA FRAME: {0} rows x cols\n\n".format(self.holidays_df.shape)
                output += "{0} \n\n".format(self.holidays_df.to_string())
        
        elif step == 3:
            # Output in case the input contains less than 2 non-Null rows
            output = "\nForecast cannot be generated as the request contains less than two non-Null rows\n\n"
        
        elif step == 4:
            # Output the future data frame 
            output = "\nFUTURE DATA FRAME: {0} rows x cols\n\n".format(self.future_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.future_df.head(5).to_string(), self.future_df.tail(5).to_string())

        elif step == 5:         
            # Output the forecast data frame and returned series 
            output = "\nFORECAST DATA FRAME: {0} rows x cols\n\n".format(self.forecast.shape)
            output += "RESULT COLUMNS:\n\n"
            for col in self.forecast:
                output += "{}\n".format(col)

            output += "\nSAMPLE RESULTS:\n{0} \n\n".format(self.forecast.tail(5).to_string())

            result = self.response if self.load_script else self.forecast
            cols = result.columns if self.result_type == 'all' else ['ds', self.result_type]
            output += "FORECAST RETURNED:\n{0}\n...\n{1}\n\n".format(result.loc[:, cols].head(5).to_string(),\
                result.loc[:, cols].tail(5).to_string())
        
        elif step == 6:
            # Print the table description if the call was made from the load script
            output = "\nTABLE DESCRIPTION SENT TO QLIK:\n\n{0} \n\n".format(self.table)

        elif step == 7:
            # Inform of fall back when additional regressors are incorrect
            output = "\nAdditional regressors have not been passed correctly. Falling back to a basic model.\n\n"
        
        sys.stdout.write(output)
        with open(self.logfile, mode, encoding='utf-8') as f:
            f.write(output)
def _print_log ( self , step ) : # Set mode to append to log file mode = 'a' if step == 1 : # Increment log counter for the class. Each instance of the class generates a new log. self . __class__ . log_no += 1 # Create a log file for the instance # Logs will be stored in ..\logs\Prophet Log <n>.txt self . logfile = os . path . join ( os . getcwd ( ) , 'logs' , 'Prophet Log {}.txt' . format ( self . log_no ) ) # Output log header output = "ProphetForQlik Log: {0} \n\n" . format ( time . ctime ( time . time ( ) ) ) # Set mode to write new log file mode = 'w' elif step == 2 : # Output the request and input data frames output = "Prophet parameters: {0}\n\n" . format ( self . kwargs ) output += "Instance creation parameters: {0}\n\n" . format ( self . prophet_kwargs ) output += "Make future data frame parameters: {0}\n\n" . format ( self . make_kwargs ) output += "Add seasonality parameters: {0}\n\n" . format ( self . add_seasonality_kwargs ) output += "Fit parameters: {0}\n\n" . format ( self . fit_kwargs ) if self . has_regressors and len ( self . regressor_kwargs ) : output += "Additional regressor parameters: {0}\n\n" . format ( self . regressor_kwargs ) output += "REQUEST DATA FRAME: {0} rows x cols\n\n" . format ( self . request_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . request_df . head ( 5 ) . to_string ( ) , self . request_df . tail ( 5 ) . to_string ( ) ) if len ( self . NaT_df ) > 0 : output += "REQUEST NULL VALUES DATA FRAME: {0} rows x cols\n\n" . format ( self . NaT_df . shape ) output += "{0} \n\n" . format ( self . NaT_df . to_string ( ) ) output += "INPUT DATA FRAME: {0} rows x cols\n\n" . format ( self . input_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . input_df . head ( 5 ) . to_string ( ) , self . input_df . tail ( 5 ) . to_string ( ) ) if self . has_holidays : output += "HOLIDAYS DATA FRAME: {0} rows x cols\n\n" . format ( self . holidays_df . shape ) output += "{0} \n\n" . format ( self . holidays_df . to_string ( ) ) elif step == 3 : # Output in case the input contains less than 2 non-Null rows output = "\nForecast cannot be generated as the request contains less than two non-Null rows\n\n" elif step == 4 : # Output the future data frame  output = "\nFUTURE DATA FRAME: {0} rows x cols\n\n" . format ( self . future_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . future_df . head ( 5 ) . to_string ( ) , self . future_df . tail ( 5 ) . to_string ( ) ) elif step == 5 : # Output the forecast data frame and returned series  output = "\nFORECAST DATA FRAME: {0} rows x cols\n\n" . format ( self . forecast . shape ) output += "RESULT COLUMNS:\n\n" for col in self . forecast : output += "{}\n" . format ( col ) output += "\nSAMPLE RESULTS:\n{0} \n\n" . format ( self . forecast . tail ( 5 ) . to_string ( ) ) result = self . response if self . load_script else self . forecast cols = result . columns if self . result_type == 'all' else [ 'ds' , self . result_type ] output += "FORECAST RETURNED:\n{0}\n...\n{1}\n\n" . format ( result . loc [ : , cols ] . head ( 5 ) . to_string ( ) , result . loc [ : , cols ] . tail ( 5 ) . to_string ( ) ) elif step == 6 : # Print the table description if the call was made from the load script output = "\nTABLE DESCRIPTION SENT TO QLIK:\n\n{0} \n\n" . format ( self . table ) elif step == 7 : # Inform of fall back when additional regressors are incorrect output = "\nAdditional regressors have not been passed correctly. Falling back to a basic model.\n\n" sys . stdout . write ( output ) with open ( self . logfile , mode , encoding = 'utf-8' ) as f : f . write ( output )