inasafe / inasafe

InaSAFE - QGIS plugin for estimating impact from natural disasters
www.inasafe.org
GNU General Public License v3.0
260 stars 135 forks source link

We need to migrate the IF archtecture #1627

Closed timlinux closed 8 years ago

timlinux commented 9 years ago

We want to adopt a more OOP architecture for IF's using this example as a guide:

https://github.com/timlinux/impact_function_registry

The above is my working proposal for how we could approach a new IF architecture. Note that it is just a prototype and not functionally complete. In that architecture, every IF would inherit from base.py ( https://github.com/timlinux/impact_function_registry/blob/master) and IF will be initialised, have properties set for hazard, exposure, parameters etc. The prototype above addresses a lot of the things we already discussed like providing for pervasive metadata and reducing the amount of boilerplate code we have.

You will note there is a prepare() method in that method the subclass would 'do whatever is needed to classify its data'. Its not in the example but there should be a run() method that would be the generic IF kernel.

A subclass (e.g. ITB Earthquake) could overload the run method if it wanted to do things differently. And of course each if would implement impact() and tabulated_impact() this is where they would write IF specific keywords to the metadata class.

For style we would try to standarised styles so that e.g. @charlotte-morgan 's concern about different IF's writing out high - medium - low in different orders can be address (e..g some list low - medium - high).

@IsmailSunni and @lucernae I think this is a good place for the two of you to dive in would you be happy to take my prototype above and start integrating it?

I think some of the things in the prototype need updating since we have changed the architecture a little since.

We will just need to work to coordinate things as we will be stepping on each other's toes a bit.

I was going to suggest one thing you could do to phase it is to wrap the old if logic inside of the new ones. So by wrap I mean that in the IF package you also put a copy of the old IF. And then in run you actually just delegate a call to old IF. When everything is fine, we delete the old IF. That way we can port the IF's over after the main architectural changes are done, and we can do it in a phased way e.g. do all the flood IF's first, then the earthquakes and so on.

akbargumbira commented 9 years ago

Hmm, we have implemented some of this in this PR https://github.com/AIFDR/inasafe/pull/1756 as the phase 1.

For the phase 2, these are some list that I have in mind: