-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: discovery module with config model
- Loading branch information
1 parent
7313a25
commit 08a878d
Showing
9 changed files
with
137 additions
and
1 deletion.
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
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,4 @@ | ||
from . import helpers | ||
from . import models | ||
|
||
__all__ = ["helpers", "models"] |
Empty file.
Empty file.
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,22 @@ | ||
from pydantic import BaseModel | ||
|
||
from .fields import DateFieldDefinition, NumberFieldDefinition, StringFieldDefinition | ||
from .overview import OverviewSection | ||
from .search import SearchSection | ||
|
||
__all__ = [ | ||
"DiscoveryConfigRules", | ||
"DiscoveryConfig", | ||
] | ||
|
||
|
||
class DiscoveryConfigRules(BaseModel): | ||
count_threshold: int | ||
max_query_parameters: int | ||
|
||
|
||
class DiscoveryConfig(BaseModel): | ||
overview: list[OverviewSection] | ||
search: list[SearchSection] | ||
fields: dict[str, DateFieldDefinition | NumberFieldDefinition | StringFieldDefinition] | ||
rules: DiscoveryConfigRules | ||
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,69 @@ | ||
from pydantic import AliasChoices, BaseModel, Field | ||
from typing import Literal | ||
|
||
__all__ = [ | ||
"BaseFieldDefinition", | ||
# string | ||
"StringFieldConfig", | ||
"StringFieldDefinition", | ||
# number | ||
"BaseNumberFieldConfig", | ||
"ManualBinsNumberFieldConfig", | ||
"AutoBinsNumberFieldConfig", | ||
"NumberFieldDefinition", | ||
# date | ||
"DateFieldConfig", | ||
"DateFieldDefinition", | ||
] | ||
|
||
|
||
class BaseFieldDefinition(BaseModel): | ||
mapping: str | ||
title: str # TODO: make optional and pull from Bento schema if not set | ||
description: str # TODO: make optional and pull from Bento schema if not set | ||
datatype: Literal["string", "number", "date"] = Field(validation_alias=AliasChoices("data_type", "datatype")) | ||
# --- The below fields are currently valid, but need to be reworked for new search --------------------------------- | ||
mapping_for_search_filter: str | None = None | ||
group_by: str | None = None | ||
group_by_value: str | None = None | ||
value_mapping: str | None = None | ||
# ------------------------------------------------------------------------------------------------------------------ | ||
|
||
|
||
class StringFieldConfig(BaseModel): | ||
enum: list[str] | None | ||
|
||
|
||
class StringFieldDefinition(BaseFieldDefinition): | ||
datatype: Literal["string"] | ||
config: StringFieldConfig | ||
|
||
|
||
class BaseNumberFieldConfig(BaseModel): | ||
units: str | ||
|
||
|
||
class ManualBinsNumberFieldConfig(BaseNumberFieldConfig): | ||
bins: list[int] | ||
|
||
|
||
class AutoBinsNumberFieldConfig(BaseNumberFieldConfig): | ||
bin_size: int | ||
taper_left: int | ||
taper_right: int | ||
minimum: int | ||
maximum: int | ||
|
||
|
||
class NumberFieldDefinition(BaseFieldDefinition): | ||
datatype: Literal["number"] | ||
config: ManualBinsNumberFieldConfig | AutoBinsNumberFieldConfig | ||
|
||
|
||
class DateFieldConfig(BaseModel): | ||
bin_by: str # TODO | ||
|
||
|
||
class DateFieldDefinition(BaseFieldDefinition): | ||
datatype: Literal["date"] | ||
config: DateFieldConfig | ||
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,17 @@ | ||
from pydantic import BaseModel | ||
from typing import Literal | ||
|
||
__all__ = [ | ||
"OverviewChart", | ||
"OverviewSection", | ||
] | ||
|
||
|
||
class OverviewChart(BaseModel): | ||
field: str | ||
chart_type: Literal["bar", "choropleth", "histogram", "pie"] | ||
|
||
|
||
class OverviewSection(BaseModel): | ||
section_title: str | ||
charts: list[OverviewChart] | ||
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,8 @@ | ||
from pydantic import BaseModel | ||
|
||
__all__ = ["SearchSection"] | ||
|
||
|
||
class SearchSection(BaseModel): | ||
section_title: str | ||
fields: list[str] | ||