def __init__(self):
        '''

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
    def __init__(self, svm_data, session_type):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        # class variables
        self.svm_data = svm_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
    def __init__(self, premodel_data, session_type):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        # class variables
        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
예제 #4
0
    def __init__(self, premodel_data):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.premodel_data = premodel_data
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
        self.classification = current_app.config.get('MODEL_TYPE')[0]
        self.regression = current_app.config.get('MODEL_TYPE')[1]
예제 #5
0
    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
예제 #6
0
    def __init__(self, svm_data, session_type):
        """@__init__

        This constructor is responsible for defining class variables.

        Note: during the SVM entity instance, 'self.svm_data' is a dictionary
              with the following elements:

                  {'uid': xx, 'id_entity': xx, 'title': yyy}

              where 'xx' denotes an integer value, 'yyy' a unicode string, and
              'zz' representing a float value.

        """

        self.svm_data = svm_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
예제 #7
0
    def __init__(self, premodel_data, session_type):
        '''@__init__

        This constructor is responsible for defining class variables.

        @self.premodel_data, a dictionary with the following elements:

            {'uid': xx, 'id_entity': xx, 'title': yyy}

        Note: 'xx' denotes an integer value, 'yyy' a unicode string, and 'zz'
              representing a float value.

        '''

        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
예제 #8
0
    def __init__(self, svm_data):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        self.svm_data = svm_data
        self.list_error = []
        self.sql = SQL()
예제 #9
0
    def __init__(self, premodel_data):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.premodel_data = premodel_data
        self.list_error = []
        self.sql = SQL()
    def __init__(self):
        """

        This constructor is responsible for defining class variables.

        """

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get("DB_ML")
예제 #11
0
    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
    def __init__(self, svm_data, session_type):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        # class variables
        self.svm_data = svm_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
class Retrieve_Entity(object):

    ## constructor:
    def __init__(self):
        # class variables
        self.list_error = []
        self.sql = SQL()

    ## get_title: retrieve an SVM entity tile from corresponding 'EAV data model'
    #             database table(s), using a fixed 'id_entity'.
    #
    #  @id_entity, this supplied argument corresponds to the 'id_entity' column from the
    #      'tbl_dataset_value' database table.
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s'
    #      is used for argument substitution.
    def get_title(self, id_entity):
        # select dataset
        self.sql.sql_connect("db_machine_learning")
        sql_statement = "SELECT title FROM tbl_dataset_entity where id_entity=%s"
        args = id_entity
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"error": response_error, "result": None}
        else:
            return {"error": None, "result": response["result"]}
class Retrieve_Session(object):

    ## constructor:
    def __init__(self):
        self.list_error = []
        self.sql        = SQL()

    ## get_all_sessions: get all sessions from 'tbl_dataset_entity'
    def get_all_sessions(self):
        # local variables
        list_session = []

        # sql query
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'SELECT id_entity, title FROM tbl_dataset_entity'
        response      = self.sql.sql_command(sql_statement, 'select')

        # rebuild session list, get error(s) if any
        if response['result']:
            for item in response['result']:
                list_session.append({'id': item[0], 'title': item[1]})
            response_error = self.sql.get_errors()
        else:
            response_error = 'no previous session found in database'

        # disconnect from database
        self.sql.sql_disconnect()

        # return result
        if response_error: return {'result': None, 'error': response_error}
        else: return {'result': list_session, 'error': None}
예제 #15
0
    def __init__(self, premodel_data):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.premodel_data = premodel_data
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
        self.classification = current_app.config.get('MODEL_TYPE')[0]
        self.regression = current_app.config.get('MODEL_TYPE')[1]
예제 #16
0
    def __init__(self, premodel_data, session_type):
        '''

        This constructor is responsible for defining class variables.

        '''

        # class variables
        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
class Save_Entity(object):

    ## constructor: stores an SVM entity (python dict), database configurations
    #               into their own corresponding class variable.
    #
    #  Note: during the SVM entity instance, 'self.svm_data' is a dictionary with the
    #        following elements:
    #
    #            {'uid': xx, 'id_entity': xx, 'title': yyy}
    #
    #        where 'xx' denotes an integer value, 'yyy' a unicode string, and 'zz'
    #        representing a float value.
    def __init__(self, svm_data, session_type):
        # class variables
        self.svm_data = svm_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()

    ## save: store, or update SVM entity into corresponding 'EAV data model'
    #        database table.
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s'
    #      is used for argument substitution.
    #
    #  Note: 'UTC_TIMESTAMP' returns the universal UTC datetime
    def save(self):
        # insert / update dataset entity value
        self.sql.sql_connect("db_machine_learning")

        if self.session_type == "data_append":
            sql_statement = (
                "UPDATE tbl_dataset_entity SET uid_modified=%s, datetime_modified=UTC_TIMESTAMP() WHERE id_entity=%s"
            )
            args = (self.svm_data["uid"], self.svm_data["id_entity"])
            response = self.sql.sql_command(sql_statement, "update", args)

        elif self.session_type == "data_new":
            sql_statement = (
                "INSERT INTO tbl_dataset_entity (title, uid_created, datetime_created) VALUES(%s, %s, UTC_TIMESTAMP())"
            )
            args = (self.svm_data["title"], self.svm_data["uid"])
            response = self.sql.sql_command(sql_statement, "insert", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"status": False, "error": response_error}
        else:
            return {"status": True, "error": None, "id": response["id"]}
예제 #18
0
class Retrieve_Session(object):
    '''
    @Retrieve_Session

    This class provides an interface to retrieve the 'session_name', and
    'id_entity' from the 'tbl_dataset_entity' sql database table.

    Note: this class is invoked within 'views.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_all_sessions(self):
        '''@get_all_sessions

        This method is responsible for retrieving all sessions from the
        'tbl_dataset_entity' sql database table.

        '''

        # local variables
        list_session = []

        # sql query
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT id_entity, title FROM tbl_dataset_entity'
        response = self.sql.sql_command(sql_statement, 'select')

        # rebuild session list, get error(s) if any
        if response['result']:
            for item in response['result']:
                list_session.append({'id': item[0], 'title': item[1]})
            response_error = self.sql.get_errors()
        else:
            response_error = 'no previous session found in database'

        # disconnect from database
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'result': None, 'error': response_error}
        else:
            return {'result': list_session, 'error': None}
