src.fairreckitlib.data.filter.filter_params
This module contains the parameter creation functions for filters.
Functions:
create_params_numerical: TODO
create_params_categorical: TODO
create_params_count: TODO
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)
1"""This module contains the parameter creation functions for filters. 2 3Functions: 4 5 create_params_numerical: TODO 6 create_params_categorical: TODO 7 create_params_count: TODO 8 9This program has been developed by students from the bachelor Computer Science at 10Utrecht University within the Software Project course. 11© Copyright Utrecht University (Department of Information and Computing Sciences) 12""" 13 14from ...core.config.config_parameters import ConfigParameters 15 16 17def create_params_numerical(**kwargs) -> ConfigParameters: 18 """Create the parameters of a numerical filter. 19 20 Keyword Args: 21 column_name(str): the name of the column that has numerical values. 22 dataset(Dataset): the dataset associated with the filter. 23 matrix_name(str): the matrix name related to the dataset. 24 25 Returns: 26 the configuration parameters of the numerical filter. 27 """ 28 column_name = kwargs['column_name'] 29 dataset = kwargs['dataset'] 30 matrix_name = kwargs['matrix_name'] 31 32 params = ConfigParameters() 33 34 for table_name, table_columns in dataset.get_available_columns(matrix_name).items(): 35 if column_name in table_columns: 36 table = dataset.read_table(table_name, [column_name]) 37 numerical_range = (int(table[column_name].min()), int(table[column_name].max())) 38 params.add_range('range', int, numerical_range, numerical_range) 39 40 return params 41 42 43def create_params_categorical(**kwargs) -> ConfigParameters: 44 """Create the parameters of a categorical filter. 45 46 Keyword Args: 47 column_name(str): the name of the column that has categorical values. 48 dataset(Dataset): the dataset associated with the filter. 49 matrix_name(str): the matrix name related to the dataset. 50 51 Returns: 52 the configuration parameters of the categorical filter. 53 """ 54 column_name = kwargs['column_name'] 55 dataset = kwargs['dataset'] 56 matrix_name = kwargs['matrix_name'] 57 58 params = ConfigParameters() 59 60 for table_name, table_columns in dataset.get_available_columns(matrix_name).items(): 61 if column_name in table_columns: 62 table = dataset.read_table(table_name, [column_name]) 63 categories = list(table[column_name].fillna('').unique()) 64 categories = [None if len(c) == 0 else c for c in categories] 65 params.add_multi_option('values', categories, categories) 66 67 return params 68 69def create_params_count(**_) -> ConfigParameters: 70 """Create the parameters of a count filter. 71 72 Returns: 73 the configuration parameters of the count filter. 74 """ 75 params = ConfigParameters() 76 params.add_number('threshold', int, 100, (1, 10000000000)) 77 return params
18def create_params_numerical(**kwargs) -> ConfigParameters: 19 """Create the parameters of a numerical filter. 20 21 Keyword Args: 22 column_name(str): the name of the column that has numerical values. 23 dataset(Dataset): the dataset associated with the filter. 24 matrix_name(str): the matrix name related to the dataset. 25 26 Returns: 27 the configuration parameters of the numerical filter. 28 """ 29 column_name = kwargs['column_name'] 30 dataset = kwargs['dataset'] 31 matrix_name = kwargs['matrix_name'] 32 33 params = ConfigParameters() 34 35 for table_name, table_columns in dataset.get_available_columns(matrix_name).items(): 36 if column_name in table_columns: 37 table = dataset.read_table(table_name, [column_name]) 38 numerical_range = (int(table[column_name].min()), int(table[column_name].max())) 39 params.add_range('range', int, numerical_range, numerical_range) 40 41 return params
Create the parameters of a numerical filter.
Keyword Args: column_name(str): the name of the column that has numerical values. dataset(Dataset): the dataset associated with the filter. matrix_name(str): the matrix name related to the dataset.
Returns: the configuration parameters of the numerical filter.
44def create_params_categorical(**kwargs) -> ConfigParameters: 45 """Create the parameters of a categorical filter. 46 47 Keyword Args: 48 column_name(str): the name of the column that has categorical values. 49 dataset(Dataset): the dataset associated with the filter. 50 matrix_name(str): the matrix name related to the dataset. 51 52 Returns: 53 the configuration parameters of the categorical filter. 54 """ 55 column_name = kwargs['column_name'] 56 dataset = kwargs['dataset'] 57 matrix_name = kwargs['matrix_name'] 58 59 params = ConfigParameters() 60 61 for table_name, table_columns in dataset.get_available_columns(matrix_name).items(): 62 if column_name in table_columns: 63 table = dataset.read_table(table_name, [column_name]) 64 categories = list(table[column_name].fillna('').unique()) 65 categories = [None if len(c) == 0 else c for c in categories] 66 params.add_multi_option('values', categories, categories) 67 68 return params
Create the parameters of a categorical filter.
Keyword Args: column_name(str): the name of the column that has categorical values. dataset(Dataset): the dataset associated with the filter. matrix_name(str): the matrix name related to the dataset.
Returns: the configuration parameters of the categorical filter.
70def create_params_count(**_) -> ConfigParameters: 71 """Create the parameters of a count filter. 72 73 Returns: 74 the configuration parameters of the count filter. 75 """ 76 params = ConfigParameters() 77 params.add_number('threshold', int, 100, (1, 10000000000)) 78 return params
Create the parameters of a count filter.
Returns: the configuration parameters of the count filter.