Skip to content

Commit

Permalink
fix(schedule): Add a check for schedule length in FixedInterval
Browse files Browse the repository at this point in the history
Hopefully, this helps people use the component correctly.
  • Loading branch information
chriswmackey authored and Chris Mackey committed Aug 3, 2023
1 parent 3428882 commit c2b1328
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 6 deletions.
Binary file modified honeybee_grasshopper_energy/icon/HB Fixed Interval Schedule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified honeybee_grasshopper_energy/icon/HB Model to OSM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.6.1",
"nickname": "FixedIntervalSchedule",
"outputs": [
[
Expand Down Expand Up @@ -50,7 +50,7 @@
}
],
"subcategory": "2 :: Schedules",
"code": "\ntry: # import the ladybug dependencies\n from ladybug.dt import Date\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry: # import the core honeybee dependencies\n from honeybee.typing import clean_and_id_ep_string, clean_ep_string\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the honeybee-energy dependencies\n from honeybee_energy.schedule.fixedinterval import ScheduleFixedInterval\n from honeybee_energy.lib.scheduletypelimits import schedule_type_limit_by_identifier\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry: # import ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # set the defaults\n _timestep_ = 1 if _timestep_ is None else _timestep_\n start_date = Date(1, 1) if analysis_period_ is None else \\\n analysis_period_.st_time.date\n name = clean_and_id_ep_string('FixedIntervalSchedule') if _name_ is None else \\\n clean_ep_string(_name_)\n\n # get the ScheduleTypeLimit object\n if _type_limit_ is None:\n _type_limit_ = schedule_type_limit_by_identifier('Fractional')\n elif isinstance(_type_limit_, str):\n _type_limit_ = schedule_type_limit_by_identifier(_type_limit_)\n\n # create the schedule object\n schedule = ScheduleFixedInterval(\n name, _values, _type_limit_, _timestep_, start_date,\n placeholder_value=0, interpolate=False)\n if _name_ is not None:\n schedule.display_name = _name_\n",
"code": "\ntry: # import the ladybug dependencies\n from ladybug.dt import Date\n from ladybug.analysisperiod import AnalysisPeriod\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry: # import the core honeybee dependencies\n from honeybee.typing import clean_and_id_ep_string, clean_ep_string\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the honeybee-energy dependencies\n from honeybee_energy.schedule.fixedinterval import ScheduleFixedInterval\n from honeybee_energy.lib.scheduletypelimits import schedule_type_limit_by_identifier\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry: # import ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # set the defaults\n _timestep_ = 1 if _timestep_ is None else _timestep_\n start_date = Date(1, 1) if analysis_period_ is None else \\\n analysis_period_.st_time.date\n name = clean_and_id_ep_string('FixedIntervalSchedule') if _name_ is None else \\\n clean_ep_string(_name_)\n\n # perform a check to see if the input values align with the analysis period\n a_per = AnalysisPeriod() if analysis_period_ is None else analysis_period_\n if len(a_per) * _timestep_ != len(_values):\n msg = 'The number of values implied by the analysis period [{}]\\n' \\\n 'is not the same as the number of values supplied [{}].\\n' \\\n 'This may result in unexpeted behavior.'.format(\n len(a_per) * _timestep_, len(_values))\n print(msg)\n give_warning(ghenv.Component, msg)\n\n # get the ScheduleTypeLimit object\n if _type_limit_ is None:\n _type_limit_ = schedule_type_limit_by_identifier('Fractional')\n elif isinstance(_type_limit_, str):\n _type_limit_ = schedule_type_limit_by_identifier(_type_limit_)\n\n # create the schedule object\n schedule = ScheduleFixedInterval(\n name, _values, _type_limit_, _timestep_, start_date,\n placeholder_value=0, interpolate=False)\n if _name_ is not None:\n schedule.display_name = _name_\n",
"category": "HB-Energy",
"name": "HB Fixed Interval Schedule",
"description": "Create a schedule defined by a list of values at a fixed interval or timestep\nrunning over the entirety of the simulation period.\n-"
Expand Down
2 changes: 1 addition & 1 deletion honeybee_grasshopper_energy/json/HB_Model_to_OSM.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.4",
"version": "1.6.5",
"nickname": "ModelToOSM",
"outputs": [
[
Expand Down
15 changes: 13 additions & 2 deletions honeybee_grasshopper_energy/src/HB Fixed Interval Schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@

ghenv.Component.Name = 'HB Fixed Interval Schedule'
ghenv.Component.NickName = 'FixedIntervalSchedule'
ghenv.Component.Message = '1.6.0'
ghenv.Component.Message = '1.6.1'
ghenv.Component.Category = 'HB-Energy'
ghenv.Component.SubCategory = '2 :: Schedules'
ghenv.Component.AdditionalHelpFromDocStrings = '4'

try: # import the ladybug dependencies
from ladybug.dt import Date
from ladybug.analysisperiod import AnalysisPeriod
except ImportError as e:
raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

Expand All @@ -79,7 +80,7 @@
raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e))

try: # import ladybug_rhino dependencies
from ladybug_rhino.grasshopper import all_required_inputs
from ladybug_rhino.grasshopper import all_required_inputs, give_warning
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

Expand All @@ -92,6 +93,16 @@
name = clean_and_id_ep_string('FixedIntervalSchedule') if _name_ is None else \
clean_ep_string(_name_)

# perform a check to see if the input values align with the analysis period
a_per = AnalysisPeriod() if analysis_period_ is None else analysis_period_
if len(a_per) * _timestep_ != len(_values):
msg = 'The number of values implied by the analysis period [{}]\n' \
'is not the same as the number of values supplied [{}].\n' \
'This may result in unexpeted behavior.'.format(
len(a_per) * _timestep_, len(_values))
print(msg)
give_warning(ghenv.Component, msg)

# get the ScheduleTypeLimit object
if _type_limit_ is None:
_type_limit_ = schedule_type_limit_by_identifier('Fractional')
Expand Down
2 changes: 1 addition & 1 deletion honeybee_grasshopper_energy/src/HB Model to OSM.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

ghenv.Component.Name = 'HB Model to OSM'
ghenv.Component.NickName = 'ModelToOSM'
ghenv.Component.Message = '1.6.4'
ghenv.Component.Message = '1.6.5'
ghenv.Component.Category = 'HB-Energy'
ghenv.Component.SubCategory = '5 :: Simulate'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand Down
Binary file not shown.
Binary file modified honeybee_grasshopper_energy/user_objects/HB Model to OSM.ghuser
Binary file not shown.
Binary file modified samples/shoe_box_energy_model.gh
Binary file not shown.

0 comments on commit c2b1328

Please sign in to comment.