-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use model classes and also refactor original config impleme… #48
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @kapil-agnihotri, thank you for submitting a pull request. We will address it.
a79aa2f
to
1acb08a
Compare
…ntation to use model classes
1acb08a
to
5790d7d
Compare
c75409e
to
02a26a5
Compare
For now I have duplicated all model classes in here. I think later ranking-service can be modified to refer to the model classes from ProMCDA submodule. This will also reduce code duplication. |
@kapil-agnihotri The main reasons are:
|
@Flaminietta thank you for your feedback. I can create a new branch and push the changes to it once the review is complete. I believe that the review is still in progress? |
@kapil-agnihotri @mspada Did you already perform also end-to-end controlled tests? I still need to run it once. Do I run it from the terminal as before? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I didn't get around to running it, the principal structure is as I would have expected.
The README needs to be updated too for the new refactoring. For example, now the run is not initiated by typing: However, for now I cannot run it, I should dig deeper to find the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that this file represents a combination of the previous configuration.json. file and the input_matrix.cvs. I would name it referring to the idea of a configuration anyway, like "configuration_car_data_rank_robustness_on_weight_no_sensitivity.json"
In "robustness", what happens if the user selects "robustness": "indicators"? The entry "onWeightsLevel" will be then substituted with "on_indicators"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, in this example writing the input matrix is easy (even manually). What would the strategy be when the input matrix is a table with many more rows and columns?
@@ -7,21 +7,21 @@ | |||
Usage (from root directory): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that we won't run it from CLI anymore.
|
||
def config_dict_to_configuration_model(input_config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the function somewhere outside of this script. It's a utility, let's keep this running script clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring to the function by following the format used for the other functions.
Something like:
"""
Describe functionality.
Parameters:
- A (type): description.
- B (type): description.
Raises:
- ValueError: when it happens.
:param A: type
:param B: type
:return R: type
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the type hinting (that indicates the expected type of the value that the function will return).
|
||
def config_dict_to_configuration_model(input_config): | ||
# Extracting relevant configuration values | ||
config = Config(input_config) | ||
input_matrix = read_matrix(config.input_matrix_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retrieving the input_matrix_path
is possible from the old version of the configuration file (configuration.json). But it's not valid anymore with the new kind of configuration that you created in input_files/toy_example
. What is your plan?
|
||
|
||
# noinspection PyTypeChecker | ||
def main_using_model(input_config: dict) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I am unsure if main_using_model
is the best function name. What do you think of main_using_config
? Is the config that makes a difference, the model is always the same (i.e., MCDA).
T = typing.TypeVar('T') | ||
|
||
|
||
class Model(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring and in summary explain something like:
The class Model is designed to represent a data model with serialization and deserialization capabilities. It provides a framework for representing data models that can be easily serialized to and from dictionaries. It supports operations for equality checks, and for creating more complex models in Python applications with data exchange.
from ProMCDA.mcda import util | ||
|
||
|
||
class Configuration(Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the original class Config stays too, we need perhaps to review naming. It's quite confusing for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, adding short descriptions (docstrings) of the main functionalities helps navigate the various scripts.
For example:
The Configuration class encapsulates a configuration for MCDA, allowing for structured data representation and easy manipulation of attributes.
|
||
@property | ||
def sensitivity(self) -> ConfigurationSensitivity: | ||
"""Gets the sensitivity of this Configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adjust the docstrings to be less misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that these are all automatically generated scripts, and probably all necessary then. However, for me, the overall package structure became quite confusing. The name of this script is also confusing: why "modified"?
I am not sure we can make something different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand well that, if one day we want to modify something in the original configuration settings (e.g., by adding a new functionality), then all of these automatically created scripts won't be manually changed but Swagger will recreate them?
@@ -100,7 +104,7 @@ def get_list_random_input_matrices() -> list[pd.DataFrame]: | |||
config = TestMCDA_with_robustness.get_test_config() | |||
config = Config(config) | |||
mcda_with_robustness = MCDAWithRobustness(config, input_matrix, is_exact_pdf_mask, is_poisson_pdf_mask) | |||
output_list = mcda_with_robustness.convert_list(out_list) | |||
output_list = MCDAWithRobustness.convert_list(out_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, you instantiated MCDAWithRobustness in an object, why do you then use MCDAWithRobustness.convert_list(out_list)
? I believe that it works if you made it...
…ntation to use model classes