openstudio-recommendation-engine 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ module OpenStudio
27
27
 
28
28
  def check_measures
29
29
  measure_checks = Dir.glob("#{@path_to_measures}/**/recommendation.rb")
30
-
30
+
31
31
  applicable_measures = []
32
32
  debug_outputs = []
33
33
 
@@ -40,27 +40,103 @@ module OpenStudio
40
40
  measure = Object.const_get(measure_class_name).new
41
41
 
42
42
  if @model
43
- results_json, debug_json = measure.check_applicability(@model)
44
- if results_json
45
- applicable_measures << results_json
43
+ results_hash, debug_hash = measure.check_applicability(@model)
44
+ if results_hash
45
+ applicable_measures << results_hash
46
46
  else
47
47
  puts "measure #{measure_class_name} not applicable"
48
48
  end
49
- debug_outputs << debug_json
49
+ debug_outputs << debug_hash
50
50
  else
51
51
  raise "No model passed into the recommendation engine"
52
52
  end
53
53
 
54
54
  end
55
-
56
- #convert the output to JSON
57
- applicable_measures_json = JSON.pretty_generate(applicable_measures)
58
- debug_output_json = JSON.pretty_generate(debug_outputs)
59
55
 
60
- return [applicable_measures_json,debug_output_json]
56
+ return [applicable_measures,debug_outputs]
61
57
 
62
58
  end
63
59
 
60
+ # measures_hash looks like
61
+ # {
62
+ # "measure": {
63
+ # "uid": "123-fake-daylight-uid",
64
+ # "name": "AddEconomizer",
65
+ # "spaces": [
66
+ # "427_office_1_North Perimeter Space",
67
+ # "427_office_1_South Perimeter Space",
68
+ # "427_office_1_West Perimeter Space",
69
+ # "427_office_1_East Perimeter Space"
70
+ # ]
71
+ # "arguments": {
72
+ # "cost_per_thing":50,
73
+ # "input_2":true,
74
+ # }
75
+ # },
76
+ # "measure": {
77
+ # "uid": "123-fake-daylight-uid",
78
+ # "name": "AddDaylightControls",
79
+ # "spaces": [
80
+ # "427_office_1_North Perimeter Space",
81
+ # "427_office_1_South Perimeter Space",
82
+ # "427_office_1_West Perimeter Space",
83
+ # "427_office_1_East Perimeter Space"
84
+ # ]
85
+ # }
86
+ # }
87
+
88
+ def apply_measures(model, measures_hash)
89
+
90
+ messages = {}
91
+
92
+ #loop through each measure in the measures_hash
93
+ measures_hash.each do |m|
94
+ puts JSON.pretty_generate(m)
95
+ measure_name = m['measure']['name']
96
+ puts measure_name
97
+ messages[measure_name] = []
98
+ puts File.expand_path(measure_name)
99
+ require "#{@path_to_measures}/#{measure_name}/measure"
100
+
101
+
102
+ #make os argument vector and assign values from measures_json
103
+ measure = Object.const_get(measure_name).new
104
+
105
+ arguments = measure.arguments(model)
106
+ runner = OpenStudio::Ruleset::OSRunner.new
107
+
108
+ argument_map = OpenStudio::Ruleset::OSArgumentMap.new
109
+ arguments.each do |arg|
110
+ argument_map[arg.name] = arg.clone
111
+ end
112
+
113
+ if m['measure']['arguments']
114
+ m['measure']['arguments'].each do |arg_name, arg_val|
115
+ v = argument_map[arg_name]
116
+ raise "Could not find argument map in measure" if not v
117
+ value_set = v.setValue(arg_val)
118
+ raise "Could not set argument #{arg_name} of value #{arg_val} on model" unless value_set
119
+ argument_map[arg_name] = v.clone
120
+ end
121
+ end
122
+
123
+ #run the measure
124
+ measure.run(model, runner, argument_map)
125
+
126
+ #log the messages from when running the measure
127
+ result = runner.result
128
+ messages[measure_name] << result.initialCondition.get.logMessage if result.initialCondition.is_initialized
129
+ messages[measure_name] << result.finalCondition.get.logMessage if result.finalCondition.is_initialized
130
+ result.warnings.each { |w| messages[measure_name] << w.logMessage}
131
+ result.errors.each { |w| messages[measure_name] << w.logMessage}
132
+ result.info.each { |w| messages[measure_name] << w.logMessage}
133
+
134
+ end #next measure
135
+
136
+ return model,messages
137
+
138
+ end #apply_measures
139
+
64
140
  end
65
141
  end
66
142
 
@@ -19,6 +19,6 @@
19
19
 
20
20
  module OpenStudio
21
21
  module RecommendationEngine
22
- VERSION = "0.1.4"
22
+ VERSION = "0.1.5"
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstudio-recommendation-engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nicholas Long