feat(catalog): preserve and display dataset value scores
Deploy production / deploy (push) Successful in 51s

This commit is contained in:
yuxuanhui
2026-09-09 11:51:59 +08:00
parent f31dda78b4
commit 4debca7dbd
7 changed files with 49 additions and 2 deletions
+2 -1
View File
@@ -37,7 +37,7 @@ class CatalogFilters(Scope):
field_type: str | None = None
coverage_min: float | None = Field(default=None, ge=0, le=1)
sort: Literal[
"id", "name", "category", "field_count", "coverage", "user_count", "alpha_count", "field_type"
"id", "name", "category", "field_count", "coverage", "user_count", "alpha_count", "field_type", "value_score"
] = "name"
direction: Literal["asc", "desc"] = "asc"
limit: int = Field(default=25, ge=1, le=100)
@@ -80,6 +80,7 @@ class EntryOutput(BaseModel):
category: str | None
subcategory: str | None
field_type: str | None
value_score: float | None = None
coverage: float | None
user_count: int | None
alpha_count: int | None
+1
View File
@@ -55,6 +55,7 @@ def normalize(raw, dataset_id):
subcategory=label(raw.get("subcategory")),
field_type=label(raw.get("type")) if dataset_id else None,
coverage=coverage,
value_score=number(raw.get("valueScore")) if not dataset_id else None,
user_count=number(raw.get("userCount"), True),
alpha_count=number(raw.get("alphaCount"), True),
field_count=number(raw.get("fieldCount"), True),
+1
View File
@@ -357,6 +357,7 @@ class CatalogEntry(Base):
subcategory: Mapped[str | None] = mapped_column(String(200))
field_type: Mapped[str | None] = mapped_column(String(100))
coverage: Mapped[float | None] = mapped_column(Float)
value_score: Mapped[float | None] = mapped_column(Float)
user_count: Mapped[int | None] = mapped_column(Integer)
alpha_count: Mapped[int | None] = mapped_column(Integer)
field_count: Mapped[int | None] = mapped_column(Integer)
@@ -0,0 +1,17 @@
"""Preserve the upstream dataset value score; old snapshots remain unknown."""
import sqlalchemy as sa
from alembic import op
revision = "0009"
down_revision = "0008"
branch_labels = None
depends_on = None
def upgrade():
op.add_column("catalog_entries", sa.Column("value_score", sa.Float(), nullable=True))
def downgrade():
op.drop_column("catalog_entries", "value_score")
+2
View File
@@ -37,6 +37,7 @@ def catalog_response(request, fields=None):
"category": {"name": "基本面"},
"subcategory": {"name": "财务报表"},
"fieldCount": 123,
"valueScore": 2.0,
"description": "合成数据,仅用于验收",
},
{
@@ -45,6 +46,7 @@ def catalog_response(request, fields=None):
"category": {"name": "新闻"},
"subcategory": {"name": "情绪"},
"fieldCount": 3,
"valueScore": 0.0,
},
{"id": "TEST_UNKNOWN", "name": "TEST 未分类", "fieldCount": 0},
]
+14
View File
@@ -279,3 +279,17 @@ async def test_dynamic_platform_scopes_and_validation(catalog):
runner.client.disconnect()
assert (await client.get(BASE + "/scopes")).status_code == 409
assert (await search(client))["total"] == 0
async def test_dataset_value_score_survives_sync_and_sorts_null_last(catalog):
client, _, _ = catalog
assert (await sync(catalog))["status"] == "completed"
rows = (await search(client, sort="value_score", direction="desc"))["items"]
assert [(row["id"], row["value_score"]) for row in rows] == [
("TEST_FIN", 2.0), ("TEST_NEWS", 0.0), ("TEST_UNKNOWN", None)
]
rows = (await search(client, sort="value_score", direction="asc"))["items"]
assert [row["value_score"] for row in rows] == [0.0, 2.0, None]
assert (await search(client, "/datasets/TEST_FIN"))["value_score"] == 2.0
assert (await search(client, "/datasets/TEST_NEWS"))["value_score"] == 0.0
assert (await search(client, "/datasets/TEST_UNKNOWN"))["value_score"] is None