class Retrieve_Session(object):
    '''
    @Retrieve_Session

    This class provides an interface to retrieve the 'session_name', and
    'id_entity' from the 'tbl_dataset_entity' sql database table.

    Note: this class is invoked within 'views.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''
    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_all_sessions(self):
        '''@get_all_sessions

        This method is responsible for retrieving all sessions from the
        'tbl_dataset_entity' sql database table.

        '''

        # local variables
        list_session = []

        # sql query
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT id_entity, title FROM tbl_dataset_entity'
        response = self.sql.sql_command(sql_statement, 'select')

        # rebuild session list, get error(s) if any
        if response['result']:
            for item in response['result']:
                list_session.append({'id': item[0], 'title': item[1]})
            response_error = self.sql.get_errors()
        else:
            response_error = 'no previous session found in database'

        # disconnect from database
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'result': None, 'error': response_error}
        else:
            return {'result': list_session, 'error': None}
예제 #20
0
class Retrieve_Entity(object):
    '''
    @Retrieve_Entity

    This class provides an interface to get an SVM entity title, from the
    'tbl_dataset_entity' sql database table.

    Note: this class is invoked within 'model_generate.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_title(self, id_entity):
        '''@get_title

        This method is responsible for retrieving an SVM entity title, from the
        SQL database, using a fixed 'id_entity'.

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT title FROM tbl_dataset_entity'\
            ' where id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result']}
class Retrieve_Entity(object):
    '''
    @Retrieve_Entity

    This class provides an interface to get an SVM entity title, from the
    'tbl_dataset_entity' sql database table.

    Note: this class is invoked within 'model_generate.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''
    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_title(self, id_entity):
        '''@get_title

        This method is responsible for retrieving an SVM entity title, from the
        SQL database, using a fixed 'id_entity'.

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT title '\
            'FROM tbl_dataset_entity '\
            'WHERE id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result']}
class Retrieve_Model_Type(object):
    '''
    @Retrieve_Model_Type

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_model_type(self, id_entity):
        '''@get_title

        This method is responsible for retrieving the model type, from the
        SQL database, using a fixed 'model_id'.

        @id_entity, this supplied argument corresponding to the 'id_entity'
            column from the 'tbl_dataset_entity' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT mtype.model'\
            ' FROM tbl_dataset_entity mid'\
            ' INNER JOIN tbl_model_type mtype'\
            ' ON mid.model_type = mtype.id_model'\
            ' WHERE mid.id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result'][0][0]}
예제 #23
0
class Retrieve_Model_Type(object):
    '''

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self):
        '''

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_model_type(self, id_entity):
        '''

        This method is responsible for retrieving the model type, from the
        SQL database, using a fixed 'model_id'.

        @id_entity, this supplied argument corresponding to the 'id_entity'
            column from the 'tbl_dataset_entity' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT mtype.model'\
            ' FROM tbl_dataset_entity mid'\
            ' INNER JOIN tbl_model_type mtype'\
            ' ON mid.model_type = mtype.id_model'\
            ' WHERE mid.id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result'][0][0]}
