Skip to content
Snippets Groups Projects

Resolve "Introduce a new filter for when rules should be run based on the source ID of a building."

Compare and Show latest version
2 files
+ 42
54
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 13
48
@@ -29,14 +29,15 @@ class AbstractRule(abc.ABC):
structure that is or could be necessary for all rules.
Args:
filters_dict (dict):
String representing the source_id_filter for the rule. May contain more than one
filter input, such as the `source_id` and the `geographic_filter_boundary`.
"""
rule_source_ids (list):
A list of integers representing all the valid source ID's for the rule.
geographic_filter_boundary (str):
Boundary polygon in WKT format defining the geographic boundary of the rule.
def __init__(self, filters_dict: dict = None):
"""
rule_source_ids, geographic_filter_boundary = self.parse_filters(filters_dict)
def __init__(self, rule_source_ids: list = None, geographic_filter_boundary: str = None):
self.geographic_filter_boundary_geometry = None
if geographic_filter_boundary is not None:
@@ -44,9 +45,6 @@ class AbstractRule(abc.ABC):
geographic_filter_boundary
)
if rule_source_ids is not None:
rule_source_ids = [int(source_id) for source_id in rule_source_ids]
self.rule_source_ids = rule_source_ids
@abc.abstractmethod
@@ -76,32 +74,6 @@ class AbstractRule(abc.ABC):
+ "please implement this class first."
)
@staticmethod
def parse_filters(filters_dict: dict) -> tuple | None:
"""
Parses the source_id_filter string input from the rule's XML file or the file attached
to it. Takes a single string separated by semicolons and splits it into the different
filter inputs it includes.
Args:
filters_dict (dict):
List with all the filter inputs.
Returns:
tuple | None:
A list of one or more strings each of which represents a different filter, or
None.
"""
if bool(filters_dict):
if "source_id" in filters_dict:
source_ids = filters_dict["source_id"].split(",")
else:
source_ids = None
return source_ids, filters_dict["boundary"]
return None, None
@staticmethod
def read_geometry_from_wkt(geographic_filter_boundary):
"""
@@ -145,23 +117,16 @@ class AbstractRule(abc.ABC):
"""
# Geographic filter, passes if the inputs coordinates lie within the boundary geometry.
if self.geographic_filter_boundary_geometry is None:
pass
elif self.geographic_filter_boundary_geometry.contains(
shapely.geometry.Point(longitude, latitude)
if (
self.geographic_filter_boundary_geometry is not None
and not self.geographic_filter_boundary_geometry.contains(
shapely.geometry.Point(longitude, latitude)
)
):
pass
else:
return False
# Source ID filter, passes if the rules and the inputs source ID match.
if self.rule_source_ids is None:
pass
elif source_id in self.rule_source_ids:
print(source_id, self.rule_source_ids)
pass
else:
if self.rule_source_ids is not None and source_id not in self.rule_source_ids:
return False
return True
Loading