Skip to content

Commit

Permalink
Merge pull request #116 from JW-Kraft/fix/func_time_zero_error
Browse files Browse the repository at this point in the history
Skip appliance if func_time==0 or rand_time==0
  • Loading branch information
Bachibouzouk authored Mar 19, 2024
2 parents 0c0f51e + 0c65148 commit a0346dd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
1 change: 0 additions & 1 deletion ramp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- random
"""


from ramp._version import __version__
from ramp.core.core import UseCase, User, Appliance
from ramp.core.utils import yearly_pattern, get_day_type
Expand Down
12 changes: 11 additions & 1 deletion ramp/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,14 @@ def __init__(
self.name = name
self.number = number
self.num_windows = num_windows

if func_time == 0:
warnings.warn(
UserWarning(
f"Func_time of appliance '{self.name}' is defined as 0. Ignore if this is intended"
)
)

self.func_time = func_time
self.time_fraction_random_variability = time_fraction_random_variability
self.func_cycle = func_cycle
Expand Down Expand Up @@ -1799,6 +1807,8 @@ def generate_load_profile(self, prof_i, peak_time_range, day_type, power):
or (self.pref_index != 0 and self.user.rand_daily_pref != self.pref_index)
# checks if the app is allowed in the given yearly behaviour pattern
or self.wd_we_type not in [day_type, 2]
# skip if the app has a func_time of 0
or self.func_time == 0
):
return

Expand Down Expand Up @@ -1845,7 +1855,7 @@ def generate_load_profile(self, prof_i, peak_time_range, day_type, power):
]

tot_time = 0
while tot_time <= rand_time:
while tot_time <= rand_time and rand_time != 0:
# one option could be to generate a lot of them at once
indexes = self.rand_switch_on_window(
rand_time=rand_time, # TODO maybe only consider rand_time-tot_time ...
Expand Down
42 changes: 42 additions & 0 deletions tests/test_func_time_zero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import numpy as np
import pytest
from ramp import UseCase, User


def test_skip_when_func_time_zero():
# Generate test user and appliance
user = User(user_name="Test User", num_users=1)
appliance = user.add_appliance(
name="Test Appliance",
func_time=0, # Set func_time to be 0
func_cycle=20,
time_fraction_random_variability=0.1,
)

# Add to use_case
use_case = UseCase(name="test_use_case", users=[user])

# Calculate peak time range for this use_case
peak_time_range = use_case.calc_peak_time_range()

# Generated one load profile of this appliance
power = 1000
appliance.generate_load_profile(
prof_i=0, peak_time_range=peak_time_range, day_type=0, power=power
)

# Check that no use of this appliance is simulated -> the appliances load profile is always smaller than it's power
# (Checking for the load_profile to always be 0 might be unreliable, since the RAMP core "marks" potential usage
# windows with small power values larger 0)
assert np.max(appliance.daily_use) < power


def test_warning_when_func_time_zero():
user = User(user_name="Test User", num_users=1)
with pytest.warns():
appliance = user.add_appliance(
name="Test Appliance",
func_time=0, # Set func_time to be 0
func_cycle=20,
time_fraction_random_variability=0.1,
)

0 comments on commit a0346dd

Please sign in to comment.