예제 #24
0
    def __init__(self, premodel_data, session_type):
        '''@__init__

        This constructor is responsible for defining class variables.

        @self.premodel_data, a dictionary with the following elements:

            {'uid': xx, 'id_entity': xx, 'title': yyy}

        Note: 'xx' denotes an integer value, 'yyy' a unicode string, and 'zz'
              representing a float value.

        '''

        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')
예제 #25
0
class Save_Account(object):
    '''@Save_Account

    This class provides an interface to save a username, and their
    corresponding password.

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def save_account(self, username, email, password):
        '''@save_account

        This method stores a user account, along with their corresponding
        password into an 'EAV data model' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        '''

        # insert / update dataset entity value
        self.sql.sql_connect(self.db_ml)

        sql_statement = 'INSERT INTO tbl_user '\
            '(username, email, password, datetime_joined) '\
            'VALUES(%s, %s, %s, UTC_TIMESTAMP())'
        args = (username, email, password)
        response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}
class Save_Observation(object):

    ## constructor: stores an SVM label (python dict), database configurations
    #               into their own corresponding class variable.
    def __init__(self, svm_data, session_type):
        # class variables
        self.svm_data     = svm_data
        self.session_type = session_type
        self.list_error   = []
        self.sql          = SQL()

    ## save_label: store, or update SVM dataset(s) into corresponding 'EAV data model'
    #              database table(s).
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s'
    #      is used for argument substitution.
    #
    #  Note: 'UTC_TIMESTAMP' returns the universal UTC datetime
    def save_label(self):
        # insert / update feature label(s)
        self.sql.sql_connect('db_machine_learning')

        # add labels (append case)
        if self.session_type in ['data_append', 'data_new']:

            # check if observation label exists in database
            sql_statement = 'SELECT * FROM tbl_observation_label WHERE dep_variable_label=%s AND id_entity=%s'
            args          = (self.svm_data['label'], self.svm_data['id_entity'])
            response      = self.sql.sql_command(sql_statement, 'select', args)

            # add labels if not exist
            if not response['result']:
                sql_statement  = 'INSERT INTO tbl_observation_label (id_entity, dep_variable_label) VALUES(%s, %s)'
                args           = (self.svm_data['id_entity'], self.svm_data['label'])
                response_added = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error: return {'status': False, 'error': response_error}
        else: return {'status': True, 'error': None}
class Save_Feature(object):

    ## constructor:
    def __init__(self, svm_data):
        # class variables
        self.svm_data = svm_data
        self.list_error = []
        self.sql = SQL()

    ## save_count: store the number of features that can be expected in a given
    #              observation.
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s'
    #      is used for argument substitution.
    def save_count(self):
        # insert / update dataset value(s)
        self.sql.sql_connect("db_machine_learning")
        sql_statement = "INSERT INTO tbl_feature_count (id_entity, count_features) VALUES(%s, %s)"
        args = (self.svm_data["id_entity"], self.svm_data["count_features"])
        response = self.sql.sql_command(sql_statement, "insert", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"status": False, "error": response_error}
        else:
            return {"status": True, "error": None, "id": response["id"]}

    ## save_feature: store, or update SVM dataset(s) into corresponding 'EAV data model'
    #                database table(s).
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s'
    #      is used for argument substitution.
    #
    #  Note: 'UTC_TIMESTAMP' returns the universal UTC datetime
    def save_feature(self):
        # insert / update dataset value(s)
        self.sql.sql_connect("db_machine_learning")
        sql_statement = "INSERT INTO tbl_feature_value (id_entity, dep_variable_label, indep_variable_label, indep_variable_value) VALUES(%s, %s, %s, %s)"
        dataset = self.svm_data["svm_dataset"]
        args = (
            self.svm_data["id_entity"],
            dataset["dep_variable_label"],
            dataset["indep_variable_label"],
            dataset["indep_variable_value"],
        )
        response = self.sql.sql_command(sql_statement, "insert", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"status": False, "error": response_error}
        else:
            return {"status": True, "error": None, "id": response["id"]}
 def __init__(self, svm_data):
     # class variables
     self.svm_data = svm_data
     self.list_error = []
     self.sql = SQL()
예제 #29
0
class Save_Entity(object):
    '''@Save_Entity

    This class provides an interface to save dataset(s) later used to generate
    corresponding model(s).

    Note: this class is invoked within 'base_data.py', and 'data_append.py'

    Note: this class explicitly inherits the 'new-style' class.
    '''

    def __init__(self, premodel_data, session_type):
        '''@__init__

        This constructor is responsible for defining class variables.

        @self.premodel_data, a dictionary with the following elements:

            {'uid': xx, 'id_entity': xx, 'title': yyy}

        Note: 'xx' denotes an integer value, 'yyy' a unicode string, and 'zz'
              representing a float value.

        '''

        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def save(self):
        '''@save

        This method stores, or updates dataset entities into its corresponding
        'EAV data model' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime

        '''

        # insert / update dataset entity value
        self.sql.sql_connect(self.db_ml)

        if self.session_type == 'data_append':
            sql_statement = 'UPDATE tbl_dataset_entity SET '\
                'uid_modified=%s, datetime_modified=UTC_TIMESTAMP() '\
                'WHERE id_entity=%s'
            args = (self.premodel_data['uid'], self.premodel_data['id_entity'])
            response = self.sql.sql_command(sql_statement, 'update', args)

        elif self.session_type == 'data_new':
            sql_statement = 'INSERT INTO tbl_dataset_entity (title, '\
                'uid_created, datetime_created) VALUES(%s, %s, '\
                'UTC_TIMESTAMP())'
            args = (self.premodel_data['title'], self.premodel_data['uid'])
            response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}
예제 #30
0
class Save_Entity(object):
    """@Save_Entity

    This class provides an interface to save an svm dataset.

    Note: this class is invoked within 'base_data.py', and 'data_append.py'

    Note: this class explicitly inherits the 'new-style' class.
    """

    def __init__(self, svm_data, session_type):
        """@__init__

        This constructor is responsible for defining class variables.

        Note: during the SVM entity instance, 'self.svm_data' is a dictionary
              with the following elements:

                  {'uid': xx, 'id_entity': xx, 'title': yyy}

              where 'xx' denotes an integer value, 'yyy' a unicode string, and
              'zz' representing a float value.

        """

        self.svm_data = svm_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()

    def save(self):
        """@save

        This method stores, or updates SVM entities into its corresponding 'EAV
        data model' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime

        """

        # insert / update dataset entity value
        self.sql.sql_connect('db_machine_learning')

        if self.session_type == 'data_append':
            sql_statement = 'UPDATE tbl_dataset_entity SET '\
                'uid_modified=%s, datetime_modified=UTC_TIMESTAMP() '\
                'WHERE id_entity=%s'
            args = (self.svm_data['uid'], self.svm_data['id_entity'])
            response = self.sql.sql_command(sql_statement, 'update', args)

        elif self.session_type == 'data_new':
            sql_statement = 'INSERT INTO tbl_dataset_entity (title, '\
                'uid_created, datetime_created) VALUES(%s, %s, '\
                'UTC_TIMESTAMP())'
            args = (self.svm_data['title'], self.svm_data['uid'])
            response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}
 def __init__(self):
     self.list_error = []
     self.sql        = SQL()
예제 #32
0
class Save_Feature(object):
    """@Save_Feature

    This class provides an interface to store the expected number of features
    that can be expected in a given dataset, and each feature instance into
    corresponding database tables (using EAV data model).

    Note: this class is invoked within 'base_data.py'

    Note: this class explicitly inherits the 'new-style' class.

    """
    def __init__(self, svm_data):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        self.svm_data = svm_data
        self.list_error = []
        self.sql = SQL()

    def save_count(self):
        """@save_count

        This method stores the number of features that can be expected in a
        given observation.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        """

        # insert / update dataset value(s)
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'INSERT INTO tbl_feature_count (id_entity, '\
            'count_features) VALUES(%s, %s)'
        args = (
            self.svm_data['id_entity'],
            self.svm_data['count_features'],
        )
        response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}

    def save_feature(self):
        """@save_feature

        This method can store, or update an existing SVM dataset stored in
        corresponding database tables (using EAV data model).

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime

        """

        # insert / update dataset value(s)
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'INSERT INTO tbl_feature_value (id_entity, '\
            'dep_variable_label, indep_variable_label, indep_variable_value) '\
            'VALUES(%s, %s, %s, %s)'
        dataset = self.svm_data['svm_dataset']
        args = (
            self.svm_data['id_entity'],
            dataset['dep_variable_label'],
            dataset['indep_variable_label'],
            dataset['indep_variable_value'],
        )
        response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}
class Retrieve_Feature(object):

    ## constructor:
    def __init__(self):
        # class variables
        self.list_error = []
        self.sql        = SQL()

    ## get_dataset: retrieve an SVM dataset from corresponding 'EAV data model'
    #               database table(s), using a fixed 'id_entity'.
    #
    #  @id_entity, this supplied argument corresponds to the 'id_entity' column from the
    #      'tbl_dataset_value' database table.
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s' 
    #      is used for argument substitution.
    def get_dataset(self, id_entity):
        # select dataset
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'SELECT dep_variable_label, indep_variable_label, indep_variable_value FROM tbl_feature_value where id_entity=%s'
        args          = (id_entity)
        response      = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error: return {'status': False, 'error': response_error, 'result': None}
        else: return {'status': True, 'error': None, 'result': response['result']}

    ## get_count: retrieve the number of features that can be expected in any given observation,
    #             from a particular dataset instance (id_entity).
    #
    #  @id_entity, this supplied argument corresponds to the 'id_entity' column from the
    #      'tbl_dataset_value' database table.
    #
    #  @sql_statement, is a sql format string, and not a python string. Therefore, '%s'
    #      is used for argument substitution.
    def get_count(self, id_entity):
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'SELECT count_features FROM tbl_feature_count where id_entity=%s'
        args          = (id_entity)
        response      = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error: return {'status': False, 'error': response_error, 'result': None}
        else: return {'status': True, 'error': None, 'result': response['result']}
예제 #34
0
class Retrieve_Feature(object):
    '''

    This class provides an interface to retrieve corresponding dataset(s),
    using a fixed supplied 'id_entity'.  The 'id_entity' is a reference,
    indicating which dataset to get.

    Note: this class is invoked within 'model_generate.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self):
        '''

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_dataset(self, id_entity, model):
        '''

        This method retrieves a correspondinng dataset, from corresponding
        'EAV data model' database table(s), using a fixed 'id_entity'.

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        @model, is the model type (i.e. svm, svr)

        '''

        # local variables
        list_model_type = current_app.config.get('MODEL_TYPE')

        # establish connection
        self.sql.sql_connect(self.db_ml)

        # case 1: svm data
        if model == list_model_type[0]:
            sql_statement = 'SELECT dep_variable_label, '\
                'indep_variable_label, indep_variable_value '\
                'FROM tbl_svm_data '\
                'WHERE id_entity=%s'

        # case 2: svr data
        elif model == list_model_type[1]:
            sql_statement = 'SELECT criterion, indep_variable_label, '\
                'indep_variable_value '\
                'FROM tbl_svr_data '\
                'WHERE id_entity=%s'

        # get dataset
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {
                'status': False,
                'error': response_error,
                'result': None
            }
        else:
            return {
                'status': True,
                'error': None,
                'result': response['result'],
            }

    def get_count(self, id_entity):
        '''

        This method retrieves the number of features that can be expected in
        any given observation, from a particular dataset instance (id_entity).

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.
        '''

        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT count_features '\
            'FROM tbl_feature_count '\
            'WHERE id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {
                'status': False,
                'error': response_error,
                'result': None
            }
        else:
            return {
                'status': True,
                'error': None,
                'result': response['result'],
            }
 def __init__(self):
     # class variables
     self.list_error = []
     self.sql        = SQL()
class Save_Observation(object):
    '''@Save_Observation, explicitly inherit 'new-style' class

    This class provides an interface to store observation labels, provided
    from corresponding dataset(s) into corresponding database tables.

    Note: this class is invoked within 'base_data.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''

    def __init__(self, premodel_data, session_type):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        # class variables
        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def save_label(self):
        '''@save_label

        This method can store, or update an existing set of observation labels
        in corresponding database tables (using EAV data model).

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime
        '''

        # insert / update feature label(s)
        self.sql.sql_connect(self.db_ml)

        # add labels (append case)
        if self.session_type in ['data_append', 'data_new']:

            # check if observation label exists in database
            sql_statement = 'SELECT * FROM tbl_observation_label '\
                'WHERE dep_variable_label=%s '\
                'AND id_entity=%s'
            args = (
                self.premodel_data['label'],
                self.premodel_data['id_entity']
            )
            response = self.sql.sql_command(sql_statement, 'select', args)

            # add labels if not exist
            if not response['result']:
                sql_statement = 'INSERT INTO tbl_observation_label '\
                    '(id_entity, dep_variable_label) VALUES(%s, %s)'
                args = (
                    self.premodel_data['id_entity'],
                    self.premodel_data['label']
                )
                self.sql.sql_command(
                    sql_statement,
                    'insert',
                    args,
                )

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None}
예제 #37
0
class Save_Entity(object):
    '''@Save_Entity

    This class provides an interface to save dataset(s) later used to generate
    corresponding model(s).

    Note: this class is invoked within 'base_data.py', and 'data_append.py'

    Note: this class explicitly inherits the 'new-style' class.
    '''
    def __init__(self, premodel_data, session_type):
        '''@__init__

        This constructor is responsible for defining class variables.

        @self.premodel_data, a dictionary with the following elements:

            {'uid': xx, 'id_entity': xx, 'title': yyy}

        Note: 'xx' denotes an integer value, 'yyy' a unicode string, and 'zz'
              representing a float value.

        '''

        self.premodel_data = premodel_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def save(self):
        '''@save

        This method stores, or updates dataset entities into its corresponding
        'EAV data model' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime

        '''

        # insert / update dataset entity value
        self.sql.sql_connect(self.db_ml)

        if self.session_type == 'data_append':
            sql_statement = 'UPDATE tbl_dataset_entity '\
                'SET uid_modified=%s, datetime_modified=UTC_TIMESTAMP() '\
                'WHERE id_entity=%s'
            args = (self.premodel_data['uid'], self.premodel_data['id_entity'])
            response = self.sql.sql_command(sql_statement, 'update', args)

        elif self.session_type == 'data_new':
            sql_statement = 'INSERT INTO tbl_dataset_entity '\
                '(title, model_type, uid_created, datetime_created) '\
                'VALUES(%s, %s, %s, UTC_TIMESTAMP())'
            args = (self.premodel_data['title'],
                    self.premodel_data['model_type'],
                    self.premodel_data['uid'])
            response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}
