openstudio-workflow 1.0.0.pat1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +16 -68
- data/Rakefile +9 -9
- data/bin/openstudio_cli +786 -0
- data/lib/openstudio/workflow/adapters/input/local.rb +97 -0
- data/lib/openstudio/workflow/adapters/output/local.rb +90 -0
- data/lib/openstudio/workflow/adapters/output/socket.rb +70 -0
- data/lib/openstudio/workflow/{jobs/run_preflight/run_preflight.rb → adapters/output/web.rb} +37 -19
- data/lib/openstudio/workflow/{adapter.rb → adapters/output_adapter.rb} +53 -51
- data/lib/openstudio/workflow/job.rb +22 -0
- data/lib/openstudio/workflow/jobs/{run_energyplus → resources}/monthly_report.idf +0 -0
- data/lib/openstudio/workflow/jobs/run_energyplus.rb +49 -0
- data/lib/openstudio/workflow/jobs/run_ep_measures.rb +55 -0
- data/lib/openstudio/workflow/jobs/run_initialization.rb +136 -0
- data/lib/openstudio/workflow/jobs/run_os_measures.rb +59 -0
- data/lib/openstudio/workflow/jobs/run_postprocess.rb +53 -0
- data/lib/openstudio/workflow/jobs/run_preprocess.rb +81 -0
- data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +86 -0
- data/lib/openstudio/workflow/jobs/run_translation.rb +49 -0
- data/lib/openstudio/workflow/multi_delegator.rb +1 -3
- data/lib/openstudio/workflow/registry.rb +137 -0
- data/lib/openstudio/workflow/run.rb +182 -221
- data/lib/openstudio/workflow/time_logger.rb +1 -1
- data/lib/openstudio/workflow/util/energyplus.rb +564 -0
- data/lib/openstudio/workflow/util/io.rb +33 -0
- data/lib/openstudio/workflow/util/measure.rb +520 -0
- data/lib/openstudio/workflow/util/model.rb +100 -0
- data/lib/openstudio/workflow/util/post_process.rb +177 -0
- data/lib/openstudio/workflow/util/weather_file.rb +108 -0
- data/lib/openstudio/workflow/util.rb +14 -0
- data/lib/openstudio/workflow/version.rb +1 -1
- data/lib/openstudio/workflow_json.rb +399 -0
- data/lib/openstudio/workflow_runner.rb +213 -0
- data/lib/openstudio-workflow.rb +13 -118
- metadata +45 -85
- data/lib/openstudio/extended_runner.rb +0 -105
- data/lib/openstudio/workflow/adapters/local.rb +0 -101
- data/lib/openstudio/workflow/adapters/mongo.rb +0 -227
- data/lib/openstudio/workflow/jobs/lib/apply_measures.rb +0 -253
- data/lib/openstudio/workflow/jobs/run_energyplus/run_energyplus.rb +0 -314
- data/lib/openstudio/workflow/jobs/run_openstudio/run_openstudio.rb +0 -230
- data/lib/openstudio/workflow/jobs/run_postprocess/run_postprocess.rb +0 -110
- data/lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb +0 -471
- data/lib/openstudio/workflow/jobs/run_runmanager/run_runmanager.rb +0 -247
- data/lib/openstudio/workflow/jobs/run_xml/run_xml.rb +0 -279
data/lib/openstudio-workflow.rb
CHANGED
@@ -17,138 +17,33 @@
|
|
17
17
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
18
|
######################################################################
|
19
19
|
|
20
|
-
require 'pp'
|
21
|
-
require 'rubyXL'
|
22
|
-
require 'multi_json'
|
23
|
-
require 'colored'
|
24
20
|
require 'fileutils'
|
25
|
-
require '
|
26
|
-
require 'json' # needed for a single pretty generate call
|
21
|
+
require 'json'
|
27
22
|
require 'pathname'
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
require 'openstudio/workflow/multi_delegator'
|
37
|
-
require 'openstudio/workflow/run'
|
38
|
-
require 'openstudio/workflow/jobs/lib/apply_measures'
|
39
|
-
require 'openstudio/workflow/time_logger'
|
40
|
-
|
24
|
+
require_relative 'openstudio/workflow/version'
|
25
|
+
require_relative 'openstudio/workflow/multi_delegator'
|
26
|
+
require_relative 'openstudio/workflow/run'
|
27
|
+
require_relative 'openstudio/workflow/job'
|
28
|
+
require_relative 'openstudio/workflow/time_logger'
|
29
|
+
require_relative 'openstudio/workflow/registry'
|
30
|
+
require_relative 'openstudio/workflow/util'
|
41
31
|
require 'openstudio'
|
42
|
-
|
43
|
-
|
44
|
-
ENV['OPENSTUDIO_WORKFLOW'] = 'true'
|
45
|
-
|
46
|
-
# some core extensions
|
47
|
-
class String
|
48
|
-
def to_underscore
|
49
|
-
gsub(/::/, '/')
|
50
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
51
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
52
|
-
.tr('-', '_')
|
53
|
-
.downcase
|
54
|
-
end
|
55
|
-
end
|
32
|
+
require_relative 'openstudio/workflow_runner'
|
56
33
|
|
57
34
|
module OpenStudio
|
58
35
|
module Workflow
|
59
36
|
extend self
|
60
37
|
|
61
|
-
# Create a new workflow instance using the defined adapter and UUID
|
62
|
-
def load(adapter_name, run_directory, options = {})
|
63
|
-
defaults = { adapter_options: {} }
|
64
|
-
options = defaults.merge(options)
|
65
|
-
# We don't have deep merge so just check for the rails_env
|
66
|
-
options[:adapter_options][:rails_env] = :development unless options[:adapter_options][:rails_env]
|
67
|
-
|
68
|
-
# Convert various paths to absolute paths
|
69
|
-
if options[:adapter_options] && options[:adapter_options][:mongoid_path] &&
|
70
|
-
(Pathname.new options[:adapter_options][:mongoid_path]).absolute? == false
|
71
|
-
options[:adapter_options][:mongoid_path] = File.expand_path options[:adapter_options][:mongoid_path]
|
72
|
-
end
|
73
|
-
if options[:analysis_root_path] &&
|
74
|
-
(Pathname.new options[:analysis_root_path]).absolute? == false
|
75
|
-
options[:analysis_root_path] = File.expand_path options[:analysis_root_path]
|
76
|
-
end
|
77
|
-
unless (Pathname.new run_directory).absolute?
|
78
|
-
# relative to wherever you are running the script
|
79
|
-
run_directory = File.expand_path run_directory
|
80
|
-
end
|
81
|
-
adapter = load_adapter adapter_name, options[:adapter_options]
|
82
|
-
run_klass = OpenStudio::Workflow::Run.new(adapter, run_directory, options)
|
83
|
-
# return the run class
|
84
|
-
run_klass
|
85
|
-
end
|
86
|
-
|
87
|
-
# predefined method that simply runs EnergyPlus in the specified directory. It does not apply any workflow steps
|
88
|
-
# such as preprocessing / postprocessing. The directory must have the IDF and EPW file in the folder. The
|
89
|
-
# simulations will run in the directory/run path
|
90
|
-
#
|
91
|
-
# @param adapter_name [String] Type of adapter, local or mongo.
|
92
|
-
# @param run_directory [String] Path to where the simulation is to run
|
93
|
-
# @param options [Hash] List of options for the adapter
|
94
|
-
def run_energyplus(adapter_name, run_directory, options = {})
|
95
|
-
unless (Pathname.new run_directory).absolute?
|
96
|
-
# relative to wherever you are running the script
|
97
|
-
run_directory = File.expand_path run_directory
|
98
|
-
end
|
99
|
-
|
100
|
-
transitions = [
|
101
|
-
{ from: :queued, to: :preflight },
|
102
|
-
{ from: :preflight, to: :energyplus },
|
103
|
-
{ from: :energyplus, to: :finished }
|
104
|
-
]
|
105
|
-
|
106
|
-
states = [
|
107
|
-
{ state: :queued, options: { initial: true } },
|
108
|
-
{ state: :preflight, options: { after_enter: :run_preflight } },
|
109
|
-
{ state: :energyplus, options: { after_enter: :run_energyplus } },
|
110
|
-
{ state: :finished },
|
111
|
-
{ state: :errored }
|
112
|
-
]
|
113
|
-
options = {
|
114
|
-
transitions: transitions,
|
115
|
-
states: states
|
116
|
-
}
|
117
|
-
|
118
|
-
adapter = load_adapter adapter_name, options[:adapter_options]
|
119
|
-
run_klass = OpenStudio::Workflow::Run.new(adapter, run_directory, options)
|
120
|
-
|
121
|
-
run_klass
|
122
|
-
end
|
123
|
-
|
124
38
|
# Extract an archive to a specific location
|
39
|
+
#
|
125
40
|
# @param archive_filename [String] Path and name of the file to extract
|
126
41
|
# @param destination [String] Path to extract to
|
127
42
|
# @param overwrite [Boolean] If true, will overwrite any extracted file that may already exist
|
43
|
+
#
|
128
44
|
def extract_archive(archive_filename, destination, overwrite = true)
|
129
|
-
|
130
|
-
|
131
|
-
f_path = File.join(destination, f.name)
|
132
|
-
FileUtils.mkdir_p(File.dirname(f_path))
|
133
|
-
|
134
|
-
if File.exist?(f_path) && overwrite
|
135
|
-
FileUtils.rm_rf(f_path)
|
136
|
-
zf.extract(f, f_path)
|
137
|
-
elsif !File.exist? f_path
|
138
|
-
zf.extract(f, f_path)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
def load_adapter(name, adapter_options = {})
|
147
|
-
require "openstudio/workflow/adapters/#{name.downcase}"
|
148
|
-
klass_name = name.to_s.split('_').map(&:capitalize) * ''
|
149
|
-
# pp "#{klass_name} is the adapter class name"
|
150
|
-
klass = OpenStudio::Workflow::Adapters.const_get(klass_name).new(adapter_options)
|
151
|
-
klass
|
45
|
+
zf = OpenStudio::UnzipFile.new(archive_filename)
|
46
|
+
zf.extractAllFiles(destination)
|
152
47
|
end
|
153
48
|
end
|
154
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstudio-workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Long
|
8
|
+
- Henry Horsey
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -25,103 +26,62 @@ dependencies:
|
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '1.6'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: json-schema
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- -
|
32
|
+
- - ~>
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: multi_json
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.10.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.10.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: colored
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.2'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.2'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubyXL
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
38
|
requirements:
|
73
39
|
- - ~>
|
74
40
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ~>
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 3.3.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubyzip
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.2.0
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ~>
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.2.0
|
97
|
-
description: Run OpenStudio based simulations using EnergyPlus
|
41
|
+
version: '0'
|
42
|
+
description: Run OpenStudio based measures and simulations using EnergyPlus
|
98
43
|
email:
|
99
44
|
- nicholas.long@nrel.gov
|
100
|
-
|
45
|
+
- henry.horsey@nrel.gov
|
46
|
+
executables:
|
47
|
+
- openstudio_cli
|
101
48
|
extensions: []
|
102
49
|
extra_rdoc_files: []
|
103
50
|
files:
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
108
|
-
- lib/openstudio
|
109
|
-
- lib/openstudio/workflow/
|
110
|
-
- lib/openstudio/workflow/
|
111
|
-
- lib/openstudio/workflow/
|
112
|
-
- lib/openstudio/workflow/
|
113
|
-
- lib/openstudio/workflow/
|
114
|
-
- lib/openstudio/workflow/
|
115
|
-
- lib/openstudio/workflow/jobs/
|
116
|
-
- lib/openstudio/workflow/jobs/
|
51
|
+
- CHANGELOG.md
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/openstudio_cli
|
55
|
+
- lib/openstudio-workflow.rb
|
56
|
+
- lib/openstudio/workflow/adapters/input/local.rb
|
57
|
+
- lib/openstudio/workflow/adapters/output/local.rb
|
58
|
+
- lib/openstudio/workflow/adapters/output/socket.rb
|
59
|
+
- lib/openstudio/workflow/adapters/output/web.rb
|
60
|
+
- lib/openstudio/workflow/adapters/output_adapter.rb
|
61
|
+
- lib/openstudio/workflow/job.rb
|
62
|
+
- lib/openstudio/workflow/jobs/resources/monthly_report.idf
|
63
|
+
- lib/openstudio/workflow/jobs/run_energyplus.rb
|
64
|
+
- lib/openstudio/workflow/jobs/run_ep_measures.rb
|
65
|
+
- lib/openstudio/workflow/jobs/run_initialization.rb
|
66
|
+
- lib/openstudio/workflow/jobs/run_os_measures.rb
|
67
|
+
- lib/openstudio/workflow/jobs/run_postprocess.rb
|
68
|
+
- lib/openstudio/workflow/jobs/run_preprocess.rb
|
69
|
+
- lib/openstudio/workflow/jobs/run_reporting_measures.rb
|
70
|
+
- lib/openstudio/workflow/jobs/run_translation.rb
|
117
71
|
- lib/openstudio/workflow/multi_delegator.rb
|
72
|
+
- lib/openstudio/workflow/registry.rb
|
118
73
|
- lib/openstudio/workflow/run.rb
|
119
74
|
- lib/openstudio/workflow/time_logger.rb
|
75
|
+
- lib/openstudio/workflow/util.rb
|
76
|
+
- lib/openstudio/workflow/util/energyplus.rb
|
77
|
+
- lib/openstudio/workflow/util/io.rb
|
78
|
+
- lib/openstudio/workflow/util/measure.rb
|
79
|
+
- lib/openstudio/workflow/util/model.rb
|
80
|
+
- lib/openstudio/workflow/util/post_process.rb
|
81
|
+
- lib/openstudio/workflow/util/weather_file.rb
|
120
82
|
- lib/openstudio/workflow/version.rb
|
121
|
-
- lib/openstudio
|
122
|
-
-
|
123
|
-
- CHANGELOG.md
|
124
|
-
- Rakefile
|
83
|
+
- lib/openstudio/workflow_json.rb
|
84
|
+
- lib/openstudio/workflow_runner.rb
|
125
85
|
homepage: https://github.com/NREL/OpenStudio-workflow-gem
|
126
86
|
licenses:
|
127
87
|
- LGPL
|
@@ -134,16 +94,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
94
|
requirements:
|
135
95
|
- - '>='
|
136
96
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
97
|
+
version: '2.0'
|
138
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
99
|
requirements:
|
140
|
-
- - '
|
100
|
+
- - '>='
|
141
101
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
102
|
+
version: '0'
|
143
103
|
requirements: []
|
144
104
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.6.7
|
146
106
|
signing_key:
|
147
107
|
specification_version: 4
|
148
|
-
summary: Workflow Manager
|
108
|
+
summary: OpenStudio Workflow Manager
|
149
109
|
test_files: []
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# Extend OS Runner to persist measure information throughout the workflow
|
2
|
-
class ExtendedRunner < OpenStudio::Ruleset::OSRunner
|
3
|
-
# Allow former arguments to be set and read
|
4
|
-
# TODO: Consider having the former arguments passed in in initialization, and define as attr_reader
|
5
|
-
attr_accessor :former_workflow_arguments
|
6
|
-
attr_accessor :past_results
|
7
|
-
attr_reader :workflow_arguments
|
8
|
-
|
9
|
-
# Add in @workflow_arguments
|
10
|
-
def initialize(multi_logger, analysis_hash, datapoint_hash)
|
11
|
-
@multi_logger = multi_logger
|
12
|
-
@analysis = analysis_hash
|
13
|
-
@datapoint = datapoint_hash
|
14
|
-
@workflow_arguments = nil
|
15
|
-
super()
|
16
|
-
end
|
17
|
-
|
18
|
-
def analysis
|
19
|
-
return @analysis
|
20
|
-
end
|
21
|
-
|
22
|
-
def datapoint
|
23
|
-
return @datapoint
|
24
|
-
end
|
25
|
-
|
26
|
-
# Take the OS Argument type and map it correctly to the argument value.
|
27
|
-
# OPENSTUDIO_ENUM( OSArgumentType,
|
28
|
-
# ((Boolean)(Bool)(0))
|
29
|
-
# ((Double)(Double)(1))
|
30
|
-
# ((Quantity)(Quantity)(2))
|
31
|
-
# ((Integer)(Int)(3))
|
32
|
-
# ((String)(String)(4))
|
33
|
-
# ((Choice)(Choice)(5))
|
34
|
-
# ((Path)(Path)(6))
|
35
|
-
# );
|
36
|
-
# @param os_argument_name [String] The string of the argument to check
|
37
|
-
# @param user_arguments [OSArgumentMap] Map of the arguments to check
|
38
|
-
def bad_os_typecasting(os_argument_name, user_arguments)
|
39
|
-
out = nil
|
40
|
-
user_arguments.each do |arg_name, arg|
|
41
|
-
# get the type cast value
|
42
|
-
next unless os_argument_name == arg_name
|
43
|
-
|
44
|
-
case arg.type.valueName
|
45
|
-
when 'Boolean'
|
46
|
-
out = arg.valueAsBool if arg.hasValue
|
47
|
-
when 'Double'
|
48
|
-
out = arg.valueAsDouble if arg.hasValue
|
49
|
-
when 'Quantity'
|
50
|
-
warn 'This OpenStudio Argument Type is deprecated'
|
51
|
-
when 'Integer'
|
52
|
-
out = arg.valueAsInteger if arg.hasValue
|
53
|
-
when 'String'
|
54
|
-
out = arg.valueAsString if arg.hasValue
|
55
|
-
when 'Choice'
|
56
|
-
out = arg.valueAsString if arg.hasValue
|
57
|
-
when 'Path'
|
58
|
-
out = arg.valueAsPath.to_s if arg.hasValue
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
out
|
63
|
-
end
|
64
|
-
|
65
|
-
# Overloaded argument parsing
|
66
|
-
def validateUserArguments(script_arguments, user_arguments)
|
67
|
-
@workflow_arguments = {}
|
68
|
-
user_arguments.each do |hash|
|
69
|
-
value = bad_os_typecasting(hash, user_arguments)
|
70
|
-
@workflow_arguments[hash.to_sym] = value if value
|
71
|
-
end
|
72
|
-
|
73
|
-
super
|
74
|
-
end
|
75
|
-
|
76
|
-
# Overload registerInfo
|
77
|
-
def registerInfo(message)
|
78
|
-
super
|
79
|
-
@multi_logger.info message
|
80
|
-
end
|
81
|
-
|
82
|
-
# Overload registerInfo
|
83
|
-
def registerWarning(message)
|
84
|
-
super
|
85
|
-
@multi_logger.warn message
|
86
|
-
end
|
87
|
-
|
88
|
-
# Overload registerError
|
89
|
-
def registerError(message)
|
90
|
-
super
|
91
|
-
@multi_logger.error message
|
92
|
-
end
|
93
|
-
|
94
|
-
# Overload registerInitialCondition
|
95
|
-
def registerInitialCondition(message)
|
96
|
-
super
|
97
|
-
@multi_logger.info message
|
98
|
-
end
|
99
|
-
|
100
|
-
# Overload registerFinalCondition
|
101
|
-
def registerFinalCondition(message)
|
102
|
-
super
|
103
|
-
@multi_logger.info message
|
104
|
-
end
|
105
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
######################################################################
|
2
|
-
# Copyright (c) 2008-2014, Alliance for Sustainable Energy.
|
3
|
-
# All rights reserved.
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License as published by the Free Software Foundation; either
|
8
|
-
# version 2.1 of the License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This library is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# Lesser General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU Lesser General Public
|
16
|
-
# License along with this library; if not, write to the Free Software
|
17
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
-
######################################################################
|
19
|
-
|
20
|
-
require_relative '../adapter'
|
21
|
-
|
22
|
-
# Local file based workflow
|
23
|
-
module OpenStudio
|
24
|
-
module Workflow
|
25
|
-
module Adapters
|
26
|
-
class Local < Adapter
|
27
|
-
def initialize(options = {})
|
28
|
-
super
|
29
|
-
end
|
30
|
-
|
31
|
-
# Tell the system that the process has started
|
32
|
-
def communicate_started(directory, _options = {})
|
33
|
-
# Watch out for namespace conflicts (::Time is okay but Time is OpenStudio::Time)
|
34
|
-
File.open("#{directory}/started.job", 'w') { |f| f << "Started Workflow #{::Time.now}" }
|
35
|
-
end
|
36
|
-
|
37
|
-
# Get the data point from the path
|
38
|
-
def get_datapoint(directory, options = {})
|
39
|
-
defaults = { datapoint_filename: 'datapoint.json', format: 'json' }
|
40
|
-
options = defaults.merge(options)
|
41
|
-
|
42
|
-
# how do we log within this file?
|
43
|
-
if File.exist? "#{directory}/#{options[:datapoint_filename]}"
|
44
|
-
::JSON.parse(File.read("#{directory}/#{options[:datapoint_filename]}"), symbolize_names: true)
|
45
|
-
else
|
46
|
-
fail "Data point file does not exist for #{directory}/#{options[:datapoint_filename]}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Get the Problem/Analysis definition from the local file
|
51
|
-
# TODO: rename this to get_analysis_definintion (or something like that)
|
52
|
-
def get_problem(directory, options = {})
|
53
|
-
defaults = { problem_filename: 'problem.json', format: 'json' }
|
54
|
-
options = defaults.merge(options)
|
55
|
-
|
56
|
-
if File.exist? "#{directory}/#{options[:problem_filename]}"
|
57
|
-
::JSON.parse(File.read("#{directory}/#{options[:problem_filename]}"), symbolize_names: true)
|
58
|
-
else
|
59
|
-
fail "Problem file does not exist for #{directory}/#{options[:problem_filename]}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def communicate_intermediate_result(_directory)
|
64
|
-
# noop
|
65
|
-
end
|
66
|
-
|
67
|
-
def communicate_complete(directory)
|
68
|
-
File.open("#{directory}/finished.job", 'w') { |f| f << "Finished Workflow #{::Time.now}" }
|
69
|
-
end
|
70
|
-
|
71
|
-
# Final state of the simulation. The os_directory is the run directory and may be needed to
|
72
|
-
# zip up the results of the simuation.
|
73
|
-
def communicate_failure(directory)
|
74
|
-
File.open("#{directory}/failed.job", 'w') { |f| f << "Failed Workflow #{::Time.now}" }
|
75
|
-
# @communicate_module.communicate_failure(@communicate_object, os_directory)
|
76
|
-
end
|
77
|
-
|
78
|
-
def communicate_results(directory, results)
|
79
|
-
zip_results(directory)
|
80
|
-
|
81
|
-
if results.is_a? Hash
|
82
|
-
File.open("#{directory}/data_point_out.json", 'w') { |f| f << JSON.pretty_generate(results) }
|
83
|
-
else
|
84
|
-
pp "Unknown datapoint result type. Please handle #{results.class}"
|
85
|
-
# data_point_json_path = OpenStudio::Path.new(run_dir) / OpenStudio::Path.new('data_point_out.json')
|
86
|
-
# os_data_point.saveJSON(data_point_json_path, true)
|
87
|
-
end
|
88
|
-
# end
|
89
|
-
end
|
90
|
-
|
91
|
-
# For the local adapter send back a handle to a file to append the data. For this adapter
|
92
|
-
# the log messages are likely to be the same as the run.log messages.
|
93
|
-
# ?: do we really want two local logs from the Local adapter? One is in the run dir and the other is in the root
|
94
|
-
def get_logger(directory, _options = {})
|
95
|
-
@log ||= File.open("#{directory}/local_adapter.log", 'w')
|
96
|
-
@log
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|