Class: AdjustDHWSetpointTest

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/measures/adjust_dhw_setpoint/tests/adjust_dhw_setpoint_test.rb

Instance Method Summary collapse

Instance Method Details

#test_adjust_dhw_setpoint_hpwhObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/measures/adjust_dhw_setpoint/tests/adjust_dhw_setpoint_test.rb', line 95

def test_adjust_dhw_setpoint_hpwh
  # create an instance of the measure
  measure = AdjustDHWSetpoint.new

  # create runner with empty OSW
  osw = OpenStudio::WorkflowJSON.new
  runner = OpenStudio::Measure::OSRunner.new(osw)

  # load the test model
  translator = OpenStudio::OSVersion::VersionTranslator.new
  path = "#{File.dirname(__FILE__)}/LargeOffice-90.1-2013-ASHRAE 169-2013-5A-HPWH.osm"
  model = translator.loadModel(path)
  assert(!model.empty?)
  model = model.get

  # get arguments
  arguments = measure.arguments(model)
  argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)

  # create hash of argument values.
  # If the argument has a default that you want to use, you don't need it in the hash
  args_hash = {}
  args_hash['stp_adj_method'] = 'By Absolute Temperature'   # 'By Setback Degree'
  args_hash['flex_stp_1'] = '170'
  args_hash['flex_hrs_1'] = '10:00-14:00'
  # args_hash['flex_stp_2'] = '170'
  # args_hash['flex_hrs_2'] = '00:00-9:00'
  args_hash['flex_stp_3'] = '120'
  args_hash['flex_hrs_3'] = '14:00-18:00'
  # args_hash['flex_stp_4'] = '170'
  # args_hash['flex_hrs_4'] = '13:00-24:00'
  # using defaults values from measure.rb for other arguments

  # populate argument with specified hash value if specified
  arguments.each do |arg|
    temp_arg_var = arg.clone
    if args_hash.key?(arg.name)
      assert(temp_arg_var.setValue(args_hash[arg.name]))
    end
    argument_map[arg.name] = temp_arg_var
  end
  puts argument_map.values.inspect
  # flex1
  # flex_hrs1

  # run the measure
  measure.run(model, runner, argument_map)
  result = runner.result

  # assert that it ran correctly
  assert_equal('Success', result.value.valueName)

  # show the output
  show_output(result)

  # save the model to test output directory
  output_file_path = "#{File.dirname(__FILE__)}//output/test_output.osm"
  model.save(output_file_path, true)

  # test run the modified model
  osw = {}
  osw["weather_file"] = File.join(File.dirname(__FILE__ ), "CZ06RV2.epw")
  osw["seed_file"] = output_file_path
  osw_path = "#{File.dirname(__FILE__)}//output/test_output.osw"
  File.open(osw_path, 'w') do |f|
    f << JSON.pretty_generate(osw)
  end
  cli_path = OpenStudio.getOpenStudioCLI
  cmd = "\"#{cli_path}\" run -w \"#{osw_path}\""
  puts cmd
  system(cmd)
end

#test_good_argument_valuesObject

def teardown end



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/measures/adjust_dhw_setpoint/tests/adjust_dhw_setpoint_test.rb', line 22

def test_good_argument_values
  # create an instance of the measure
  measure = AdjustDHWSetpoint.new

  # create runner with empty OSW
  osw = OpenStudio::WorkflowJSON.new
  runner = OpenStudio::Measure::OSRunner.new(osw)

  # load the test model
  translator = OpenStudio::OSVersion::VersionTranslator.new
  path = "#{File.dirname(__FILE__)}/SmallHotel-2A.osm"
  model = translator.loadModel(path)
  assert(!model.empty?)
  model = model.get

  # get arguments
  arguments = measure.arguments(model)
  argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)

  # create hash of argument values.
  # If the argument has a default that you want to use, you don't need it in the hash
  args_hash = {}
  args_hash['stp_adj_method'] = 'By Absolute Temperature'   # 'By Setback Degree'
  args_hash['flex_stp_1'] = '140'
  args_hash['flex_hrs_1'] = '9:00-11:00'
  args_hash['flex_stp_2'] = '170'
  args_hash['flex_hrs_2'] = '00:00-9:00'
  args_hash['flex_stp_3'] = '120'
  args_hash['flex_hrs_3'] = '11:00-13:00'
  args_hash['flex_stp_4'] = '170'
  args_hash['flex_hrs_4'] = '13:00-24:00'
  # using defaults values from measure.rb for other arguments

  # populate argument with specified hash value if specified
  arguments.each do |arg|
    temp_arg_var = arg.clone
    if args_hash.key?(arg.name)
      assert(temp_arg_var.setValue(args_hash[arg.name]))
    end
    argument_map[arg.name] = temp_arg_var
  end
  puts argument_map.values.inspect
  # flex1
  # flex_hrs1

  # run the measure
  measure.run(model, runner, argument_map)
  result = runner.result

  # assert that it ran correctly
  assert_equal('Success', result.value.valueName)

  # show the output
  show_output(result)

  # save the model to test output directory
  output_file_path = "#{File.dirname(__FILE__)}//output/test_output.osm"
  model.save(output_file_path, true)

  # test run the modified model
  osw = {}
  osw["weather_file"] = File.join(File.dirname(__FILE__ ), "CZ06RV2.epw")
  osw["seed_file"] = output_file_path
  osw_path = "#{File.dirname(__FILE__)}//output/test_output.osw"
  File.open(osw_path, 'w') do |f|
    f << JSON.pretty_generate(osw)
  end
  cli_path = OpenStudio.getOpenStudioCLI
  cmd = "\"#{cli_path}\" run -w \"#{osw_path}\""
  puts cmd
  system(cmd)
end