Create a schedule based on user input [closed]

asked 2023-01-31 21:50:02 -0500

HoussemYounes's avatar

Hello, I am writing a measure in openstudio that takes user inputs about start and end times of charging of a system. I want to recreate the following compact schedule in Ruby with times 7:00, 17:00, 24:00 being user inputs.

Schedule:Compact,
ChargeSchedule,          !- Name
On/Off,                  !- Schedule Type Limits Name
Through: 12/31,          !- Field 1
For: Weekdays,           !- Field 2
Until: 7:00, 1,          !- Field 4
Until: 17:00, 0,         !- Field 6
Until: 24:00, 1,         !- Field 8
For: Weekends Holidays,  !- Field 9
Until: 24:00, 1,         !- Field 11
For: AllOtherDays,       !- Field 12
Until: 24:00, 1;         !- Field 14

I will then create a sensor to get the schedule value (the authorization to charge my system) for my calculation.

This what i've written so far

# Get user inputs
  charge_start = runner.getStringArgumentValue('charge_start', user_arguments)
  charge_end = runner.getStringArgumentValue('charge_end', user_arguments

# Convert HR:MM format into HR.fraction format
(c_start_hr, c_start_min) = charge_start.split(':')
(c_end_hr, c_end_min) = charge_end.split(':')
# Store re-formatted time values in shorthand variables for use in schedule building  cs: charge start , ce:charge end 
  cs = (c_start_hr.to_f + c_start_min.to_f / 60).round(2)
      ce = (c_end_hr.to_f + c_end_min.to_f / 60).round(2)

#Create Schedule Type Limits
  sched_limits_onoff = OpenStudio::Model::ScheduleTypeLimits.new(model)
      sched_limits_onoff.setName('OnOff')
      sched_limits_onoff.setNumericType('Discrete')
      sched_limits_onoff.setUnitType('Availability')
      sched_limits_onoff.setLowerLimitValue(0.0)
      sched_limits_onoff.setUpperLimitValue(1.0)

    # Create the Compact Schedule   
  charge_schedule = OpenStudio::Model::ScheduleCompact.new(model)
  charge_schedule.setName('Charge_Schedule')
  charge_schedule.setScheduleTypeLimitsName(sched_limits_onoff.handle.to_s)

Any indications on how to continue from here ?

Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by Aaron Boranian
close date 2023-02-01 09:54:12.053183

Comments

Duplicate of this post.

Aaron Boranian's avatar Aaron Boranian  ( 2023-02-01 09:54:21 -0500 )edit