From 6ac032091cfa8d46be9e016ae75e41cc37567417 Mon Sep 17 00:00:00 2001 From: Frode Helgetun Krogh <70878501+frodehk@users.noreply.github.com> Date: Mon, 18 Sep 2023 16:04:58 +0200 Subject: [PATCH] chore: add method to convert to time series --- src/libecalc/core/graph_result.py | 40 ++++++++++++++++++------------ src/libecalc/dto/result/results.py | 10 ++++++++ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/libecalc/core/graph_result.py b/src/libecalc/core/graph_result.py index 0b57fc08cb..7fc71cafe3 100644 --- a/src/libecalc/core/graph_result.py +++ b/src/libecalc/core/graph_result.py @@ -26,6 +26,7 @@ from libecalc.dto.graph import Graph from libecalc.dto.models.consumer_system import CompressorSystemConsumerFunction from libecalc.dto.result.emission import EmissionIntensityResult +from libecalc.dto.result.results import CompressorModelResult from libecalc.dto.types import RateType from libecalc.dto.utils.aggregators import aggregate_emissions, aggregate_is_valid from libecalc.expression import Expression @@ -304,16 +305,23 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: # Convert rates in stage results from lists to time series: for stage_result in model.stage_results: - stage_result.asv_recirculation_loss_mw = TimeSeriesRate( - timesteps=self.timesteps, - values=stage_result.asv_recirculation_loss_mw - if stage_result.asv_recirculation_loss_mw is not None - else [math.nan] * len(model.timesteps), + # stage_result.asv_recirculation_loss_mw = TimeSeriesRate( + # timesteps=model.timesteps, + # values=stage_result.asv_recirculation_loss_mw + # if stage_result.asv_recirculation_loss_mw is not None + # else [math.nan] * len(model.timesteps), + # unit=Unit.MEGA_WATT, + # rate_type=RateType.STREAM_DAY, + # ) + + stage_result.asv_recirculation_loss_mw = CompressorModelResult.to_time_series( + self=model, + stage_result=stage_result.asv_recirculation_loss_mw, unit=Unit.MEGA_WATT, - rate_type=RateType.STREAM_DAY, ) + stage_result.energy_usage = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.energy_usage if stage_result.energy_usage is not None else [math.nan] * len(model.timesteps), @@ -321,7 +329,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.mass_rate_kg_per_hr = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.mass_rate_kg_per_hr if stage_result.mass_rate_kg_per_hr is not None else [math.nan] * len(model.timesteps), @@ -329,7 +337,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.mass_rate_before_asv_kg_per_hr = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.mass_rate_before_asv_kg_per_hr if stage_result.mass_rate_before_asv_kg_per_hr is not None else [math.nan] * len(model.timesteps), @@ -337,7 +345,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.power = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.power if stage_result.power is not None else [math.nan] * len(model.timesteps), @@ -345,7 +353,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.inlet_stream_condition.actual_rate_m3_per_hr = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.inlet_stream_condition.actual_rate_m3_per_hr if stage_result.inlet_stream_condition.actual_rate_m3_per_hr is not None else [math.nan] * len(model.timesteps), @@ -353,7 +361,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.inlet_stream_condition.actual_rate_before_asv_m3_per_hr = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.inlet_stream_condition.actual_rate_before_asv_m3_per_hr if stage_result.inlet_stream_condition.actual_rate_before_asv_m3_per_hr is not None else [math.nan] * len(model.timesteps), @@ -361,7 +369,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.inlet_stream_condition.density_kg_per_m3 = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.inlet_stream_condition.density_kg_per_m3 if stage_result.inlet_stream_condition.density_kg_per_m3 is not None else [math.nan] * len(model.timesteps), @@ -370,7 +378,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: ) stage_result.outlet_stream_condition.actual_rate_m3_per_hr = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.outlet_stream_condition.actual_rate_m3_per_hr if stage_result.outlet_stream_condition.actual_rate_m3_per_hr is not None else [math.nan] * len(model.timesteps), @@ -378,7 +386,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.outlet_stream_condition.actual_rate_before_asv_m3_per_hr = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.outlet_stream_condition.actual_rate_before_asv_m3_per_hr if stage_result.outlet_stream_condition.actual_rate_before_asv_m3_per_hr is not None else [math.nan] * len(model.timesteps), @@ -386,7 +394,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult: rate_type=RateType.STREAM_DAY, ) stage_result.outlet_stream_condition.density_kg_per_m3 = TimeSeriesRate( - timesteps=self.timesteps, + timesteps=model.timesteps, values=stage_result.outlet_stream_condition.density_kg_per_m3 if stage_result.outlet_stream_condition.density_kg_per_m3 is not None else [math.nan] * len(model.timesteps), diff --git a/src/libecalc/dto/result/results.py b/src/libecalc/dto/result/results.py index 31ba570558..9db2ee558a 100644 --- a/src/libecalc/dto/result/results.py +++ b/src/libecalc/dto/result/results.py @@ -1,5 +1,6 @@ from __future__ import annotations +import math from operator import attrgetter from typing import Any, Dict, List, Literal, Optional, Union @@ -8,6 +9,7 @@ from libecalc.common.time_utils import Frequency from libecalc.common.units import Unit from libecalc.common.utils.rates import ( + RateType, TimeSeriesBoolean, TimeSeriesFloat, TimeSeriesInt, @@ -151,6 +153,14 @@ class CompressorModelResult(ConsumerModelResultBase): energy_usage_unit: Unit power_unit: Unit + def to_time_series(self, stage_result: list, unit: Unit) -> TimeSeriesRate: + return TimeSeriesRate( + timesteps=self.timesteps, + values=stage_result if stage_result is not None else [math.nan] * len(self.timesteps), + unit=unit, + rate_type=RateType.STREAM_DAY, + ) + class GenericModelResult(ConsumerModelResultBase): """Generic consumer result component."""