Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
4

Grab time data from an OS model schedule

asked 2019-01-02 14:01:29 -0600

ParticleSwarm's avatar

updated 2019-01-02 14:37:07 -0600

Hello Unmet Hours!

I am currently writing a measure to modify schedules in Open Studio and was wondering if it is possible to get time data when a certain set point or threshold is reached. for example, I would like to grab the time of day based on when the building was occupied; specifically the start time of the day.

I am still new to writing measures so any info would be extremely helpful.

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2019-01-03 09:42:52 -0600

updated 2019-01-03 09:48:37 -0600

Let's say you grab a ScheduleRuleset from your Model:

In [1]:
sch = m.getScheduleRulesetByName("Large Office Bldg Occ").get
# Get the default day schedule
sch_day = sch.defaultDaySchedule
# Or get one of the schedule rules' day schedule
sch_rule = sch.scheduleRules[0]
sch_day = sch_rule.daySchedule

You could also get a specific schedule day from a list of dates: see SDK Doc for ScheduleRuleset::getDaySchedules

In [2]:
start_date and end_date are both inclusive, so to get a single schedule day for a specific date, do like this:

start_date = OpenStudio::Date.new(OpenStudio::MonthOfYear.new("Jan"), 3)
sch_days = sch.getDaySchedules(start_date, end_date)
sch_day = sch_days[0]

In all cases, you end up with a ScheduleDay object, which has two vectors: values and times. You can loop on them:

In [3]:
sch_day.times.each_with_index do |t, i|
   v = sch_day.values[i]
   puts "#{t} - #{v}"
end

Out[3]:
06:00:00 - 0.0
07:00:00 - 0.1
08:00:00 - 0.2
12:00:00 - 0.95
13:00:00 - 0.5
17:00:00 - 0.95
18:00:00 - 0.7
20:00:00 - 0.4
22:00:00 - 0.1
24:00:00 - 0.05

For the record, here's the content of my sch_day

In [4]: puts sch_day
Out[4]: OS:Schedule:Day,
  {2b88cc09-05ab-4d50-acb8-6333aa6ac43b}, ! Handle
  Large Office Bldg Occ Default Schedule, ! Name
  {5eb48a4a-20e2-4feb-8b1f-c9c9b1824a15}, ! Schedule Type Limits Name
  ,                                       ! Interpolate to Timestep
  6,                                      !- Hour 1
  0,                                      !- Minute 1
  0,                                      !- Value Until Time 1
  7,                                      !- Hour 2
  0,                                      !- Minute 2
  0.1,                                    !- Value Until Time 2
  8,                                      !- Hour 3
  0,                                      !- Minute 3
  0.2,                                    !- Value Until Time 3
  12,                                     !- Hour 4
  0,                                      !- Minute 4
  0.95,                                   !- Value Until Time 4
  13,                                     !- Hour 5
  0,                                      !- Minute 5
  0.5,                                    !- Value Until Time 5
  17,                                     !- Hour 6
  0,                                      !- Minute 6
  0.95,                                   !- Value Until Time 6
  18,                                     !- Hour 7
  0,                                      !- Minute 7
  0.7,                                    !- Value Until Time 7
  20,                                     !- Hour 8
  0,                                      !- Minute 8
  0.4,                                    !- Value Until Time 8
  22,                                     !- Hour 9
  0,                                      !- Minute 9
  0.1,                                    !- Value Until Time 9
  24,                                     !- Hour 10
  0,                                      !- Minute 10
  0.05;                                   !- Value Until Time 10
edit flag offensive delete link more

Comments

This is perfect thank you!

ParticleSwarm's avatar ParticleSwarm  ( 2019-01-03 10:17:35 -0600 )edit
1

@Julien Marrec and @ParticleSwarm there is also a sch_day.getValue()method that you pass a time into. This allows you to get a value for any time, even if that exact time doesn't exist in sch_day.times

David Goldwasser's avatar David Goldwasser  ( 2019-01-03 12:20:55 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2019-01-02 14:01:29 -0600

Seen: 432 times

Last updated: Jan 03 '19