Skip to content

Commit

Permalink
Merge pull request #152 from RAMP-project/fix/ramp_convert
Browse files Browse the repository at this point in the history
Small fixes before the release
  • Loading branch information
Bachibouzouk authored Jun 7, 2024
2 parents b34509f + 37c9d21 commit 077ddbe
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.7"
python: "3.10"

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand All @@ -23,4 +23,4 @@ sphinx:
# Optionally set the version of Python and requirements required to build your docs
python:
install:
- requirements: docs/docs-requirements.txt
- requirements: docs/docs-requirements.txt
1 change: 1 addition & 0 deletions docs/docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ ipykernel
sphinx-autobuild
sphinx-copybutton
sphinx_wagtail_theme
myst_parser
nbformat
nbconvert
8 changes: 7 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def copy_contributing():
copyright = "2022, Author List"
author = "Author List"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand All @@ -76,8 +75,15 @@ def copy_contributing():
"sphinx_copybutton",
"sphinx.ext.autosectionlabel",
"sphinx_wagtail_theme",
"sphinx_copybutton",
"myst_parser",
]

source_suffix = {
".rst": "restructuredtext",
".txt": "markdown",
".md": "markdown",
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
55 changes: 35 additions & 20 deletions ramp/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
random_choice,
read_input_file,
within_peak_time_window,
range_within_window,
)
from ramp.post_process.post_process import Plot

Expand Down Expand Up @@ -699,6 +700,8 @@ def _add_appliance_instance(self, appliances):
f"You are trying to add an object of type {type(app)} as an appliance to the user {self.user_name}"
)
if app not in self.App_list:
if app.name == "":
app.name = f"appliance_{len(self.App_list) + 1}"
self.App_list.append(app)

def add_appliance(self, *args, **kwargs):
Expand Down Expand Up @@ -1865,35 +1868,47 @@ def rand_switch_on_window(self, rand_time: int):
if (
self.fixed_cycle > 0
): # evaluates if the app has some duty cycles to be considered
evaluate = np.round(np.mean(indexes)) if indexes.size > 0 else 0
indexes_low = indexes[0]
indexes_high = indexes[-1]
# selects the proper duty cycle
if (
self.cw11[0] <= evaluate < self.cw11[1]
or self.cw12[0] <= evaluate < self.cw12[1]
):
if range_within_window(
indexes_low, indexes_high, self.cw11
) or range_within_window(indexes_low, indexes_high, self.cw12):
self.current_duty_cycle_id = 1
duty_cycle_duration = len(self.random_cycle1)
elif (
self.cw21[0] <= evaluate < self.cw21[1]
or self.cw22[0] <= evaluate < self.cw22[1]
):
elif range_within_window(
indexes_low, indexes_high, self.cw21
) or range_within_window(indexes_low, indexes_high, self.cw22):
self.current_duty_cycle_id = 2
duty_cycle_duration = len(self.random_cycle2)
elif (
self.cw31[0] <= evaluate < self.cw31[1]
or self.cw32[0] <= evaluate < self.cw32[1]
):
elif range_within_window(
indexes_low, indexes_high, self.cw31
) or range_within_window(indexes_low, indexes_high, self.cw32):
self.current_duty_cycle_id = 3
duty_cycle_duration = len(self.random_cycle3)
else:
print(
f"The app {self.name} has duty cycle option on, however the switch on event fell outside the provided duty cycle windows"
# previously duty_cycle3 was always considered as default if neither duty_cycle1 nor duty_cycle2
# got selected. If the switch on window does not fall within any duty cycle we do not assign it
# to duty_cycle3 by default, rather we pick another switch on event and we notify the user we
# did so. That way, in case this warning is shown too often, it can indicate to the user there
# is some peculiar behavior for this appliance
warnings.warn(
f"The app {self.name} has duty cycle option on (with {self.fixed_cycle} cycle(s)). However, the switch on window [{switch_on}, {switch_on + len(indexes)}] fell outside the provided duty cycle windows: "
+ "cw11 "
+ str(self.cw11)
+ ", cw12 "
+ str(self.cw12)
+ ", cw21 "
+ str(self.cw21)
+ ", cw22 "
+ str(self.cw22)
+ ", cw31 "
+ str(self.cw31)
+ ", cw32 "
+ str(self.cw32)
+ ". Picking another random switch on event. You probably see this warning because your window of use is the same as the duty cycle window and the random variability of the windows of use is greater than zero. If you see this warning only once, no need to worry, this is inherent to stochasticity."
)
# TODO previously duty_cycle3 was always considered as default if the evaluate proxy did neither
# get selected by duty_cycle1 nor duty_cycle2, for default is kept but not silently anymore in
# order to see wheather this is an issue or not
self.current_duty_cycle_id = 3
duty_cycle_duration = len(self.random_cycle3)
return self.rand_switch_on_window(rand_time)

if (
indexes.size > duty_cycle_duration
Expand Down
14 changes: 14 additions & 0 deletions ramp/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ def duty_cycle(var, t1, p1, t2, p2):
)


def range_within_window(range_low, range_high, window):
"""Compare a range with a window to see if there is an overlap
The two cases where there is no overlap between two windows are when the
range boundaries are both lower than the lowest window value or both
higher than the highest window value
"""
return not (
(range_low < window[0] and range_high < window[0])
or (range_low > window[1] and range_high > window[1])
)


def random_choice(var, t1, p1, t2, p2):
"""Chooses one of two duty cycles randomly
Expand Down
Loading

0 comments on commit 077ddbe

Please sign in to comment.