예제 #38
0
class Save_Feature(object):
    """@Save_Feature

    This class provides an interface to store the expected number of features
    that can be expected in a given dataset, and each feature instance into
    corresponding database tables (using EAV data model).

    Note: this class is invoked within 'base_data.py'

    Note: this class explicitly inherits the 'new-style' class.

    """

    def __init__(self, svm_data):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        self.svm_data = svm_data
        self.list_error = []
        self.sql = SQL()

    def save_count(self):
        """@save_count

        This method stores the number of features that can be expected in a
        given observation.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        """

        # insert / update dataset value(s)
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'INSERT INTO tbl_feature_count (id_entity, '\
            'count_features) VALUES(%s, %s)'
        args = (
            self.svm_data['id_entity'],
            self.svm_data['count_features'],
        )
        response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}

    def save_feature(self):
        """@save_feature

        This method can store, or update an existing SVM dataset stored in
        corresponding database tables (using EAV data model).

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime

        """

        # insert / update dataset value(s)
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'INSERT INTO tbl_feature_value (id_entity, '\
            'dep_variable_label, indep_variable_label, indep_variable_value) '\
            'VALUES(%s, %s, %s, %s)'
        dataset = self.svm_data['svm_dataset']
        args = (
            self.svm_data['id_entity'],
            dataset['dep_variable_label'],
            dataset['indep_variable_label'],
            dataset['indep_variable_value'],
        )
        response = self.sql.sql_command(sql_statement, 'insert', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None, 'id': response['id']}
 def __init__(self, svm_data, session_type):
     # class variables
     self.svm_data = svm_data
     self.session_type = session_type
     self.list_error = []
     self.sql = SQL()
