Skip to content
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

Fiat adapter refactoring #433

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Fiat adapter refactoring #433

wants to merge 22 commits into from

Conversation

panosatha
Copy link
Contributor

No description provided.

@panosatha panosatha linked an issue May 1, 2024 that may be closed by this pull request
2 tasks
@panosatha panosatha marked this pull request as ready for review June 10, 2024 13:01
@panosatha panosatha requested review from LuukBlom and dladrichem June 10, 2024 13:01
@@ -42,17 +41,17 @@ def __init__(self, database: IDatabase):
def get_aggregation_areas(self) -> dict:
"""Get a list of the aggregation areas that are provided in the site configuration.

These are expected to much the ones in the FIAT model.
These are expected to much the ones in the direct impacts model.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean match

Comment on lines +121 to +133
@abstractmethod
def set_hazard(self, hazard) -> None:
"""
Set the hazard data for the model.

Args:
hazard (Hazard): The hazard object containing the necessary information.

Returns
-------
None
"""
...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should directly hard-couple the hazard to the direct impacts like this.
I think we had a very short discussion about this and decided we were going to put a class HazardOutput in between the Hazard models and the DirectImact models to completely decouple them. Where HazardOutput can have multiple formats.

That way any hazard model can implement functions to output its data to a HazardOutput and any DirectImacts model can then implement functions to read HazardOutput.

Implementing that is not the scope of this PR, so we can still merge this one, but we should keep this in mind. This is very related to the discussion with Dirk and Hessel as well, so good that we are looking at this now!

Comment on lines +88 to +91
def rel_to_abs_path(path):
if path:
path_abs = self.database_static_path.joinpath(path)
return path_abs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path(..).resolve() does this. Not that it really matters, just good practice to use builtin libraries if they are available!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of generalizing the DirectImacts adapter is great! However, we need to give some more consideration to what will be in the Interface and what should be in the ConcreteAdapter classes. The current implementation is very much based on fiat (obviously), which is not really neccesary as that functionality can be in the FiatAdapter itself.

This AdapterInterface is something that all DI adapters have in common and should in my opinion only contain very generic functions. Which are then implemented for the each model and call specific functions implemented for that model.

preprocess()        # setup model from template + read_hazard_output + x * add_measure()
run()                  
postprocess()    
has_run_check()

Possibly:

add_measure(measure: IMeasure) 
# Implement this function to handle all measures that make sense for that DirectImpact model, and do nothing for measures that dont affect this model. (think of raising buildings for RA2CE for example) 
read_hazard_output(output: IHazardOutput)
write_output(dst: Path)

With the goal of being able to treat all Hazards/Impacts agnostically like this: (where hazards & direct_impacts are lists of implemented Adapters)

def run_scenario()
  for hazard in hazards:
    hazard.preprocess()
    hazard.run()
    hazard.postprocess()

  for direct_impact in direct_impacts:
    direct_impact.preprocess()
    direct_impact.run()
    direct_impact.postprocess()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on direct_impacts_adapter.py.
This adapter class needs to implement all @abtractfunctions in the DirectImpactsAdapter Interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to have a look at how to do the dbs_classes refactor from Daley to the benefit class as well. It seems unnecessary to store the 3 database paths in a benefit object. Again, not the scope of this PR, but good to keep in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactroring FIAT adapter to a general DirectImpact adapter
2 participants