Change structure of `rule-lib` for faster processing and easier reading of rule definitions
The rule definitions are now simple python files, where the input parameters are specified in some metadata attributes and the code is then executed. One example of such code can be this:
if floors is not None:
area = floors * footprint
else:
area = None
Problem
If we would make a repository with linters checks etc., we would run into the problem that theoretically here, the floors
and footprint
parameters are not defined. Therefore this won't pass our checks. My suggestion is to change the code, such that there is always one function that is executed, with some parameters:
class AreaRule:
def __call__(self, floors=None, footprint=None, **kwargs):
if floors is not None:
area = floors * footprint
else:
area = None
return {"area": area}
One note here:
- We need to return the outputs as a dictionary, because we don't know beforehand what are the outputs (as functions are not defined at run-time)
- We need to create a class every time. If we would make functions instead, they would be global and that might run into problems if we would get many rules that are for example similar, but slightly different per location.