-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from bluesky/337-add-basemodel-support-1
Convert from `BaseModel` to `jsonschema` + `TypedDict`
- Loading branch information
Showing
43 changed files
with
2,564 additions
and
1,494 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
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,61 @@ | ||
from typing import Tuple, Type, Union | ||
|
||
from event_model.basemodels.datum import Datum | ||
from event_model.basemodels.datum_page import DatumPage | ||
from event_model.basemodels.event import Event | ||
from event_model.basemodels.event_descriptor import ( | ||
Dtype, | ||
EventDescriptor, | ||
Limits, | ||
LimitsRange, | ||
) | ||
from event_model.basemodels.event_page import EventPage | ||
from event_model.basemodels.resource import Resource | ||
from event_model.basemodels.run_start import RunStart | ||
from event_model.basemodels.run_stop import RunStop | ||
from event_model.basemodels.stream_datum import StreamDatum | ||
from event_model.basemodels.stream_resource import StreamResource | ||
|
||
DocumentType = Union[ | ||
Type[Datum], | ||
Type[DatumPage], | ||
Type[Event], | ||
Type[EventDescriptor], | ||
Type[EventPage], | ||
Type[Resource], | ||
Type[RunStart], | ||
Type[RunStop], | ||
Type[StreamDatum], | ||
Type[StreamResource], | ||
] | ||
|
||
ALL_BASEMODELS: Tuple[DocumentType, ...] = ( | ||
Datum, | ||
DatumPage, | ||
Event, | ||
EventDescriptor, | ||
EventPage, | ||
Resource, | ||
RunStart, | ||
RunStop, | ||
StreamDatum, | ||
StreamResource, | ||
) | ||
|
||
|
||
__all__ = [ | ||
"Datum", | ||
"DatumPage", | ||
"Dtype", | ||
"Event", | ||
"EventDescriptor", | ||
"EventPage", | ||
"Limits", | ||
"LimitsRange", | ||
"Resource", | ||
"RunStart", | ||
"RunStop", | ||
"StreamDatum", | ||
"StreamResource", | ||
"DocumentType", | ||
] |
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,32 @@ | ||
from typing import Any, Dict | ||
|
||
from pydantic import ( | ||
BaseModel, | ||
ConfigDict, | ||
Field, | ||
) | ||
from typing_extensions import Annotated | ||
|
||
|
||
class Datum(BaseModel): | ||
"""Document to reference a quanta of externally-stored data""" | ||
|
||
model_config = ConfigDict(extra="forbid") | ||
|
||
datum_id: Annotated[ | ||
str, | ||
Field( | ||
description="Globally unique identifier for this Datum (akin to 'uid' " | ||
"for other Document types), typically formatted as '<resource>/<integer>'" | ||
), | ||
] | ||
datum_kwargs: Annotated[ | ||
Dict[str, Any], | ||
Field( | ||
description="Arguments to pass to the Handler to " | ||
"retrieve one quanta of data", | ||
), | ||
] | ||
resource: Annotated[ | ||
str, Field(description="The UID of the Resource to which this Datum belongs") | ||
] |
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,35 @@ | ||
from typing import Any, Dict, List | ||
|
||
from pydantic import BaseModel, ConfigDict, Field, RootModel | ||
from typing_extensions import Annotated | ||
|
||
|
||
class DataFrameForDatumPage(RootModel): | ||
root: List[str] = Field(alias="Dataframe") | ||
|
||
|
||
class DatumPage(BaseModel): | ||
"""Page of documents to reference a quanta of externally-stored data""" | ||
|
||
model_config = ConfigDict(extra="forbid") | ||
|
||
datum_id: Annotated[ | ||
DataFrameForDatumPage, | ||
Field( | ||
description="Array unique identifiers for each Datum (akin to 'uid' for " | ||
"other Document types), typically formatted as '<resource>/<integer>'" | ||
), | ||
] | ||
datum_kwargs: Annotated[ | ||
Dict[str, List[Any]], | ||
Field( | ||
description="Array of arguments to pass to the Handler to " | ||
"retrieve one quanta of data" | ||
), | ||
] | ||
resource: Annotated[ | ||
str, | ||
Field( | ||
description="The UID of the Resource to which all Datums in the page belong" | ||
), | ||
] |
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,48 @@ | ||
from typing import Any, Dict, Union | ||
|
||
from pydantic import BaseModel, ConfigDict, Field | ||
from typing_extensions import Annotated | ||
|
||
|
||
class PartialEvent(BaseModel): | ||
model_config = ConfigDict(extra="forbid") | ||
|
||
data: Annotated[Dict[str, Any], Field(description="The actual measurement data")] | ||
filled: Annotated[ | ||
Dict[str, Union[bool, str]], | ||
Field( | ||
default_factory=dict, | ||
description="Mapping each of the keys of externally-stored data to the " | ||
"boolean False, indicating that the data has not been loaded, or to " | ||
"foreign keys (moved here from 'data' when the data was loaded)", | ||
), | ||
] | ||
time: Annotated[ | ||
float, | ||
Field( | ||
description="The event time. This maybe different than the timestamps on " | ||
"each of the data entries.", | ||
), | ||
] | ||
timestamps: Annotated[ | ||
Dict[str, Any], | ||
Field(description="The timestamps of the individual measurement data"), | ||
] | ||
|
||
|
||
class Event(PartialEvent): | ||
"""Document to record a quanta of collected data""" | ||
|
||
model_config = ConfigDict(extra="forbid") | ||
|
||
descriptor: Annotated[ | ||
str, Field(description="UID of the EventDescriptor to which this Event belongs") | ||
] | ||
seq_num: Annotated[ | ||
int, | ||
Field( | ||
description="Sequence number to identify the location of this Event in the " | ||
"Event stream", | ||
), | ||
] | ||
uid: Annotated[str, Field(description="Globally unique identifier for this Event")] |
Oops, something went wrong.