Database Pipeline
flask_app.db_create_pipeline.add_fields_from_data(attr_names, values, object)
Add dynamic fields to an object from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attr_names |
List
|
A list of new fields that we want to add to the object. |
required |
values |
List
|
A list of values to be inserted in the database for the corresponding field. |
required |
object |
Database object
|
The database object to which we want to add dynamic fields. |
required |
Returns:
| Type | Description |
|---|---|
|
Database object: The updated database object with the new fields and values. |
Source code in flask_app/db_create_pipeline.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
flask_app.db_create_pipeline.get_doc_object_in_db(attr_names, values, display_fields)
Retrieves a document object from the database based on the provided attribute names, values, and display fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attr_names |
list
|
A list of attribute names. |
required |
values |
list
|
A list of corresponding attribute values. |
required |
display_fields |
list
|
A list of fields to be displayed. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
doc_obj |
The document object retrieved from the database. |
Source code in flask_app/db_create_pipeline.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
flask_app.db_create_pipeline.add_exp_to_db(data_exp)
Adds experiment data to the database based on the provided experiment configurations. Ensures that 'form' tasks (questionnaires) are uniquely identified per experiment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_exp |
list
|
A list of dictionaries, where each dictionary contains information about an experiment, including its tasks. |
required |
Returns: None
Source code in flask_app/db_create_pipeline.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
flask_app.db_create_pipeline.add_query_docs_to_db(data, data_configs)
Adding query and documents to the database. Args: data (dict): dict containing the query dataframe and the document dataframe. data_configs (dict): configuration dict of the dataset.
Source code in flask_app/db_create_pipeline.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
flask_app.db_create_pipeline.add_data_to_db(data, fields, ranking_type, query_col, sort_col='score', ascending=True)
Adding query-ranking pairs in the database (Data object). If pre-processing fairness methods are applied the changed data will be added in the database (DocRepr object).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
dict
|
dict containing the query dataframe and the document dataframe. |
required |
fields |
list(str
|
list of fields defined for the document. |
required |
ranking_type |
str
|
ranking type of the ranking to be added in the database (e.g. original if ranking is done based on the original value of sort_col, else depends on the ranker model or fairness intervention applied on the data). |
required |
query_col |
str
|
column name defined as the query. |
required |
sort_col |
str
|
column name to sort the documents in the ranking. |
'score'
|
ascending |
bool
|
True if sorting by sort_col in ascending order, else in descending order. |
True
|
Source code in flask_app/db_create_pipeline.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
flask_app.db_create_pipeline.get_docs_df(ranking_type, data_config, features)
Retrieve documents representation from the database and converts in dataframe. Args: ranking_type (str): If set to preprocessing, it retrieves the document representation transformed by the preprocessing fairness method. If set to original it retrieves the original document representation. data_config (dict): Configuration dict of the dataset. features (list(str)): List of columns representing the features of the document.
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
dataframe containing the retrieved document representation from the database. |
Source code in flask_app/db_create_pipeline.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
flask_app.db_create_pipeline.get_docs_df(ranking_type, data_config, features)
Retrieve documents representation from the database and converts in dataframe. Args: ranking_type (str): If set to preprocessing, it retrieves the document representation transformed by the preprocessing fairness method. If set to original it retrieves the original document representation. data_config (dict): Configuration dict of the dataset. features (list(str)): List of columns representing the features of the document.
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
dataframe containing the retrieved document representation from the database. |
Source code in flask_app/db_create_pipeline.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
Pipeline class for inserting the data in the database.
__init__(config)
Pipeline init class. Attributes
config : dict configuration dict defined in the configuration file data_reader : DataReader DataReader object corresponding to the dataset defined in the configuration file query_col : str
read_data()
Read data using the DataReader
Returns:
| Name | Type | Description |
|---|---|---|
data_train |
DataFrame
|
data used for training the ranker and/or the fairness intervention. |
data_test |
DataFrame
|
data used for testing and displaying in the UI. |
train_ranker()
Trains the ranking model based on the configurations defined under train_ranker_config.
It saves the predicted ranking on the test split in the database.
Returns: None
apply_fair_method(fields, config_method_key, sort_column, ascending)
Apply fairness methods defined in the configuration file under pre/in/post_processing_config.
Save the changed data (in case of pre-processing) and the new ranking in the database.
Args:
fields (list(str)): attributes of the document defined in the configuration file.
config_method_key (str): can have the following values: pre_processing, in_processing and post_processing
indicating which type of fairness method is applied.
sort_column (str): column name after which the items are ranked.
ascending (bool): True if sorting by sort_col in ascending order, else in descending order.