-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add table neighbor model (#571)
- Loading branch information
Showing
6 changed files
with
245 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from graphene import UUID, Boolean, Float, List, ObjectType, String | ||
from graphene_django import DjangoObjectType | ||
|
||
from bd_api.apps.api.v1.models import TableNeighbor | ||
from bd_api.custom.graphql_base import PlainTextNode | ||
|
||
|
||
class TableNeighborNode(DjangoObjectType): | ||
"""Similiar tables and columns with filters""" | ||
|
||
table_id = String() | ||
table_name = String() | ||
dataset_id = String() | ||
dataset_name = String() | ||
score = Float() | ||
|
||
class Meta: | ||
model = TableNeighbor | ||
fields = ("id",) | ||
filter_fields = ("id",) | ||
interfaces = (PlainTextNode,) | ||
|
||
def resolve__table_id(root, info): | ||
return root.table_b.pk | ||
|
||
def resolve__table_name(root, info): | ||
return root.table_b.name | ||
|
||
def resolve__dataset_id(root, info): | ||
return root.table_b.dataset.pk | ||
|
||
def resolve__dataset_name(root, info): | ||
return root.table_b.dataset.name | ||
|
||
def resolve_score(root, info): | ||
return root.score | ||
|
||
|
||
class APIQuery(ObjectType): | ||
get_table_neighbor = List( | ||
TableNeighborNode, | ||
table_id=UUID(required=True), | ||
theme=String(), | ||
share_theme=Boolean(), | ||
) | ||
|
||
def resolve_get_table_neighbor(root, info, table_id, **kwargs): | ||
return TableNeighbor.objects.filter(table_a__pk=table_id).all() |
58 changes: 58 additions & 0 deletions
58
bd_api/apps/api/v1/migrations/0028_tableneighbor_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 4.2.10 on 2024-03-20 11:53 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("v1", "0027_dataset_page_views_table_page_views"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="TableNeighbor", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("similarity", models.FloatField(default=0)), | ||
("similarity_of_area", models.FloatField(default=0)), | ||
("similarity_of_datetime", models.FloatField(default=0)), | ||
("similarity_of_directory", models.FloatField(default=0)), | ||
("similarity_of_popularity", models.FloatField(default=0)), | ||
( | ||
"table_a", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="tableneighbor_a_set", | ||
to="v1.table", | ||
), | ||
), | ||
( | ||
"table_b", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="tableneighbor_b_set", | ||
to="v1.table", | ||
), | ||
), | ||
], | ||
options={ | ||
"db_table": "table_neighbor", | ||
}, | ||
), | ||
migrations.AddConstraint( | ||
model_name="tableneighbor", | ||
constraint=models.UniqueConstraint( | ||
fields=("table_a", "table_b"), name="table_neighbor_unique_constraint" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters