Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip appliance if func_time==0 or rand_time==0 #116

Merged
Merged
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
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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally you could simply create an appliance without user or usecase and call generate_load_profile

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,
)
Loading