예제 #40
0
class Retrieve_Feature(object):
    """@Retrieve_Feature

    This class provides an interface to retrieve an svm dataset, using a fixed
    supplied 'id_entity'.  The 'id_entity' is a reference, indicating which
    dataset to get.

    Note: this class is invoked within 'model_generate.py'

    Note: this class explicitly inherits the 'new-style' class.

    """
    def __init__(self):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        self.list_error = []
        self.sql = SQL()

    def get_dataset(self, id_entity):
        """@get_dataset

        This method retrieves an SVM dataset, from corresponding 'EAV data
        model' database table(s), using a fixed 'id_entity'.

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        """

        # select dataset
        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'SELECT dep_variable_label, indep_variable_label, '\
            'indep_variable_value FROM tbl_feature_value where id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error, 'result': None}
        else:
            return {
                'status': True,
                'error': None,
                'result': response['result'],
            }

    def get_count(self, id_entity):
        """@get_count

        This method retrieves the number of features that can be expected in
        any given observation, from a particular dataset instance (id_entity).

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.
        """

        self.sql.sql_connect('db_machine_learning')
        sql_statement = 'SELECT count_features FROM tbl_feature_count '\
            'where id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error, 'result': None}
        else:
            return {
                'status': True,
                'error': None,
                'result': response['result'],
            }
