From 21deeb7a70cd64f47db87494314a0119ee4598d5 Mon Sep 17 00:00:00 2001 From: Frode Helgetun Krogh <70878501+frodehk@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:09:32 +0200 Subject: [PATCH] chore: add rate type to pump model result (#209) * chore: add rate type to pump model result --- src/libecalc/core/graph_result.py | 54 +++++ src/libecalc/dto/result/results.py | 10 +- .../test_app/test_json_true/test_v3.json | 195 +++++++++++++----- .../test_full_json_v3.json | 195 +++++++++++++----- 4 files changed, 337 insertions(+), 117 deletions(-) diff --git a/src/libecalc/core/graph_result.py b/src/libecalc/core/graph_result.py index bdab7c1ac2..8602547e48 100644 --- a/src/libecalc/core/graph_result.py +++ b/src/libecalc/core/graph_result.py @@ -30,6 +30,7 @@ CompressorModelResult, CompressorModelStageResult, CompressorStreamConditionResult, + PumpModelResult, TurbineModelResult, ) from libecalc.dto.types import RateType @@ -649,6 +650,59 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: ) ] ) + elif consumer_node_info.component_type in [ComponentType.PUMP, ComponentType.PUMP_SYSTEM]: + component = self.graph.get_component(consumer_id) + for model in consumer_result.models: + models.extend( + [ + PumpModelResult( + parent=consumer_id, + name=model.name, + componentType=model.component_type, + component_level=ComponentLevel.MODEL, + energy_usage=model.energy_usage, + is_valid=model.is_valid, + energy_usage_cumulative=model.energy_usage.to_volumes().cumulative(), + timesteps=model.timesteps, + power_cumulative=( + model.power.to_volumes().to_unit(Unit.GIGA_WATT_HOURS).cumulative() + if model.power is not None + else None + ), + power=model.power, + inlet_liquid_rate_m3_per_day=TimeSeriesRate( + timesteps=model.timesteps, + values=model.inlet_liquid_rate_m3_per_day + if model.inlet_liquid_rate_m3_per_day is not None + else [math.nan] * len(model.timesteps), + unit=Unit.STANDARD_CUBIC_METER_PER_DAY, + rate_type=RateType.STREAM_DAY, + ), + inlet_pressure_bar=TimeSeriesFloat( + timesteps=model.timesteps, + values=model.inlet_pressure_bar + if model.inlet_pressure_bar is not None + else [math.nan] * len(model.timesteps), + unit=Unit.BARA, + ), + outlet_pressure_bar=TimeSeriesFloat( + timesteps=model.timesteps, + values=model.outlet_pressure_bar + if model.outlet_pressure_bar is not None + else [math.nan] * len(model.timesteps), + unit=Unit.BARA, + ), + operational_head=TimeSeriesFloat( + timesteps=model.timesteps, + values=model.operational_head + if model.operational_head is not None + else [math.nan] * len(model.timesteps), + unit=Unit.POLYTROPIC_HEAD_JOULE_PER_KG, + ), + ) + ] + ) + else: models.extend( [ diff --git a/src/libecalc/dto/result/results.py b/src/libecalc/dto/result/results.py index cdd22e63cd..158b33131d 100644 --- a/src/libecalc/dto/result/results.py +++ b/src/libecalc/dto/result/results.py @@ -24,7 +24,6 @@ from libecalc.dto.result.emission import EmissionIntensityResult, EmissionResult from libecalc.dto.result.simple import SimpleComponentResult, SimpleResultData from libecalc.dto.result.tabular_time_series import TabularTimeSeries -from libecalc.dto.result.types import opt_float from pydantic import Field, validator from typing_extensions import Annotated @@ -137,10 +136,11 @@ class PumpModelResult(ConsumerModelResultBase): """The Pump result component.""" componentType: Literal[ComponentType.PUMP] - inlet_liquid_rate_m3_per_day: Optional[List[opt_float]] - inlet_pressure_bar: Optional[List[opt_float]] - outlet_pressure_bar: Optional[List[opt_float]] - operational_head: Optional[List[float]] + inlet_liquid_rate_m3_per_day: Optional[TimeSeriesRate] + inlet_pressure_bar: Optional[TimeSeriesFloat] + outlet_pressure_bar: Optional[TimeSeriesFloat] + operational_head: Optional[TimeSeriesFloat] + is_valid: TimeSeriesBoolean class TurbineModelResult(EcalcResultBaseModel): diff --git a/src/tests/ecalc_cli/snapshots/test_app/test_json_true/test_v3.json b/src/tests/ecalc_cli/snapshots/test_app/test_json_true/test_v3.json index 2ea4665bcc..ac66e164b6 100644 --- a/src/tests/ecalc_cli/snapshots/test_app/test_json_true/test_v3.json +++ b/src/tests/ecalc_cli/snapshots/test_app/test_json_true/test_v3.json @@ -3607,34 +3607,83 @@ 13510.67 ] }, - "inlet_liquid_rate_m3_per_day": [ - 18000.0, - 19000.0, - 15000.0, - 16000.0, - 14000.0, - 15000.0, - 18000.0, - 15000.0, - 12000.0, - 14000.0, - 16000.0, - 14000.0 - ], - "inlet_pressure_bar": [ - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0 - ], + "inlet_liquid_rate_m3_per_day": { + "rate_type": "STREAM_DAY", + "regularity": [ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0 + ], + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "Sm3/d", + "values": [ + 18000.0, + 19000.0, + 15000.0, + 16000.0, + 14000.0, + 15000.0, + 18000.0, + 15000.0, + 12000.0, + 14000.0, + 16000.0, + 14000.0 + ] + }, + "inlet_pressure_bar": { + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "bara", + "values": [ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ] + }, "is_valid": { "timesteps": [ "2020-01-01 00:00:00", @@ -3667,34 +3716,68 @@ ] }, "name": "Produced water reinjection pump", - "operational_head": [ - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88 - ], - "outlet_pressure_bar": [ - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0 - ], + "operational_head": { + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "J/kg", + "values": [ + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88 + ] + }, + "outlet_pressure_bar": { + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "bara", + "values": [ + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0 + ] + }, "parent": "e1c82c648513148fb53d7b9dcff878ca", "power": { "rate_type": "STREAM_DAY", diff --git a/src/tests/ecalc_cli/snapshots/test_app/test_json_true_detailed_output/test_full_json_v3.json b/src/tests/ecalc_cli/snapshots/test_app/test_json_true_detailed_output/test_full_json_v3.json index 2ea4665bcc..ac66e164b6 100644 --- a/src/tests/ecalc_cli/snapshots/test_app/test_json_true_detailed_output/test_full_json_v3.json +++ b/src/tests/ecalc_cli/snapshots/test_app/test_json_true_detailed_output/test_full_json_v3.json @@ -3607,34 +3607,83 @@ 13510.67 ] }, - "inlet_liquid_rate_m3_per_day": [ - 18000.0, - 19000.0, - 15000.0, - 16000.0, - 14000.0, - 15000.0, - 18000.0, - 15000.0, - 12000.0, - 14000.0, - 16000.0, - 14000.0 - ], - "inlet_pressure_bar": [ - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0 - ], + "inlet_liquid_rate_m3_per_day": { + "rate_type": "STREAM_DAY", + "regularity": [ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0 + ], + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "Sm3/d", + "values": [ + 18000.0, + 19000.0, + 15000.0, + 16000.0, + 14000.0, + 15000.0, + 18000.0, + 15000.0, + 12000.0, + 14000.0, + 16000.0, + 14000.0 + ] + }, + "inlet_pressure_bar": { + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "bara", + "values": [ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ] + }, "is_valid": { "timesteps": [ "2020-01-01 00:00:00", @@ -3667,34 +3716,68 @@ ] }, "name": "Produced water reinjection pump", - "operational_head": [ - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88, - 18811.88 - ], - "outlet_pressure_bar": [ - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0, - 200.0 - ], + "operational_head": { + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "J/kg", + "values": [ + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88, + 18811.88 + ] + }, + "outlet_pressure_bar": { + "timesteps": [ + "2020-01-01 00:00:00", + "2021-01-01 00:00:00", + "2022-01-01 00:00:00", + "2023-01-01 00:00:00", + "2024-01-01 00:00:00", + "2024-12-01 00:00:00", + "2026-01-01 00:00:00", + "2027-01-01 00:00:00", + "2028-01-01 00:00:00", + "2029-01-01 00:00:00", + "2030-01-01 00:00:00", + "2031-01-01 00:00:00" + ], + "unit": "bara", + "values": [ + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0, + 200.0 + ] + }, "parent": "e1c82c648513148fb53d7b9dcff878ca", "power": { "rate_type": "STREAM_DAY",