af.controller.data package¶
Submodules¶
af.controller.data.CSVController module¶
-
class
af.controller.data.CSVController.CSVController(data_location)[source]¶ Bases:
af.controller.data.DataController.DataControllerClass that can handles csv data files
-
CONTROLLER_EXTENSION= 'CSV (*.csv)'¶
-
CONTROLLER_TYPE= 'csv'¶
-
amount_of_rows(table_name=None)[source]¶ Returns the amount of rows the file contains.
Parameters: table_name (string) – name of the table Return type: int
-
db_available_tables()[source]¶ Returns the csv file name. Because it’s a csv file, and not a db, the table is unique and is the one expressed on the document
Return type: string
-
get_table_columns_type(table_name=None)[source]¶ Returns the types of the columns of a given table
Parameters: table_name (string) – name of the table which is to be loaded Return type: list
-
af.controller.data.DataController module¶
-
class
af.controller.data.DataController.DataController(data_location)[source]¶ Bases:
objectBase class for all controllers that are intended to retrieve data from any type of db form
-
CONTROLLER_EXTENSION= None¶
-
CONTROLLER_TYPE= None¶
-
amount_of_rows(table_name)[source]¶ Returns the amount of rows a table contains Abstract method. Not Implemented
Parameters: table_name (string) – name of the table which is queried Return type: int
-
db_available_tables()[source]¶ Returns all the available tables of a database. Abstract method. Not Implemented
Return type: list
-
get_frequency_of_qi_attributes(table_name, qi_list)[source]¶ Returns the frequency of certain attributes Abstract method. Not Implemented
Parameters: - table_name (string) – name of the table which is queried
- qi_list (list) – list of attributes to query their frequency
Return type: list
-
get_table_columns_type(table_name)[source]¶ Returns the types of all the columns of a given table Abstract method. Not Implemented
Parameters: table_name (string) – name of the table which is queried Return type: string
-
af.controller.data.DataFactory module¶
-
class
af.controller.data.DataFactory.DataFactory[source]¶ Factory class for all DB controllers created in the module directory
-
static
create_controller(data_location, controller_type)[source]¶ Given a controller type, it creates a new controller instance based on the existent one on the data module directory.
Parameters: - data_location (string) – Location of the database to use
- controller_type (string) – Type of controller we want to create the instance
Return type: class:af.controller.anonymization.data.DataController instance
-
static
get_available_controllers()[source]¶ Returns all the available controllers tyoes contained on the data module directory.
Return type: list of available controller types
-
static
get_controller_file_extension(controller_type)[source]¶ Given a controller type, it looks for its extension and returns it
Parameters: controller_type (string) – Type of DataController Return type: DataController extension
-
static
get_controller_from_extension(controller_extension)[source]¶ Given a controller extension, it retrieves the class to which it belongs.
Parameters: controller_extension (string) – Extension of the DataController intended to be looked for Return type: class:af.controller.anonymization.data.DataController class
-
static
af.controller.data.SqliteController module¶
-
class
af.controller.data.SqliteController.SqliteController(data_location)[source]¶ Bases:
af.controller.data.DataController.DataControllerClass that implements a way to connecting to sqlite dbs
-
CONTROLLER_EXTENSION= 'SQLite (*.sqlite3 *.db *.sqlite)'¶
-
CONTROLLER_TYPE= 'sqlite'¶
-
amount_of_rows(table_name)[source]¶ Returns the amount of rows a table contains
Parameters: table_name (string) – name of the table which is queried Return type: int
-
static
create_db_copy(from_location, to_location)[source]¶ Creates the copy of a certain db to a new location
Parameters: - from_location (string) – original location of the db
- to_location (string) – new location for the db
-
db_available_tables()[source]¶ Returns all the available tables of a sqlite database.
Return type: list
-
execute_many(query, values_list)[source]¶ Execute a query in the form of a typical executemany sqlite fashion
Parameters: - query (string) – Query to execute in bulk mode
- values_list (list) – Values that will go taking place during the bulk query
-
execute_query(query)[source]¶ Executes a query against a loaded db table. Returns the query result in the form of a generator.
Parameters: query (string) – query to execute Return type: list<generator>
-
get_count_of_distinct_qi_values(table_name, qi)[source]¶ Returns count of distinct values of a certain qi attribute
Parameters: - table_name (string) – name of the table which is queried
- qi (string) – Quasi Identifier attribute name
Return type: int
-
get_count_of_qi_value(table_name, qi_list, values)[source]¶ Return the amount of times a certain row contains the values of a qi attribute list
Parameters: - table_name (string) – name of the table which is queried
- qi_list (list) – List containing all the qi attributes names to query
- values (list) – List of all the particular values for each of the attributes contained on the qi_list
Return type: int
-
get_distinct_qi_values(table_name, qi)[source]¶ Returns all the distinct values of a certain qi attribute
Parameters: - table_name (string) – name of the table which is queried
- qi (string) – Quasi Identifier attribute name
Return type: list<generator>
-
get_frequency_of_eq_classes(table_name, qi_list)[source]¶ Returns the frequency of the equivalence classes of attributes list on a given sqlite table.
Parameters: - table_name (string) – name of the table which is queried
- qi_list (list) – list of attributes to query their frequency
Return type: list
-
get_frequency_of_qi_attributes(table_name, qi_list)[source]¶ Returns the frequency of certain attributes list on a given sqlite table.
Parameters: - table_name (string) – name of the table which is queried
- qi_list (list) – list of attributes to query their frequency
Return type: list<generator>
-
get_groups_examples(table, qi_list)[source]¶ Given a table name and a qi list, retrieves certain distinct rows in the form of a dictionary containing the columns info and the data sample.
Parameters: - table (string) – Table name to query
- qi_list (list) – Quasi-Identifiable attributes names to group by
Return type: dict
-
get_table_columns_type(table_name)[source]¶ Returns the types of all the columns of a given sqlite table
Parameters: table_name (string) – name of the table which is queried Return type: string
-
get_table_data(table_name)[source]¶ Returns all the data of a given sqlite table
Parameters: table_name (string) – name of the table which is queried Return type: list
-
remove_row(cursor, table_name, qi_list, values)[source]¶ Deletes those rows on the table that match the values conditions for the qi_list attributes
Parameters: - table_name (string) – name of the table which is queried
- qi_list (list) – List containing all the qi attributes names to query
- values (list) – List of all the particular values for each of the attributes contained on the qi_list
-
remove_rows(table_name, qi_list, rows_to_remove)[source]¶ Given a list of row values to remove, it deletes each one of them from the given table.
Parameters: - table_name (string) – name of the table which is queried
- qi_list (list) – List containing all the qi attributes names to query
- rows_to_remove (list) – Contains all the values to remove from the table.
-
rename_table(old_table_name, new_table_name)[source]¶ Renames a certain table to a new table name
Parameters: - old_table_name (string) – Current name of the table
- new_table_name (string) – New name for the table
-
table_columns_info(table_name)[source]¶ Returns all the header data of a given sqlite table
Parameters: table_name (string) – name of the table which is queried Return type: list
-
update_qi_value(table_name, qi, new_value, old_value)[source]¶ Given a table and a qi attribute of it, it updates it’s value to a new one.
Parameters: - table_name (string) – name of the table which is queried
- qi (string) – Quasi Identifier attribute name
- new_value (string) – New value for the qi attribute
- old_value (string) – Current value of the qi attribute
-
update_qi_values(table_name, qi, dic)[source]¶ Given a table and a qi attribute of it, it updates the qi using the dic key-value store where the key is the new value and the value of the dic are the old values
Parameters: - table_name (string) – name of the table which is queried
- qi (string) – Quasi Identifier attribute name
- dicc (dict) – Dictionary containing all the updates of the form {new_value: list_of_old_values}
-
update_qi_values_in_range(cursor, table_name, qi, new_value, old_values)[source]¶ Given a table and a qi attribute of it, it updates it’s value to a new one for those belonging to a certain range.
Parameters: - table_name (string) – name of the table which is queried
- qi (string) – Quasi Identifier attribute name
- new_value (string) – New value for the qi attribute
- old_values (list) – List of possible current values of the qi attribute
-