Skip to content

Commit

Permalink
refactor: generate time series schema (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas authored Sep 15, 2023
1 parent 714e867 commit b02d68d
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 318 deletions.
23 changes: 9 additions & 14 deletions docs/docs/about/references/keywords/EXTRAPOLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@

## Description
:::caution
Only valid for CSV data of type `MISCELLANEOUS`. For `TIME_SERIES` of [TYPE](TYPE)
`DEFAULT` the keyword is not supported as input, and the functionality is defaulted to `False`..
Only valid for `TIME_SERIES` of [TYPE](TYPE) `MISCELLANEOUS`. For type
`DEFAULT` the keyword is not supported as input, and the functionality is defaulted to `False`.
:::

Defines whether the rates in the source should be set to 0 after the last time step, or equal
to value at last time step after the time interval.
Defines whether the rates in the source should be set to 0 after the last time step (`False`), or equal
to value at last time step after the time interval (`True`).

Not supported when [TYPE](TYPE) is set to `DEFAULT`.

| `TYPE` set to | `EXTRAPOLATION` default |
|-------------------------------------------|--------------------------------------|
| `DEFAULT` | Not supported |
| `MISCELLANEOUS` | No default |

## Format
~~~~~~~~yaml
EXTRAPOLATION: <True/False>
~~~~~~~~

### Requirements
[EXTRAPOLATION](EXTRAPOLATION) has to be specified if
[TYPE](TYPE) is set to `MISCELLANEOUS`.
[EXTRAPOLATION](EXTRAPOLATION) can not be specified if
[TYPE](TYPE) is set to `DEFAULT`.

| `TYPE` set to | `EXTRAPOLATION` default |
|-------------------------------------|-------------------------|
| `DEFAULT` | always `False` |
| `MISCELLANEOUS` | `False` |

## Example
See the [TIME_SERIES](TIME_SERIES.md) `time_series_format`.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from libecalc.input.yaml_types import YamlBase
from libecalc.input.yaml_types.components.yaml_installation import YamlInstallation
from libecalc.input.yaml_types.time_series.yaml_time_series import (
YamlTimeSeriesCollection,
)
from libecalc.input.yaml_types.yaml_placeholder_type import YamlPlaceholderType
from libecalc.input.yaml_types.yaml_schema_helpers import (
replace_placeholder_property_with_legacy_ref,
Expand All @@ -18,11 +21,6 @@ class Config:

@staticmethod
def schema_extra(schema: Dict[str, Any], model: Type["YamlInstallation"]) -> None:
replace_placeholder_property_with_legacy_ref(
schema=schema,
property_key="TIME_SERIES",
property_ref="$SERVER_NAME/api/v1/schema-validation/time-series.json#properties/TIME_SERIES",
)
replace_placeholder_property_with_legacy_ref(
schema=schema,
property_key="FACILITY_INPUTS",
Expand All @@ -39,7 +37,7 @@ def schema_extra(schema: Dict[str, Any], model: Type["YamlInstallation"]) -> Non
property_ref="$SERVER_NAME/api/v1/schema-validation/fuel-types.json#properties/FUEL_TYPES",
)

time_series: YamlPlaceholderType = Field(
time_series: List[YamlTimeSeriesCollection] = Field(
None,
title="TIME_SERIES",
description="Defines the inputs for time dependent variables, or 'reservoir variables'."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from typing import Literal, Union

from libecalc.input.yaml_types import YamlBase
from pydantic import Field


class YamlTimeSeriesCollectionBase(YamlBase):
class Config:
title = "TimeSeries"

name: str = Field(
...,
title="NAME",
description="Name of the time series.\n\n$ECALC_DOCS_KEYWORDS_URL/NAME",
)
file: str = Field(
...,
title="FILE",
description="Specifies the name of a time series input file.\n\n$ECALC_DOCS_KEYWORDS_URL/FILE",
)
type: Literal["DEFAULT", "MISCELLANEOUS"] = Field(
...,
title="TYPE",
description="Defines the type of time series input file.\n\n$ECALC_DOCS_KEYWORDS_URL/TYPE",
)
influence_time_vector: bool = Field(
True,
title="INFLUENCE_TIME_VECTOR",
description="Determines if the time steps in this input source will contribute to the global time vector.\n\n$ECALC_DOCS_KEYWORDS_URL/INFLUENCE_TIME_VECTOR",
)


class YamlDefaultTimeSeriesCollection(YamlTimeSeriesCollectionBase):
class Config:
fields = {
"interpolation_type": {"exclude": True},
}

type: Literal["DEFAULT"] = Field(
...,
title="TYPE",
description="Defines the type of time series input file.\n\n$ECALC_DOCS_KEYWORDS_URL/TYPE",
)

interpolation_type: Literal["RIGHT"] = Field(
"RIGHT",
title="INTERPOLATION_TYPE",
description="Defines how the time series are interpolated between input time steps.\n\n$ECALC_DOCS_KEYWORDS_URL/INTERPOLATION_TYPE",
)


class YamlMiscellaneousTimeSeriesCollection(YamlTimeSeriesCollectionBase):
type: Literal["MISCELLANEOUS"] = Field(
...,
title="TYPE",
description="Defines the type of time series input file.\n\n$ECALC_DOCS_KEYWORDS_URL/TYPE",
)
extrapolation: bool = Field(
False,
title="EXTRAPOLATION",
description="Defines whether the rates in the source should be set to 0 after last time step or constant equal to value at last time step after time interval.\n\n$ECALC_DOCS_KEYWORDS_URL/EXTRAPOLATION",
)
interpolation_type: Literal["LEFT", "RIGHT", "LINEAR"] = Field(
...,
title="INTERPOLATION_TYPE",
description="Defines how the time series are interpolated between input time steps.\n\n$ECALC_DOCS_KEYWORDS_URL/INTERPOLATION_TYPE",
)


YamlTimeSeriesCollection = Union[YamlDefaultTimeSeriesCollection, YamlMiscellaneousTimeSeriesCollection]
Loading

0 comments on commit b02d68d

Please sign in to comment.