chap_core.database package¶
Submodules¶
chap_core.database.base_tables module¶
- class chap_core.database.base_tables.DBModel[source]¶
Bases:
SQLModelSimple wrapper that uses camelCase for the field names for the rest-api
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
chap_core.database.database module¶
- class chap_core.database.database.SessionWrapper(local_engine=None, session=None)[source]¶
Bases:
objectThis is a wrapper around data access operations. This class handles cases when putting things in/out of db requires more than just adding/getting a row, e.g. transforming data etc.
- add_configured_model(model_template_id: int, configuration: ModelConfiguration, configuration_name='default', uses_chapkit=False) int[source]¶
- add_dataset(dataset_info: DataSetCreateInfo, orig_dataset: DataSet, polygons)[source]¶
Add a dataset to the database. The dataset is provided as a spatio-temporal dataclass. The polygons should be provided as a geojson feature collection. The dataset_info should contain information about the dataset, such as its name and data sources. The function sets some derived fields in the dataset_info, such as the first and last time period and the covariates. The function returns the id of the newly created dataset.
- add_evaluation_results(evaluation_results: Iterable[DataSet[SamplesWithTruth]], last_train_period: TimePeriod, info: BackTestCreate)[source]¶
- add_model_template(model_template: ModelTemplateDB) int[source]¶
- add_model_template_from_yaml_config(model_template_config: ModelTemplateConfigV2) int[source]¶
Sets the ModelSpecRead a yaml string. Note that the yaml string is what’s defined in a model template’s MLProject file, so source_url will have to be added manually.
- get_configured_model_by_name(configured_model_name: str) ConfiguredModelDB[source]¶
- get_configured_model_with_code(configured_model_id: int) ConfiguredModel[source]¶
- get_configured_models() List[ModelSpecRead][source]¶
- get_model_template(model_template_id: int) ModelTemplateInterface[source]¶
chap_core.database.dataset_tables module¶
- class chap_core.database.dataset_tables.DataSet(*, name: str, dataSources: ~typing.List[~chap_core.database.dataset_tables.DataSource] | None = <factory>, type: str | None = None, id: int | None = None, covariates: ~typing.List[str] = <factory>, firstPeriod: str | None = None, lastPeriod: str | None = None, orgUnits: ~typing.List[str] | None = <factory>, created: ~datetime.datetime | None = None, periodType: str | None = None, geojson: str | None = None)[source]¶
Bases:
DataSetBase- covariates: List['str']¶
- created: datetime | None¶
- data_sources: List[DataSource] | None¶
- first_period: PeriodID | None¶
- geojson: str | None¶
- id: int | None¶
- last_period: PeriodID | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- observations: Mapped[List[Observation]]¶
- org_units: List['str'] | None¶
- period_type: str | None¶
- type: str | None¶
- class chap_core.database.dataset_tables.DataSetBase(*, name: str, dataSources: ~typing.List[~chap_core.database.dataset_tables.DataSource] | None = <factory>, type: str | None = None, id: int | None = None, covariates: ~typing.List[str] = <factory>, firstPeriod: str | None = None, lastPeriod: str | None = None, orgUnits: ~typing.List[str] | None = <factory>, created: ~datetime.datetime | None = None, periodType: str | None = None, geojson: str | None = None)[source]¶
Bases:
DataSetInfo- geojson: str | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.dataset_tables.DataSetCreateInfo(*, name: str, dataSources: ~typing.List[~chap_core.database.dataset_tables.DataSource] | None = <factory>, type: str | None = None)[source]¶
Bases:
DBModel- data_sources: List[DataSource] | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- type: str | None¶
- class chap_core.database.dataset_tables.DataSetInfo(*, name: str, dataSources: ~typing.List[~chap_core.database.dataset_tables.DataSource] | None = <factory>, type: str | None = None, id: int | None = None, covariates: ~typing.List[str] = <factory>, firstPeriod: str | None = None, lastPeriod: str | None = None, orgUnits: ~typing.List[str] | None = <factory>, created: ~datetime.datetime | None = None, periodType: str | None = None)[source]¶
Bases:
DataSetCreateInfo- covariates: List[str]¶
- created: datetime | None¶
- first_period: str | None¶
- id: int | None¶
- last_period: str | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_units: List[str] | None¶
- period_type: str | None¶
- class chap_core.database.dataset_tables.DataSetWithObservations(*, name: str, dataSources: ~typing.List[~chap_core.database.dataset_tables.DataSource] | None = <factory>, type: str | None = None, id: int, covariates: ~typing.List[str] = <factory>, firstPeriod: str | None = None, lastPeriod: str | None = None, orgUnits: ~typing.List[str] | None = <factory>, created: ~datetime.datetime | None, periodType: str | None = None, geojson: str | None = None, observations: ~typing.List[~chap_core.database.dataset_tables.ObservationBase])[source]¶
Bases:
DataSetBase- created: datetime | None¶
- id: int¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- observations: List[ObservationBase]¶
- class chap_core.database.dataset_tables.DataSource(*, covariate: str, dataElementId: str)[source]¶
Bases:
DBModel- covariate: str¶
- data_element_id: str¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.dataset_tables.FeatureCollectionModel(*, type: str = 'FeatureCollection', features: list[FeatureModel])[source]¶
Bases:
FeatureCollectionModel- features: list[FeatureModel]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.dataset_tables.Observation(*, period: str, orgUnit: str, value: float | None, featureName: str | None, id: int | None = None, datasetId: int)[source]¶
Bases:
ObservationBase- dataset_id: int¶
- feature_name: str | None¶
- id: int | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_unit: str¶
- period: PeriodID¶
- value: float | None¶
- class chap_core.database.dataset_tables.ObservationBase(*, period: str, orgUnit: str, value: float | None, featureName: str | None)[source]¶
Bases:
DBModel- feature_name: str | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_unit: str¶
- period: str¶
- value: float | None¶
- class chap_core.database.dataset_tables.PydanticListType(pydantic_model_class)[source]¶
Bases:
TypeDecoratorCustom SQLAlchemy type that automatically serializes/deserializes Pydantic model lists
- cache_ok: bool | None = True¶
Indicate if statements using this
ExternalTypeare “safe to cache”.The default value
Nonewill emit a warning and then not allow caching of a statement which includes this type. Set toFalseto disable statements using this type from being cached at all without a warning. When set toTrue, the object’s class and selected elements from its state will be used as part of the cache key. For example, using aTypeDecorator:class MyType(TypeDecorator): impl = String cache_ok = True def __init__(self, choices): self.choices = tuple(choices) self.internal_only = True
The cache key for the above type would be equivalent to:
>>> MyType(["a", "b", "c"])._static_cache_key (<class '__main__.MyType'>, ('choices', ('a', 'b', 'c')))
The caching scheme will extract attributes from the type that correspond to the names of parameters in the
__init__()method. Above, the “choices” attribute becomes part of the cache key but “internal_only” does not, because there is no parameter named “internal_only”.The requirements for cacheable elements is that they are hashable and also that they indicate the same SQL rendered for expressions using this type every time for a given cache value.
To accommodate for datatypes that refer to unhashable structures such as dictionaries, sets and lists, these objects can be made “cacheable” by assigning hashable structures to the attributes whose names correspond with the names of the arguments. For example, a datatype which accepts a dictionary of lookup values may publish this as a sorted series of tuples. Given a previously un-cacheable type as:
class LookupType(UserDefinedType): """a custom type that accepts a dictionary as a parameter. this is the non-cacheable version, as "self.lookup" is not hashable. """ def __init__(self, lookup): self.lookup = lookup def get_col_spec(self, **kw): return "VARCHAR(255)" def bind_processor(self, dialect): ... # works with "self.lookup" ...
Where “lookup” is a dictionary. The type will not be able to generate a cache key:
>>> type_ = LookupType({"a": 10, "b": 20}) >>> type_._static_cache_key <stdin>:1: SAWarning: UserDefinedType LookupType({'a': 10, 'b': 20}) will not produce a cache key because the ``cache_ok`` flag is not set to True. Set this flag to True if this type object's state is safe to use in a cache key, or False to disable this warning. symbol('no_cache')
If we did set up such a cache key, it wouldn’t be usable. We would get a tuple structure that contains a dictionary inside of it, which cannot itself be used as a key in a “cache dictionary” such as SQLAlchemy’s statement cache, since Python dictionaries aren’t hashable:
>>> # set cache_ok = True >>> type_.cache_ok = True >>> # this is the cache key it would generate >>> key = type_._static_cache_key >>> key (<class '__main__.LookupType'>, ('lookup', {'a': 10, 'b': 20})) >>> # however this key is not hashable, will fail when used with >>> # SQLAlchemy statement cache >>> some_cache = {key: "some sql value"} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'dict'
The type may be made cacheable by assigning a sorted tuple of tuples to the “.lookup” attribute:
class LookupType(UserDefinedType): """a custom type that accepts a dictionary as a parameter. The dictionary is stored both as itself in a private variable, and published in a public variable as a sorted tuple of tuples, which is hashable and will also return the same value for any two equivalent dictionaries. Note it assumes the keys and values of the dictionary are themselves hashable. """ cache_ok = True def __init__(self, lookup): self._lookup = lookup # assume keys/values of "lookup" are hashable; otherwise # they would also need to be converted in some way here self.lookup = tuple((key, lookup[key]) for key in sorted(lookup)) def get_col_spec(self, **kw): return "VARCHAR(255)" def bind_processor(self, dialect): ... # works with "self._lookup" ...
Where above, the cache key for
LookupType({"a": 10, "b": 20})will be:>>> LookupType({"a": 10, "b": 20})._static_cache_key (<class '__main__.LookupType'>, ('lookup', (('a', 10), ('b', 20))))
Added in version 1.4.14: - added the
cache_okflag to allow some configurability of caching forTypeDecoratorclasses.Added in version 1.4.28: - added the
ExternalTypemixin which generalizes thecache_okflag to both theTypeDecoratorandUserDefinedTypeclasses.See also
sql_caching
- impl¶
alias of
JSON
chap_core.database.datasets_seed module¶
chap_core.database.debug module¶
- class chap_core.database.debug.DebugEntry(*, id: int | None = None, timestamp: float)[source]¶
Bases:
DBModel- id: int | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- timestamp: float¶
chap_core.database.feature_tables module¶
- class chap_core.database.feature_tables.FeatureSource(*, name: str, displayName: str, featureType: str, provider: str, supportedPeriodTypes: ~typing.List[~chap_core.model_spec.PeriodType] = <factory>)[source]¶
Bases:
DBModel- display_name: str¶
- feature_type: str¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- provider: str¶
- supported_period_types: List[PeriodType]¶
- class chap_core.database.feature_tables.FeatureType(*, displayName: str, description: str, name: str = <class 'str'>)[source]¶
Bases:
FeatureTypeBase- description: str¶
- display_name: str¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- class chap_core.database.feature_tables.FeatureTypeBase(*, displayName: str, description: str)[source]¶
Bases:
DBModel- description: str¶
- display_name: str¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.feature_tables.FeatureTypeRead(*, displayName: str, description: str, name: str)[source]¶
Bases:
FeatureTypeBase- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- class chap_core.database.feature_tables.ModelFeatureLink(*, modelId: int | None = None, featureType: str | None = None)[source]¶
Bases:
DBModel- feature_type: str | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_id: int | None¶
chap_core.database.model_spec_tables module¶
- class chap_core.database.model_spec_tables.ModelSpec(*, displayName: str = 'No Display Name yet', description: str = 'No Description yet', authorNote: str = 'No Author note yet', authorAssessedStatus: AuthorAssessedStatus = AuthorAssessedStatus.red, author: str = 'Unknown Author', organization: str | None = None, organizationLogoUrl: str | None = None, contactEmail: str | None = None, citationInfo: str | None = None, name: str, sourceUrl: str | None = None, supportedPeriodType: PeriodType = PeriodType.any, id: int | None = None, targetName: str, configuration: dict | None)[source]¶
Bases:
ModelSpecBaseModelSpec is the DB class for a Configured Model. It is configured through the “configuration” field which is JSON
- author: str¶
- author_assessed_status: AuthorAssessedStatus¶
- author_note: str¶
- citation_info: str | None¶
- configuration: dict | None¶
- contact_email: str | None¶
- covariates: Mapped[List[FeatureType]]¶
- description: str¶
- display_name: str¶
- id: int | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- organization: str | None¶
- organization_logo_url: str | None¶
- source_url: str | None¶
- supported_period_type: PeriodType¶
- target: Mapped[FeatureType]¶
- target_name: str¶
- class chap_core.database.model_spec_tables.ModelSpecBase(*, displayName: str = 'No Display Name yet', description: str = 'No Description yet', authorNote: str = 'No Author note yet', authorAssessedStatus: AuthorAssessedStatus = AuthorAssessedStatus.red, author: str = 'Unknown Author', organization: str | None = None, organizationLogoUrl: str | None = None, contactEmail: str | None = None, citationInfo: str | None = None, name: str, sourceUrl: str | None = None, supportedPeriodType: PeriodType = PeriodType.any)[source]¶
Bases:
ModelTemplateMetaData,DBModelUse inheritance here so that it’s flat in the database.
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- source_url: str | None¶
- supported_period_type: PeriodType¶
- class chap_core.database.model_spec_tables.ModelSpecRead(*, displayName: str = 'No Display Name yet', description: str = 'No Description yet', authorNote: str = 'No Author note yet', authorAssessedStatus: AuthorAssessedStatus = AuthorAssessedStatus.red, author: str = 'Unknown Author', organization: str | None = None, organizationLogoUrl: str | None = None, contactEmail: str | None = None, citationInfo: str | None = None, name: str, sourceUrl: str | None = None, supportedPeriodType: PeriodType = PeriodType.any, id: int, covariates: List[FeatureType], target: FeatureType, archived: bool = False)[source]¶
Bases:
ModelSpecBase- archived: bool¶
- covariates: List[FeatureType]¶
- id: int¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- target: FeatureType¶
- chap_core.database.model_spec_tables.get_available_models(base_covariates) List[ModelSpec][source]¶
Returns a list of models that are available in chap
chap_core.database.model_template_seed module¶
- chap_core.database.model_template_seed.add_configured_model(model_template_id, configuration: ModelConfiguration, configuration_name: str, session_wrapper: SessionWrapper, uses_chapkit: bool = False) int[source]¶
Add a configured model to the database.
Parameters¶
- model_template_idint
The ID of the model template.
- configurationdict
The configuration for the model.
- session_wrapperSessionWrapper
The session wrapper for database operations.
Returns¶
- int
The ID of the added model.
- chap_core.database.model_template_seed.add_model_template(model_template: ModelTemplateDB, session_wrapper: SessionWrapper) int[source]¶
- chap_core.database.model_template_seed.add_model_template_from_url(url: str, session_wrapper: SessionWrapper, version: str) int[source]¶
chap_core.database.model_templates_and_config_tables module¶
- class chap_core.database.model_templates_and_config_tables.AuthorAssessedStatus(*values)[source]¶
Bases:
Enum- gray = 'gray'¶
- green = 'green'¶
- orange = 'orange'¶
- red = 'red'¶
- yellow = 'yellow'¶
- class chap_core.database.model_templates_and_config_tables.ConfiguredModelDB(*, userOptionValues: dict | None = <factory>, additionalContinuousCovariates: ~typing.List[str] = <factory>, name: str, id: int | None = None, modelTemplateId: int, archived: bool = False, usesChapkit: bool = False)[source]¶
Bases:
ModelConfiguration,DBModel- additional_continuous_covariates: List[str]¶
- archived: bool¶
- id: int | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_template: Mapped[ModelTemplateDB]¶
- model_template_id: int¶
- name: str¶
- user_option_values: dict | None¶
- uses_chapkit: bool¶
- class chap_core.database.model_templates_and_config_tables.ModelConfiguration(*, user_option_values: dict | None = <factory>, additional_continuous_covariates: ~typing.List[str] = <factory>)[source]¶
Bases:
SQLModel- additional_continuous_covariates: List[str]¶
- model_config: ClassVar[ConfigDict] = {'from_attributes': True, 'registry': PydanticUndefined}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- user_option_values: dict | None¶
- class chap_core.database.model_templates_and_config_tables.ModelTemplateDB(*, supportedPeriodType: ~chap_core.model_spec.PeriodType = PeriodType.any, userOptions: dict | None = <factory>, hpoSearchSpace: dict | None = None, requiredCovariates: ~typing.List[str] = <factory>, target: str = 'disease_cases', allowFreeAdditionalContinuousCovariates: bool = False, displayName: str = 'No Display Name yet', description: str = 'No Description yet', authorNote: str = 'No Author note yet', authorAssessedStatus: ~chap_core.database.model_templates_and_config_tables.AuthorAssessedStatus = AuthorAssessedStatus.red, author: str = 'Unknown Author', organization: str | None = None, organizationLogoUrl: str | None = None, contactEmail: str | None = None, citationInfo: str | None = None, name: str, id: int | None = None, sourceUrl: str | None = None, version: str | None = None)[source]¶
Bases:
DBModel,ModelTemplateMetaData,ModelTemplateInformationJust a mixin here to get the model info flat in the database.
- allow_free_additional_continuous_covariates: bool¶
- author: str¶
- author_assessed_status: AuthorAssessedStatus¶
- author_note: str¶
- citation_info: str | None¶
- configured_models: Mapped[List[ConfiguredModelDB]]¶
- contact_email: str | None¶
- description: str¶
- display_name: str¶
- hpo_search_space: dict | None¶
- id: int | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str¶
- organization: str | None¶
- organization_logo_url: str | None¶
- required_covariates: List[str]¶
- source_url: str | None¶
- supported_period_type: PeriodType¶
- target: str¶
- user_options: dict | None¶
- version: str | None¶
- class chap_core.database.model_templates_and_config_tables.ModelTemplateInformation(*, supported_period_type: ~chap_core.model_spec.PeriodType = PeriodType.any, user_options: dict | None = <factory>, hpo_search_space: dict | None = None, required_covariates: ~typing.List[str] = <factory>, target: str = 'disease_cases', allow_free_additional_continuous_covariates: bool = False)[source]¶
Bases:
SQLModel- allow_free_additional_continuous_covariates: bool¶
- hpo_search_space: dict | None¶
- model_config: ClassVar[ConfigDict] = {'from_attributes': True, 'registry': PydanticUndefined}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- required_covariates: List[str]¶
- supported_period_type: PeriodType¶
- target: str¶
- user_options: dict | None¶
- class chap_core.database.model_templates_and_config_tables.ModelTemplateMetaData(*, display_name: str = 'No Display Name yet', description: str = 'No Description yet', author_note: str = 'No Author note yet', author_assessed_status: AuthorAssessedStatus = AuthorAssessedStatus.red, author: str = 'Unknown Author', organization: str | None = None, organization_logo_url: str | None = None, contact_email: str | None = None, citation_info: str | None = None)[source]¶
Bases:
SQLModel- author: str¶
- author_assessed_status: AuthorAssessedStatus¶
- author_note: str¶
- citation_info: str | None¶
- contact_email: str | None¶
- description: str¶
- display_name: str¶
- model_config: ClassVar[ConfigDict] = {'from_attributes': True, 'registry': PydanticUndefined}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- organization: str | None¶
- organization_logo_url: str | None¶
chap_core.database.tables module¶
todo: comment this file, make it clear which classes are central and being used
- class chap_core.database.tables.BackTest(*, datasetId: int, modelId: str, name: str | None = None, created: ~datetime.datetime | None = None, modelTemplateVersion: str | None = None, id: int | None = None, orgUnits: ~typing.List[str] = <factory>, splitPeriods: ~typing.List[str] = <factory>, aggregateMetrics: ~typing.Dict[str, float] = <factory>, modelDbId: int)[source]¶
Bases:
_BackTestRead- aggregate_metrics: Dict[str, float]¶
- configured_model: Mapped[ConfiguredModelDB | None]¶
- created: datetime.datetime | None¶
- dataset_id: int¶
- forecasts: Mapped[List[BackTestForecast]]¶
- id: int | None¶
- metrics: Mapped[List[BackTestMetric]]¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_db_id: int¶
- model_id: str¶
- model_template_version: str | None¶
- name: str | None¶
- org_units: List[str]¶
- split_periods: List[PeriodID]¶
- class chap_core.database.tables.BackTestBase(*, datasetId: int, modelId: str, name: str | None = None, created: datetime | None = None, modelTemplateVersion: str | None = None)[source]¶
Bases:
DBModel- created: datetime | None¶
- dataset_id: int¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_id: str¶
- model_template_version: str | None¶
- name: str | None¶
- class chap_core.database.tables.BackTestForecast(*, period: str, orgUnit: str, values: ~typing.List[float] = <factory>, id: int | None = None, backtestId: int, lastTrainPeriod: str, lastSeenPeriod: str)[source]¶
Bases:
ForecastBase- backtest_id: int¶
- id: int | None¶
- last_seen_period: str¶
- last_train_period: str¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_unit: str¶
- period: PeriodID¶
- values: List[float]¶
- class chap_core.database.tables.BackTestMetric(*, id: int | None = None, backtestId: int, metricId: str, period: str, orgUnit: str, lastTrainPeriod: str, lastSeenPeriod: str, value: float)[source]¶
Bases:
DBModelThis class has been used when computing metrics per location/time_point/split_point adhoc in database.py. This id depcrecated and not used in the new metric system. Can be removed when no references left to this class.
- backtest_id: int¶
- id: int | None¶
- last_seen_period: str¶
- last_train_period: str¶
- metric_id: str¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_unit: str¶
- period: str¶
- value: float¶
- class chap_core.database.tables.BackTestRead(*, datasetId: int, modelId: str, name: str | None = None, created: ~datetime.datetime | None = None, modelTemplateVersion: str | None = None, id: int, orgUnits: ~typing.List[str] = <factory>, splitPeriods: ~typing.List[str] = <factory>, dataset: ~chap_core.database.tables.DataSetMeta, aggregateMetrics: ~typing.Dict[str, float], configuredModel: ~chap_core.database.tables.ConfiguredModelRead | None)[source]¶
Bases:
_BackTestRead- aggregate_metrics: Dict[str, float]¶
- configured_model: ConfiguredModelRead | None¶
- dataset: DataSetMeta¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.tables.ConfiguredModelRead(*, userOptionValues: dict | None = <factory>, additionalContinuousCovariates: ~typing.List[str] = <factory>, name: str, id: int, modelTemplate: ~chap_core.database.model_templates_and_config_tables.ModelTemplateDB)[source]¶
Bases:
ModelConfiguration,DBModel- id: int¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_template: ModelTemplateDB¶
- name: str¶
- class chap_core.database.tables.DataSetMeta(*, name: str, dataSources: ~typing.List[~chap_core.database.dataset_tables.DataSource] | None = <factory>, type: str | None = None, id: int, covariates: ~typing.List[str] = <factory>, firstPeriod: str | None = None, lastPeriod: str | None = None, orgUnits: ~typing.List[str] | None = <factory>, created: ~datetime.datetime | None = None, periodType: str | None = None)[source]¶
Bases:
DataSetInfo- id: int¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.tables.ForecastBase(*, period: str, orgUnit: str, values: ~typing.List[float] = <factory>)[source]¶
Bases:
DBModel- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_unit: str¶
- period: str¶
- values: List[float]¶
- class chap_core.database.tables.ForecastRead(*, period: str, orgUnit: str, values: ~typing.List[float] = <factory>)[source]¶
Bases:
ForecastBase- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- chap_core.database.tables.OldBackTestRead¶
alias of
_BackTestRead
- class chap_core.database.tables.Prediction(*, datasetId: int, modelId: str, nPeriods: int, name: str, created: ~datetime.datetime, metaData: dict = <factory>, orgUnits: ~typing.List[str] = <factory>, id: int | None = None, modelDbId: int)[source]¶
Bases:
PredictionBase- configured_model: Mapped[ConfiguredModelDB | None]¶
- created: datetime.datetime¶
- dataset_id: int¶
- forecasts: Mapped[List[PredictionSamplesEntry]]¶
- id: int | None¶
- meta_data: dict¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_db_id: int¶
- model_id: str¶
- n_periods: int¶
- name: str¶
- org_units: List[str]¶
- class chap_core.database.tables.PredictionBase(*, datasetId: int, modelId: str, nPeriods: int, name: str, created: ~datetime.datetime, metaData: dict = <factory>, orgUnits: ~typing.List[str] = <factory>)[source]¶
Bases:
DBModel- created: datetime¶
- dataset_id: int¶
- meta_data: dict¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_id: str¶
- n_periods: int¶
- name: str¶
- org_units: List[str]¶
- class chap_core.database.tables.PredictionInfo(*, datasetId: int, modelId: str, nPeriods: int, name: str, created: ~datetime.datetime, metaData: dict = <factory>, orgUnits: ~typing.List[str] = <factory>, id: int, configuredModel: ~chap_core.database.model_templates_and_config_tables.ConfiguredModelDB | None, dataset: ~chap_core.database.tables.DataSetMeta)[source]¶
Bases:
PredictionBase- configured_model: ConfiguredModelDB | None¶
- dataset: DataSetMeta¶
- id: int¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.tables.PredictionRead(*, datasetId: int, modelId: str, nPeriods: int, name: str, created: ~datetime.datetime, metaData: dict = <factory>, orgUnits: ~typing.List[str] = <factory>, id: int, configuredModel: ~chap_core.database.model_templates_and_config_tables.ConfiguredModelDB | None, dataset: ~chap_core.database.tables.DataSetMeta, forecasts: ~typing.List[~chap_core.database.tables.ForecastRead])[source]¶
Bases:
PredictionInfo- forecasts: List[ForecastRead]¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'registry': PydanticUndefined, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class chap_core.database.tables.PredictionSamplesEntry(*, period: str, orgUnit: str, values: ~typing.List[float] = <factory>, id: int | None = None, predictionId: int)[source]¶
Bases:
ForecastBase- id: int | None¶
- model_config: ClassVar[ConfigDict] = {'alias_generator': <function to_camel>, 'from_attributes': True, 'populate_by_name': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- org_unit: str¶
- period: PeriodID¶
- prediction: Mapped[Prediction]¶
- prediction_id: int¶
- values: List[float]¶