Skip to content

Commit

Permalink
fix: forbid extra attributes in TimeSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas committed Sep 21, 2023
1 parent 58693de commit ffc367f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/libecalc/common/utils/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from libecalc.common.units import Unit
from libecalc.dto.types import RateType
from numpy.typing import NDArray
from pydantic import validator
from pydantic import Extra, validator
from pydantic.fields import ModelField
from pydantic.generics import GenericModel
from typing_extensions import Self
Expand Down Expand Up @@ -148,6 +148,7 @@ class Config:
use_enum_values = True
alias_generator = to_camel_case
allow_population_by_field_name = True
extra = Extra.forbid

@validator("values", each_item=True, pre=True)
def convert_none_to_nan(cls, v: float, field: ModelField) -> TimeSeriesValue:
Expand Down
3 changes: 0 additions & 3 deletions src/libecalc/core/consumers/legacy_consumer/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,18 @@ def evaluate(
timesteps=consumer_function_result.time_vector.tolist(),
values=list(consumer_function_result.energy_function_result.suction_pressure),
unit=Unit.BARA,
regularity=regularity,
).reindex(new_time_vector=variables_map.time_vector)

outlet_pressure_time_series = TimeSeriesFloat(
timesteps=consumer_function_result.time_vector.tolist(),
values=list(consumer_function_result.energy_function_result.discharge_pressure),
unit=Unit.BARA,
regularity=regularity,
).reindex(new_time_vector=variables_map.time_vector)

operational_head_time_series = TimeSeriesFloat(
timesteps=consumer_function_result.time_vector.tolist(),
values=list(consumer_function_result.energy_function_result.operational_head),
unit=Unit.POLYTROPIC_HEAD_JOULE_PER_KG,
regularity=regularity,
).reindex(new_time_vector=variables_map.time_vector)

consumer_result = PumpResult(
Expand Down
12 changes: 8 additions & 4 deletions src/libecalc/core/graph_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ def _compute_intensity(
EmissionIntensityResult(
name=emissions[key].name,
timesteps=emissions[key].timesteps,
intensity_sm3=intensity_sm3,
intensity_boe=intensity_sm3.to_unit(Unit.KG_BOE),
intensity_yearly_sm3=intensity_yearly_sm3,
intensity_yearly_boe=intensity_yearly_sm3.to_unit(Unit.KG_BOE),
intensity_sm3=intensity_sm3.dict(exclude={"rate_type": True, "regularity": True}),
intensity_boe=intensity_sm3.to_unit(Unit.KG_BOE).dict(
exclude={"rate_type": True, "regularity": True}
),
intensity_yearly_sm3=intensity_yearly_sm3.dict(exclude={"rate_type": True, "regularity": True}),
intensity_yearly_boe=intensity_yearly_sm3.to_unit(Unit.KG_BOE).dict(
exclude={"rate_type": True, "regularity": True}
),
)
)
return emission_intensities
Expand Down
6 changes: 3 additions & 3 deletions src/tests/libecalc/core/result/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def test_merge_compressor_result(self):
timesteps=timesteps,
values=[1, 2, 3, 4],
unit=Unit.STANDARD_CUBIC_METER_PER_DAY,
typ=RateType.STREAM_DAY,
rate_type=RateType.STREAM_DAY,
regularity=[1, 1, 1, 1],
),
power=TimeSeriesRate(
timesteps=timesteps,
values=[1, 2, 3, 4],
unit=Unit.MEGA_WATT,
typ=RateType.STREAM_DAY,
rate_type=RateType.STREAM_DAY,
regularity=[1, 1, 1, 1],
),
is_valid=TimeSeriesBoolean(
Expand All @@ -43,7 +43,7 @@ def test_merge_compressor_result(self):
timesteps=timesteps,
values=[0.1, 0.2, 0.3, 0.4],
unit=Unit.MEGA_WATT,
typ=RateType.STREAM_DAY,
rate_type=RateType.STREAM_DAY,
regularity=[1, 1, 1, 1],
),
rate_exceeds_maximum=TimeSeriesBoolean(
Expand Down

0 comments on commit ffc367f

Please sign in to comment.