Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/gsy_e/gsy_e_core/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

if TYPE_CHECKING:
from gsy_e.gsy_e_core.sim_results.endpoint_buffer import SimulationEndpointBuffer
from gsy_e.gsy_e_core.simulation.setup import SimulationSetup
from gsy_e.models.market.future import FutureMarkets

_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -103,12 +104,14 @@ def __init__(
subdir: str,
endpoint_buffer: "SimulationEndpointBuffer",
carbon_ratio_file: str,
config_params: "SimulationSetup",
):
self.area = root_area
self.endpoint_buffer = endpoint_buffer
self.file_stats_endpoint = self._file_export_endpoints_class()
self.raw_data_subdir = None
self.carbon_ratio_file = carbon_ratio_file
self.config_params = config_params
try:
if path is not None:
path = os.path.abspath(path)
Expand Down Expand Up @@ -147,6 +150,19 @@ def _export_json_data(self) -> None:
with open(json_file, "w", encoding="utf-8") as outfile:
json.dump(value, outfile, indent=2)

# Export PV ROI
pv_assets = self.area.get_pv_assets()
for pv in pv_assets:
print("pv.uuid", pv.uuid)
cumulative_grid_trades = json_report.get("cumulative_grid_trades")
energy_produced_kWh = cumulative_grid_trades[pv.uuid]["produced"]
summary = pv.strategy.roi(
duration_days=self.config_params.config.sim_duration.days,
energy_produced_kWh=energy_produced_kWh,
)
print("summary ", summary)

# Export Carbon Emissions
if self.carbon_ratio_file:
carbon_emissions_handler = CarbonEmissionsHandler()
carbon_ratio = (
Expand Down
1 change: 1 addition & 0 deletions src/gsy_e/gsy_e_core/simulation/results_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def init_results(
self.export_subdir,
self._endpoint_buffer,
self.carbon_ratio_file,
config_params,
)

@property
Expand Down
18 changes: 17 additions & 1 deletion src/gsy_e/models/area/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
from gsy_e.models.config import SimulationConfig
from gsy_e.models.market.forward import ForwardMarketBase
from gsy_e.models.market.future import FutureMarkets

from gsy_e.models.strategy.external_strategies import ExternalMixin
from gsy_e.models.strategy.pv import PVStrategy

log = getLogger(__name__)

Expand Down Expand Up @@ -630,6 +630,22 @@ def get_results_dict(self) -> dict:
),
}

def get_pv_assets(self) -> List["Asset"]:
"""Return a list of all PV assets or areas with PV strategy in this area and sub-areas."""
pv_assets = []

for child in self.children:
has_pv_strategy = hasattr(child, "strategy") and isinstance(child.strategy, PVStrategy)

if isinstance(child, Asset) and has_pv_strategy:
pv_assets.append(child)
elif has_pv_strategy:
pv_assets.append(child)
elif isinstance(child, Area):
pv_assets.extend(child.get_pv_assets())

return pv_assets


class Market(Area):
"""Class to define geographical market areas that can contain children (areas or assets)."""
Expand Down
Loading