예제 #41
0
class Retrieve_Feature(object):
    """@Retrieve_Feature

    This class provides an interface to retrieve an svm dataset, using a fixed
    supplied 'id_entity'.  The 'id_entity' is a reference, indicating which
    dataset to get.

    Note: this class is invoked within 'model_generate.py'

    Note: this class explicitly inherits the 'new-style' class.

    """

    def __init__(self):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        self.list_error = []
        self.sql = SQL()

    def get_dataset(self, id_entity):
        """@get_dataset

        This method retrieves an SVM dataset, from corresponding 'EAV data
        model' database table(s), using a fixed 'id_entity'.

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        """

        # select dataset
        self.sql.sql_connect("db_machine_learning")
        sql_statement = (
            "SELECT dep_variable_label, indep_variable_label, "
            "indep_variable_value FROM tbl_feature_value where id_entity=%s"
        )
        args = id_entity
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"status": False, "error": response_error, "result": None}
        else:
            return {"status": True, "error": None, "result": response["result"]}

    def get_count(self, id_entity):
        """@get_count

        This method retrieves the number of features that can be expected in
        any given observation, from a particular dataset instance (id_entity).

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.
        """

        self.sql.sql_connect("db_machine_learning")
        sql_statement = "SELECT count_features FROM tbl_feature_count " "where id_entity=%s"
        args = id_entity
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"status": False, "error": response_error, "result": None}
        else:
            return {"status": True, "error": None, "result": response["result"]}
