Skip to content

Commit

Permalink
feat: add table neighbor model
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Mar 15, 2024
1 parent d5d28f9 commit 03d424f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
54 changes: 54 additions & 0 deletions bd_api/apps/api/v1/migrations/0028_tableneighbor_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# Generated by Django 4.2.10 on 2024-03-15 18:55

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)),
(
"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",
),
),
],
),
migrations.AddConstraint(
model_name="tableneighbor",
constraint=models.UniqueConstraint(
fields=("table_a", "table_b"), name="table_neighbor_unique_constraint"
),
),
]
34 changes: 34 additions & 0 deletions bd_api/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,40 @@ def clean(self):
raise ValidationError(errors)


class TableNeighbor(BaseModel):
table_a = models.ForeignKey(
Table,
on_delete=models.DO_NOTHING,
related_name="tableneighbor_a_set",
)
table_b = models.ForeignKey(
Table,
on_delete=models.DO_NOTHING,
related_name="tableneighbor_b_set",
)

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)

class Meta:
constraints = [
models.UniqueConstraint(
fields=["table_a", "table_b"],
name="table_neighbor_unique_constraint",
),
]

def clean(self) -> None:
errors = {}
if self.table_a.pk > self.table_b.pk:
errors["order"] = "Table primary keys should be ordered"
if errors:
raise ValidationError(errors)
return super().clean()


class BigQueryType(BaseModel):
"""Model definition for BigQueryType."""

Expand Down

0 comments on commit 03d424f

Please sign in to comment.