Skip to content

Commit

Permalink
chore: simplify energy calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehk committed Dec 11, 2024
1 parent 54be8e2 commit a210215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
16 changes: 1 addition & 15 deletions src/libecalc/application/energy_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
from libecalc.common.variables import ExpressionEvaluator
from libecalc.core.result import EcalcModelResult
from libecalc.core.result.emission import EmissionResult
from libecalc.infrastructure.components import ConsumerSystem
from libecalc.infrastructure.components import (
ElectricityConsumer as ElectricityConsumerDTO,
)
from libecalc.infrastructure.components import (
FuelConsumer as FuelConsumerDTO,
)
from libecalc.infrastructure.components import (
GeneratorSet as GeneratorSetDTO,
)


class Context(ComponentEnergyContext):
Expand Down Expand Up @@ -78,17 +68,13 @@ def evaluate_energy_usage(self) -> dict[str, EcalcModelResult]:
energy_components = self._energy_model.get_energy_components()

for energy_component in energy_components:
if isinstance(energy_component, ElectricityConsumerDTO | FuelConsumerDTO):
self._consumer_results.update(energy_component.evaluate_energy_usage(self._expression_evaluator))
elif isinstance(energy_component, GeneratorSetDTO):
if hasattr(energy_component, "evaluate_energy_usage"):
context = self._get_context(energy_component.id)
self._consumer_results.update(
energy_component.evaluate_energy_usage(
context=context, expression_evaluator=self._expression_evaluator
)
)
elif isinstance(energy_component, ConsumerSystem):
self._consumer_results.update(energy_component.evaluate_energy_usage(self._expression_evaluator))

self._consumer_results = Numbers.format_results_to_precision(self._consumer_results, precision=6)
return self._consumer_results
Expand Down
12 changes: 9 additions & 3 deletions src/libecalc/infrastructure/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def get_component_process_type(self) -> ComponentType:
def get_name(self) -> str:
return self.name

def evaluate_energy_usage(self, expression_evaluator: ExpressionEvaluator) -> dict[str, EcalcModelResult]:
def evaluate_energy_usage(
self, expression_evaluator: ExpressionEvaluator, context: ComponentEnergyContext
) -> dict[str, EcalcModelResult]:
consumer_results: dict[str, EcalcModelResult] = {}
consumer = ConsumerEnergyComponent(
id=self.id,
Expand Down Expand Up @@ -248,7 +250,9 @@ def get_component_process_type(self) -> ComponentType:
def get_name(self) -> str:
return self.name

def evaluate_energy_usage(self, expression_evaluator: ExpressionEvaluator) -> dict[str, EcalcModelResult]:
def evaluate_energy_usage(
self, expression_evaluator: ExpressionEvaluator, context: ComponentEnergyContext
) -> dict[str, EcalcModelResult]:
consumer_results: dict[str, EcalcModelResult] = {}
consumer = ConsumerEnergyComponent(
id=self.id,
Expand Down Expand Up @@ -449,7 +453,9 @@ def get_component_process_type(self) -> ComponentType:
def get_name(self) -> str:
return self.name

def evaluate_energy_usage(self, expression_evaluator: ExpressionEvaluator) -> dict[str, EcalcModelResult]:
def evaluate_energy_usage(
self, expression_evaluator: ExpressionEvaluator, context: ComponentEnergyContext
) -> dict[str, EcalcModelResult]:
consumer_results = {}
evaluated_stream_conditions = self.evaluate_stream_conditions(
expression_evaluator=expression_evaluator,
Expand Down

0 comments on commit a210215

Please sign in to comment.