class Save_Observation(object):
    """@Save_Observation, explicitly inherit 'new-style' class

    This class provides an interface to store observation labels, provided
    from corresponding dataset(s) into corresponding database tables.

    Note: this class is invoked within 'base_data.py'

    Note: this class explicitly inherits the 'new-style' class.

    """

    def __init__(self, svm_data, session_type):
        """@__init__

        This constructor is responsible for defining class variables.

        """

        # class variables
        self.svm_data = svm_data
        self.session_type = session_type
        self.list_error = []
        self.sql = SQL()

    def save_label(self):
        """@save_label

        This method can store, or update an existing set of observation labels
        in corresponding database tables (using EAV data model).

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        Note: 'UTC_TIMESTAMP' returns the universal UTC datetime
        """

        # insert / update feature label(s)
        self.sql.sql_connect('db_machine_learning')

        # add labels (append case)
        if self.session_type in ['data_append', 'data_new']:

            # check if observation label exists in database
            sql_statement = 'SELECT * FROM tbl_observation_label WHERE '\
                'dep_variable_label=%s AND id_entity=%s'
            args = (self.svm_data['label'], self.svm_data['id_entity'])
            response = self.sql.sql_command(sql_statement, 'select', args)

            # add labels if not exist
            if not response['result']:
                sql_statement = 'INSERT INTO tbl_observation_label '\
                    '(id_entity, dep_variable_label) VALUES(%s, %s)'
                args = (self.svm_data['id_entity'], self.svm_data['label'])
                self.sql.sql_command(
                    sql_statement,
                    'insert',
                    args,
                )

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error}
        else:
            return {'status': True, 'error': None}
class Retrieve_Account(object):
    """

    This class provides an interface to check if a username already exists,
    and retrieves the corresponding password.

    Note: this class explicitly inherits the 'new-style' class.

    """

    def __init__(self):
        """

        This constructor is responsible for defining class variables.

        """

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get("DB_ML")

    def check_username(self, username):
        """

        This method checks if the supplied username already exists.

        """

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = "SELECT * " "FROM tbl_user " "WHERE username=%s"
        args = username
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"error": response_error, "result": None}
        else:
            return {"error": None, "result": response["result"]}

    def check_email(self, email):
        """

        This method checks if the supplied email already exists.

        """

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = "SELECT * " "FROM tbl_user " "WHERE email=%s"
        args = email
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"error": response_error, "result": None}
        else:
            return {"error": None, "result": response["result"]}

    def get_password(self, username):
        """

        This method returns the hashed password for a supplied username.

        """

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = "SELECT password " "FROM tbl_user " "WHERE username=%s"
        args = username
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"error": response_error, "result": None}
        else:
            return {"error": None, "result": response["result"][0][0]}

    def get_uid(self, username):
        """

        This method returns the userid (i.e uid) for a supplied username.

        """

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = "SELECT id_user " "FROM tbl_user " "WHERE username=%s"
        args = username
        response = self.sql.sql_command(sql_statement, "select", args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {"error": response_error, "result": None}
        else:
            return {"error": None, "result": response["result"][0][0]}
class Retrieve_Feature(object):
    '''@Retrieve_Feature

    This class provides an interface to retrieve corresponding dataset(s),
    using a fixed supplied 'id_entity'.  The 'id_entity' is a reference,
    indicating which dataset to get.

    Note: this class is invoked within 'model_generate.py'

    Note: this class explicitly inherits the 'new-style' class.

    '''
    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def get_dataset(self, id_entity, model):
        '''@get_dataset

        This method retrieves a correspondinng dataset, from corresponding
        'EAV data model' database table(s), using a fixed 'id_entity'.

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.

        @model, is the model type (i.e. svm, svr)

        '''

        # local variables
        list_model_type = current_app.config.get('MODEL_TYPE')

        # establish connection
        self.sql.sql_connect(self.db_ml)

        # case 1: svm data
        if model == list_model_type[0]:
            sql_statement = 'SELECT dep_variable_label, '\
                'indep_variable_label, indep_variable_value '\
                'FROM tbl_svm_data '\
                'WHERE id_entity=%s'

        # case 2: svr data
        elif model == list_model_type[1]:
            sql_statement = 'SELECT criterion, indep_variable_label, '\
                'indep_variable_value '\
                'FROM tbl_svr_data '\
                'WHERE id_entity=%s'

        # get dataset
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error, 'result': None}
        else:
            return {
                'status': True,
                'error': None,
                'result': response['result'],
            }

    def get_count(self, id_entity):
        '''@get_count

        This method retrieves the number of features that can be expected in
        any given observation, from a particular dataset instance (id_entity).

        @id_entity, this supplied argument corresponds to the 'id_entity'
            column from the 'tbl_dataset_value' database table.

        @sql_statement, is a sql format string, and not a python string.
            Therefore, '%s' is used for argument substitution.
        '''

        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT count_features '\
            'FROM tbl_feature_count '\
            'WHERE id_entity=%s'
        args = (id_entity)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'status': False, 'error': response_error, 'result': None}
        else:
            return {
                'status': True,
                'error': None,
                'result': response['result'],
            }
예제 #45
0
class Retrieve_Account(object):
    '''
    @Retrieve_Username

    This class provides an interface to check if a username already exists,
    and retrieves the corresponding password.

    Note: this class explicitly inherits the 'new-style' class.

    '''
    def __init__(self):
        '''@__init__

        This constructor is responsible for defining class variables.

        '''

        self.list_error = []
        self.sql = SQL()
        self.db_ml = current_app.config.get('DB_ML')

    def check_username(self, username):
        '''@check_username

        This method checks if the supplied username already exists.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT * '\
            'FROM tbl_user '\
            'WHERE username=%s'
        args = (username)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result']}

    def check_email(self, email):
        '''@get_email

        This method checks if the supplied email already exists.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT * '\
            'FROM tbl_user '\
            'WHERE email=%s'
        args = (email)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result']}

    def get_password(self, username):
        '''@get_password

        This method returns the hashed password for a supplied username.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT password '\
            'FROM tbl_user '\
            'WHERE username=%s'
        args = (username)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result'][0][0]}

    def get_uid(self, username):
        '''@get_uid

        This method returns the userid (i.e uid) for a supplied username.

        '''

        # select dataset
        self.sql.sql_connect(self.db_ml)
        sql_statement = 'SELECT id_user '\
            'FROM tbl_user '\
            'WHERE username=%s'
        args = (username)
        response = self.sql.sql_command(sql_statement, 'select', args)

        # retrieve any error(s), disconnect from database
        response_error = self.sql.get_errors()
        self.sql.sql_disconnect()

        # return result
        if response_error:
            return {'error': response_error, 'result': None}
        else:
            return {'error': None, 'result': response['result'][0][0]}