Skip to content

Commit

Permalink
feat:rank and filter table/column neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Feb 14, 2024
1 parent 1aa3d77 commit e97def7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion bd_api/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit e97def7

Please sign in to comment.