Skip to content

Commit

Permalink
Merge pull request #1807 from gridsingularity/fix-monthly-fees
Browse files Browse the repository at this point in the history
GSYE-780: Fixed monthly power fees on the CoefficientArea class. Remo…
  • Loading branch information
spyrostz authored Oct 17, 2024
2 parents 17303f9 + 79944be commit fa6442f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/gsy_e/gsy_e_core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys
import termios
import tty
from calendar import monthrange
from functools import wraps
from logging import LoggerAdapter, getLogger, getLoggerClass, addLevelName, setLoggerClass, NOTSET
from typing import TYPE_CHECKING, Optional
Expand Down Expand Up @@ -529,3 +530,10 @@ def memory_usage_percent():
return 0

return round(int(mem_usage) / int(mem_limit) * 100)


def get_slots_per_month(time_slot: DateTime) -> int:
"""Get number of slots for the month defined by the time_slot."""
return (duration(days=1) / GlobalConfig.slot_length) * monthrange(
time_slot.year, time_slot.month
)[1]
15 changes: 11 additions & 4 deletions src/gsy_e/models/area/coefficient_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from gsy_e.models.strategy.external_strategies import ExternalMixin
from gsy_e.models.strategy.scm import SCMStrategy
from gsy_e.models.area.scm_dataclasses import SCMAreaProperties
from gsy_e.gsy_e_core.util import get_slots_per_month

log = getLogger(__name__)

Expand Down Expand Up @@ -80,7 +81,9 @@ def activate_energy_parameters(self, current_time_slot: DateTime) -> None:
for child in self.children:
child.activate_energy_parameters(current_time_slot)

def _handle_area_parameters_from_profiles(self, area_profiles: dict) -> None:
def _handle_area_parameters_from_profiles(
self, current_time_slot: DateTime, area_profiles: dict
) -> None:
if self.uuid not in area_profiles:
return
area_profile = area_profiles[self.uuid]
Expand All @@ -94,19 +97,23 @@ def _handle_area_parameters_from_profiles(self, area_profiles: dict) -> None:
self.area_properties.PER_KWH_FEES["energy_cargo_fee"] = area_profile.energy_cargo_fee
if area_profile.power_fee:
self.area_properties.MONTHLY_FEES["power_fee"] = (
area_profile.power_fee * area_profile.contracted_power_kw
area_profile.power_fee
* area_profile.contracted_power_kw
/ get_slots_per_month(current_time_slot)
)
if area_profile.power_cargo_fee:
self.area_properties.MONTHLY_FEES["power_cargo_fee"] = (
area_profile.power_cargo_fee * area_profile.contracted_power_kw
area_profile.power_cargo_fee
* area_profile.contracted_power_kw
/ get_slots_per_month(current_time_slot)
)

def cycle_coefficients_trading(self, current_time_slot: DateTime, area_profiles: dict) -> None:
"""Perform operations that should be executed on coefficients trading cycle."""
self.past_market_time_slot = self.current_market_time_slot
self.current_market_time_slot = current_time_slot

self._handle_area_parameters_from_profiles(area_profiles)
self._handle_area_parameters_from_profiles(current_time_slot, area_profiles)
if self.strategy:
self.strategy.market_cycle(self)

Expand Down
1 change: 0 additions & 1 deletion src/gsy_e/models/area/scm_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ class AreaFees:
grid_export_fee_const: float = 0.0
grid_fees_reduction: float = 0.0
per_kWh_fees: Dict[str, FeeContainer] = field(default_factory=dict)
per_kW_fees: Dict[str, ContractedPowerFeeContainer] = field(default_factory=dict)
monthly_fees: Dict[str, FeeContainer] = field(default_factory=dict)

def prices_as_dict(self) -> Dict:
Expand Down
10 changes: 4 additions & 6 deletions src/gsy_e/models/area/scm_manager.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from calendar import monthrange
from math import isclose
from typing import TYPE_CHECKING, Dict, Optional

from gsy_framework.constants_limits import ConstSettings, GlobalConfig
from pendulum import DateTime, duration
from gsy_framework.constants_limits import ConstSettings
from pendulum import DateTime

import gsy_e.constants
from gsy_e.constants import (
DEFAULT_SCM_COMMUNITY_NAME,
DEFAULT_SCM_GRID_NAME,
FLOATING_POINT_TOLERANCE,
)
from gsy_e.gsy_e_core.util import get_slots_per_month
from gsy_e.models.area.scm_dataclasses import (
HomeAfterMeterData,
CommunityData,
Expand Down Expand Up @@ -111,9 +111,7 @@ def calculate_community_after_meter_data(self):
)

def _init_area_energy_rates(self, home_data: HomeAfterMeterData) -> AreaEnergyRates:
slots_per_month = (duration(days=1) / GlobalConfig.slot_length) * monthrange(
self._time_slot.year, self._time_slot.month
)[1]
slots_per_month = get_slots_per_month(self._time_slot)
market_maker_rate = home_data.area_properties.AREA_PROPERTIES["market_maker_rate"]
intracommunity_base_rate = (
market_maker_rate
Expand Down

0 comments on commit fa6442f

Please sign in to comment.