(self)
return self.response
Add feature definitions for the model
Add feature definitions for the model
Add feature definitions for the model
def set_features(self):
        """
        Add feature definitions for the model
        """
        
        # Interpret the request data based on the expected row and column structure
        row_template = ['strData', 'strData', 'strData', 'strData', 'strData', 'strData']
        col_headers = ['model_name', 'name', 'variable_type', 'data_type', 'feature_strategy', 'strategy_args']
        
        # Create a Pandas Data Frame for the request data
        self.request_df = utils.request_df(self.request, row_template, col_headers)
       
        # Initialize the persistent model
        self.model = PersistentModel()
        
        # Get the model name from the request dataframe
        self.model.name = self.request_df.loc[0, 'model_name']
        
        # Get the model from cache or disk
        self._get_model()
        
        # Debug information is printed to the terminal and logs if the paramater debug = true
        if self.model.debug:
            self._print_log(3)
        
        # Add the feature definitions to the model
        self.model.features_df = self.request_df
        self.model.features_df.set_index("name", drop=False, inplace=True)
        # Store a copy of the features_df that will remain untouched in later calls
        self.model.original_features_df = self.model.features_df.copy()

        # Ensure there is at most one feature with variable_type identifier
        if len(self.model.features_df.loc[self.model.features_df["variable_type"] == "identifier"]) > 1:
            err = "Invalid feature definitions. Detected more than one feature with variable_type set to identifier. You can only pass one unique identifier."
            raise Exception(err)

        # Persist the model to disk
        self.model = self.model.save(self.model.name, self.path, overwrite=self.model.overwrite, compress=self.model.compress)
        
        # Update the cache to keep this model in memory
        self._update_cache()
        
        # Prepare the output
        message = [[self.model.name, 'Feature definitions successfully saved to model',\
                    time.strftime('%X %x %Z', time.localtime(self.model.state_timestamp))]]
        self.response = pd.DataFrame(message, columns=['model_name', 'result', 'time_stamp'])
        
        # Send the reponse table description to Qlik
        self._send_table_description("setup")
        
        # Debug information is printed to the terminal and logs if the paramater debug = true
        if self.model.debug:
            self._print_log(4)
        
        # Finally send the response
        return self.response
def set_features ( self ) : # Interpret the request data based on the expected row and column structure row_template = [ 'strData' , 'strData' , 'strData' , 'strData' , 'strData' , 'strData' ] col_headers = [ 'model_name' , 'name' , 'variable_type' , 'data_type' , 'feature_strategy' , 'strategy_args' ] # Create a Pandas Data Frame for the request data self . request_df = utils . request_df ( self . request , row_template , col_headers ) # Initialize the persistent model self . model = PersistentModel ( ) # Get the model name from the request dataframe self . model . name = self . request_df . loc [ 0 , 'model_name' ] # Get the model from cache or disk self . _get_model ( ) # Debug information is printed to the terminal and logs if the paramater debug = true if self . model . debug : self . _print_log ( 3 ) # Add the feature definitions to the model self . model . features_df = self . request_df self . model . features_df . set_index ( "name" , drop = False , inplace = True ) # Store a copy of the features_df that will remain untouched in later calls self . model . original_features_df = self . model . features_df . copy ( ) # Ensure there is at most one feature with variable_type identifier if len ( self . model . features_df . loc [ self . model . features_df [ "variable_type" ] == "identifier" ] ) > 1 : err = "Invalid feature definitions. Detected more than one feature with variable_type set to identifier. You can only pass one unique identifier." raise Exception ( err ) # Persist the model to disk self . model = self . model . save ( self . model . name , self . path , overwrite = self . model . overwrite , compress = self . model . compress ) # Update the cache to keep this model in memory self . _update_cache ( ) # Prepare the output message = [ [ self . model . name , 'Feature definitions successfully saved to model' , time . strftime ( '%X %x %Z' , time . localtime ( self . model . state_timestamp ) ) ] ] self . response = pd . DataFrame ( message , columns = [ 'model_name' , 'result' , 'time_stamp' ] ) # Send the reponse table description to Qlik self . _send_table_description ( "setup" ) # Debug information is printed to the terminal and logs if the paramater debug = true if self . model . debug : self . _print_log ( 4 ) # Finally send the response return self . response