diff --git a/bd_api/apps/api/v1/models.py b/bd_api/apps/api/v1/models.py index 569cfda8..b630286d 100644 --- a/bd_api/apps/api/v1/models.py +++ b/bd_api/apps/api/v1/models.py @@ -243,6 +243,20 @@ def clean(self) -> None: "'information_request', 'column', 'key', 'analysis' must be set." ) + def has_area_intersection(self, other: "Coverage"): + if not self.area: + return True + if not other.area: + return True + if self.area.name.startswith(other.area.name): + return True + if other.area.name.startswith(self.area.name): + return True + return False + + def has_datetime_intersection(self, other: "Coverage"): + ... + class License(BaseModel): """License model""" @@ -1122,7 +1136,7 @@ def get_graphql_full_coverage(self): def neighbors(self): """Similiar tables and columns - Tables and columns with similar directories - - Tables and columns with similar coverages or tags (WIP) + - Tables and columns with similar coverages or tags """ all_neighbors = [] for column in self.columns.all(): @@ -1153,6 +1167,13 @@ def last_updated_at(self): def get_graphql_last_updated_at(self): return self.last_updated_at + def has_directory_intersection(self, other: "Table"): + for cola in self.columns.filter(directory_primary_key__isnull=False).all(): + for colb in other.columns.filter(directory_primary_key__isnull=False).all(): + if cola.has_directory_intersection(colb): + return True + return False + def clean(self): """ Clean method for Table model @@ -1384,6 +1405,11 @@ def get_graphql_neighbors(self) -> list[dict]: ) return get_unique_list(all_neighbors) + def has_directory_intersection(self, other: "Column"): + if self.directory_primary_key == other.directory_primary_key: + return True + return False + class ColumnOriginalName(BaseModel): """Model definition for ColumnOriginalName."""