Skip to content

Write migration for splitting development of demand building appliances and removal intelligen light control #1698

@kndehaan

Description

@kndehaan

Description

For this issue, effort has been done to remove intelligent light control sliders. Additional work has been done to also split the development of demand input for electricity in buildings to separate sliders for lighting and appliances.

A scenario migration needs to be written to deal with the changes. Generally it should:

  • Set the value of the old input buildings_useful_demand_electricity to the new inputs buildings_useful_demand_lighting and buildings_useful_demand_appliances
  • If buildings_lighting_savings_from_daylight_control_light and/or buildings_lighting_savings_from_motion_detection_light had been set, the combined effect should be set to buildings_useful_demand_lighting
  • Remove old inputs from the scenarios

Practical notes:

  • The migration can be written on the existing branch remove-intelligent-control. The old migration file 20260119083809_remove_intelligent_control.rb can be fully replaced with the new migration file.

Pseudo code

Here is my attempt to write what needs to be in the migration in pseudo code. @mabijkerk could you review the content of this pseudo code? If agreed, I hope @aaccensi can start working on writing the migration, with guidance from @noracato. And let me know if this requires some verbal explanation.

# Starting with relevant inputs (keys)

# Retired buildings intelligent light keys
BUILDINGS_INTELLIGENT_LIGHT_KEYS = %w[
    buildings_lighting_savings_from_daylight_control_light
    buildings_lighting_savings_from_motion_detection_light
].freeze

# Old and new keys for development of demand appliances and lighting
OLD_DEMAND_INPUT_KEY = 'buildings_useful_demand_electricity'
NEW_DEMAND_INPUT_KEYS = %w[
    buildings_useful_demand_appliances
    buildings_useful_demand_lighting
].freeze
# Check if a key in BUILDINGS_INTELLIGENT_LIGHT_KEYS has been set
if key in BUILDINGS_INTELLIGENT_LIGHT_KEYS has been set:

The following code should all be done if a key in BUILDINGS_INTELLIGENT_LIGHT_KEYS has been set in the scenario

# get start year values of the following edges
  
demand_after_daylight_share_start_year = V(EDGE(buildings_useful_demand_after_motion_detection_daylight_control_light, buildings_useful_demand_after_motion_detection_light), share)
# (note that this edge value is the same as dataset value SHARE("energy/buildings_useful_demand_after_motion_detection_light_child_share", buildings_useful_demand_after_motion_detection_daylight_control_light))

demand_after_motion_share_start_year = V(EDGE(buildings_useful_demand_after_motion_detection_light,buildings_useful_demand_light), share)
# (note that this edge value is the same as dataset value SHARE("energy/buildings_useful_demand_light_child_share", buildings_useful_demand_after_motion_detection_light))
# determine intelligent light control effects
effect_daylight_control_start_year = 1 - demand_after_daylight_share_start_year
effect_daylight_control_end_year = buildings_lighting_savings_from_daylight_control_light / 387.0
demand_after_daylight_share_end_year = 1 - effect_daylight_control_end_year
useful_demand_effect_daylight = demand_after_daylight_share_end_year / demand_after_daylight_share_start_year

effect_motion_detection_start_year = 1 - demand_after_motion_share_start_year
effect_motion_detection_end_year = buildings_lighting_savings_from_motion_detection_light / 680.0
demand_after_motion_share_end_year = 1 - effect_motion_detecetion_end_year
useful_demand_effect_motion = demand_after_motion_share_end_year / demand_after_motion_share_start_year
# Determine combined effect
# note to only multiply below if both daylight and motion were set. If only one of the two were set, only that effect needs to be taken into account. Basically, make sure to not multiply with zero here since that will undo the other effect
combined_intelligent_light_effect = useful_demand_effect_daylight * useful_demand_effect_motion

# Convert combined effect to % per year
combined_intelligent_light_effect_per_year = combined_intelligent_light_effect ^ (1/(end_year-start_year)) -1

Once the intelligent light effect has been determined, we'll take this into account next when handling the development of demand inputs. There are three different combinations possible:

  • buildings_useful_demand_electricity has been set, BUILDINGS_INTELLIGENT_LIGHT_KEYS have not been set
  • buildings_useful_demand_electricity has been set and BUILDINGS_INTELLIGENT_LIGHT_KEYS have been set
  • buildings_useful_demand_electricity has not been set, BUILDINGS_INTELLIGENT_LIGHT_KEYS have been set

The three pieces of code below describe what to do:

if buildings_useful_demand_electricity has been set and if BUILDINGS_INTELLIGENT_LIGHT_KEYS have not been set:
  buildings_useful_demand_appliances = buildings_useful_demand_electricity
  buildings_useful_demand_lighting = buildings_useful_demand_electricity
# if buildings_useful_demand_electricity has been set and if BUILDINGS_INTELLIGENT_LIGHT_KEYS have been set, the intelligent lighting effect should be taken into account as well. A check should be done for input min and max values

if buildings_useful_demand_electricity has been set and if BUILDINGS_INTELLIGENT_LIGHT_KEYS have been set:
  # determine combined effect of intelligent light and development of demand
  combined_effect_demand_intelligent_light = buildings_useful_demand_electricity + combined_intelligent_light_effect_per_year
  
  # check if value is within the min and max bounds
  if combined_effect_demand_intelligent_light > 5.0:
    combined_effect_demand_intelligent_light = 5.0
  elif combined_effect_demand_intelligent_light < -5.0:
    combined_effect_demand_intelligent_light = -5.0
  else:
    combined_effect_demand_intelligent_light = combined_effect_demand_intelligent_light
  
  # set the new inputs
  buildings_useful_demand_appliances = buildings_useful_demand_electricity
  buildings_useful_demand_lighting = combined_effect_demand_intelligent_light
# if buildings_useful_demand_electricity has not been set, but if BUILDINGS_INTELLIGENT_LIGHT_KEYS have been set, only the intelligent lighting effect needs to be taken into account. Also here it should be checked whether the value is within the bounds

if buildings_useful_demand_electricity has not bee set, but if key in BUILDINGS_INTELLIGENT_LIGHT_KEYS has been set:
  if combined_intelligent_light_effect_per_year > 5.0:
    combined_intelligent_light_effect_per_year = 5.0
  elif combined_intelligent_light_effect_per_year < -5.0:
    combined_intelligent_light_effect_per_year = -5.0
  else:
    combined_intelligent_light_effect_per_year = combined_intelligent_light_effect_per_year
  
  buildings_useful_demand_lighting = combined_intelligent_light_effect_per_year

Finally, the old inputs should be removed from the scenario

old_keys = BUILDINGS_INTELLIGENT_LIGHT_KEYS + OLD_DEMAND_INPUT_KEY
old_keys.each do |key|
  scenario.user_values.delete(key)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions