Skip to content

Commit

Permalink
Merge pull request #23 from hydroshare/aggregation-in-schemas
Browse files Browse the repository at this point in the history
add aggregation "in" schemas
  • Loading branch information
sblack-usu authored Nov 10, 2021
2 parents f446187 + 01d3b15 commit 3effbde
Show file tree
Hide file tree
Showing 18 changed files with 941 additions and 126 deletions.
203 changes: 141 additions & 62 deletions hsmodels/schemas/aggregations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime
from datetime import date
from typing import Dict, List, Union

from pydantic import AnyUrl, Field, root_validator, validator
Expand Down Expand Up @@ -38,11 +38,8 @@
)


class BaseAggregationMetadata(BaseMetadata):
class BaseAggregationMetadataIn(BaseMetadata):

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)
title: str = Field(
title="Aggregation title", description="A string containing a descriptive title for the aggregation"
)
Expand Down Expand Up @@ -79,15 +76,14 @@ class BaseAggregationMetadata(BaseMetadata):

_parse_additional_metadata = root_validator(pre=True, allow_reuse=True)(parse_additional_metadata)
_parse_coverages = root_validator(pre=True, allow_reuse=True)(split_coverages)
_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)

_subjects_constraint = validator('subjects', allow_reuse=True)(subjects_constraint)
_language_constraint = validator('language', allow_reuse=True)(language_constraint)
_parse_spatial_coverage = validator("spatial_coverage", allow_reuse=True, pre=True)(parse_spatial_coverage)
_normalize_additional_metadata = root_validator(allow_reuse=True, pre=True)(normalize_additional_metadata)


class GeographicRasterMetadata(BaseAggregationMetadata):
class GeographicRasterMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a geographic raster aggregation
Expand All @@ -101,14 +97,6 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}

type: AggregationType = Field(
const=True,
default=AggregationType.GeographicRasterAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

band_information: BandInformation = Field(
title="Band information",
description="An object containing information about the bands contained in the raster dataset",
Expand All @@ -125,7 +113,26 @@ class Config:
_parse_spatial_reference = validator("spatial_reference", pre=True, allow_reuse=True)(parse_spatial_reference)


class GeographicFeatureMetadata(BaseAggregationMetadata):
class GeographicRasterMetadata(GeographicRasterMetadataIn):

_type = AggregationType.GeographicRasterAggregation

type: AggregationType = Field(
const=True,
default=_type,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class GeographicFeatureMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a geographic feature aggregation
Expand All @@ -139,14 +146,6 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}

type: AggregationType = Field(
const=True,
default=AggregationType.GeographicFeatureAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

field_information: List[FieldInformation] = Field(
default=[],
title="Field information",
Expand All @@ -165,7 +164,24 @@ class Config:
_parse_spatial_reference = validator("spatial_reference", pre=True, allow_reuse=True)(parse_spatial_reference)


class MultidimensionalMetadata(BaseAggregationMetadata):
class GeographicFeatureMetadata(GeographicFeatureMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.GeographicFeatureAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class MultidimensionalMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a multidimensional space-time aggregation
Expand All @@ -179,14 +195,6 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}

type: AggregationType = Field(
const=True,
default=AggregationType.MultidimensionalAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

variables: List[Variable] = Field(
default=[],
title="Variables",
Expand All @@ -203,7 +211,24 @@ class Config:
)


class ReferencedTimeSeriesMetadata(BaseAggregationMetadata):
class MultidimensionalMetadata(MultidimensionalMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.MultidimensionalAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class ReferencedTimeSeriesMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a referenced time series aggregation
Expand All @@ -217,6 +242,9 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}


class ReferencedTimeSeriesMetadata(ReferencedTimeSeriesMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.ReferencedTimeSeriesAggregation,
Expand All @@ -225,8 +253,14 @@ class Config:
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class FileSetMetadata(BaseAggregationMetadata):
class FileSetMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a file set aggregation
Expand All @@ -240,6 +274,9 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}


class FileSetMetadata(FileSetMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.FileSetAggregation,
Expand All @@ -248,8 +285,14 @@ class Config:
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class SingleFileMetadata(BaseAggregationMetadata):
class SingleFileMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a single file aggregation
Expand All @@ -262,6 +305,9 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}


class SingleFileMetadata(SingleFileMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.SingleFileAggregation,
Expand All @@ -270,8 +316,14 @@ class Config:
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

class TimeSeriesMetadata(BaseAggregationMetadata):
_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class TimeSeriesMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a time series aggregation
Expand All @@ -287,6 +339,19 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}

time_series_results: List[TimeSeriesResult] = Field(
default=[],
title="Time series results",
description="A list of time series results contained within the time series aggregation",
)

abstract: str = Field(default=None, title="Abstract", description="A string containing a summary of a aggregation")

_parse_abstract = root_validator(pre=True, allow_reuse=True)(parse_abstract)


class TimeSeriesMetadata(TimeSeriesMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.TimeSeriesAggregation,
Expand All @@ -295,18 +360,14 @@ class Config:
allow_mutation=False,
)

time_series_results: List[TimeSeriesResult] = Field(
default=[],
title="Time series results",
description="A list of time series results contained within the time series aggregation",
url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

abstract: str = Field(default=None, title="Abstract", description="A string containing a summary of a aggregation")

_parse_abstract = root_validator(pre=True, allow_reuse=True)(parse_abstract)
_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class ModelProgramMetadata(BaseAggregationMetadata):
class ModelProgramMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a model program aggregation
"""
Expand All @@ -316,14 +377,6 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}

type: AggregationType = Field(
const=True,
default=AggregationType.ModelProgramAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

version: str = Field(
default=None, title="Version", description="The software version or build number of the model", max_length=255
)
Expand Down Expand Up @@ -378,7 +431,24 @@ class Config:
_parse_file_types = root_validator(pre=True, allow_reuse=True)(parse_file_types)


class ModelInstanceMetadata(BaseAggregationMetadata):
class ModelProgramMetadata(ModelProgramMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.ModelProgramAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)


class ModelInstanceMetadataIn(BaseAggregationMetadataIn):
"""
A class used to represent the metadata associated with a model instance aggregation
"""
Expand All @@ -388,14 +458,6 @@ class Config:

schema_config = {'read_only': ['type', 'url'], 'dictionary_field': ['additional_metadata']}

type: AggregationType = Field(
const=True,
default=AggregationType.ModelInstanceAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

includes_model_output: bool = Field(
title="Includes Model Output",
description="Indicates whether model output files are included in the aggregation",
Expand All @@ -418,3 +480,20 @@ class Config:
title="JSON metadata schema values URL",
description="A URL to a JSON file containing the metadata values conforming to the JSON metadata schema for the related model program",
)


class ModelInstanceMetadata(ModelInstanceMetadataIn):

type: AggregationType = Field(
const=True,
default=AggregationType.ModelInstanceAggregation,
title="Aggregation type",
description="A string expressing the aggregation type from the list of HydroShare aggregation types",
allow_mutation=False,
)

url: AnyUrl = Field(
title="Aggregation URL", description="An object containing the URL of the aggregation", allow_mutation=False
)

_parse_url = root_validator(pre=True, allow_reuse=True)(parse_url)
Loading

0 comments on commit 3effbde

Please sign in to comment.