openstudio-metadata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +49 -0
- data/.rakeTasks +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +9 -0
- data/.travis.yml +20 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +23 -0
- data/README.md +66 -0
- data/Rakefile +22 -0
- data/doc_templates/LICENSE.md +27 -0
- data/doc_templates/README.md.erb +42 -0
- data/doc_templates/copyright_erb.txt +36 -0
- data/doc_templates/copyright_js.txt +4 -0
- data/doc_templates/copyright_ruby.txt +34 -0
- data/lib/.DS_Store +0 -0
- data/lib/files/brick/1.1/Brick.ttl +11144 -0
- data/lib/files/haystack/3.9.9/defs.ttl +5205 -0
- data/lib/files/mappings.json +388 -0
- data/lib/files/templates.yaml +361 -0
- data/lib/measures/haystack/measure.rb +574 -0
- data/lib/measures/haystack/measure.xml +83 -0
- data/lib/openstudio/metadata/controls.rb +220 -0
- data/lib/openstudio/metadata/creator.rb +432 -0
- data/lib/openstudio/metadata/helpers.rb +184 -0
- data/lib/openstudio/metadata/serializer.rb +141 -0
- data/lib/openstudio/metadata/version.rb +40 -0
- data/lib/openstudio/metadata/writer.rb +107 -0
- data/lib/openstudio/metadata.rb +55 -0
- data/lib/openstudio-metadata.rb +1 -0
- data/openstudio-metadata.gemspec +32 -0
- data/test.rb +15 -0
- metadata +165 -0
@@ -0,0 +1,184 @@
|
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
module OpenStudio
|
36
|
+
module Metadata
|
37
|
+
module Helpers
|
38
|
+
|
39
|
+
##
|
40
|
+
# Format with no spaces or '-' (can be used as EMS var name)
|
41
|
+
##
|
42
|
+
# @param [String] name
|
43
|
+
def create_ems_str(name)
|
44
|
+
return name.gsub(/[\s-]/, '_').to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Create a UUID and format as a Haystack ref (ie, "r:xxxxx")
|
49
|
+
##
|
50
|
+
# @return [String]
|
51
|
+
def haystack_create_uuid
|
52
|
+
return "r:#{OpenStudio.removeBraces(OpenStudio.createUUID)}"
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Return string formatted for Ref (ie, "r:xxxxx") with uuid of object
|
57
|
+
##
|
58
|
+
# @param [OpenStudio::UUID] id
|
59
|
+
# @return [String]
|
60
|
+
def haystack_format_as_ref(id)
|
61
|
+
return "r:#{OpenStudio.removeBraces(id)}"
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Return string formatted for strings (ie, "s:xxxxx")
|
66
|
+
##
|
67
|
+
# @param [] str An object which can be converted to a string
|
68
|
+
# @return [String]
|
69
|
+
def haystack_format_as_str(str)
|
70
|
+
return "s:#{str}"
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Return string formatted for numbers (ie, "n:xxxxx")
|
75
|
+
##
|
76
|
+
# @param [] str An object which can be converted to a string
|
77
|
+
# @return [String]
|
78
|
+
def haystack_format_as_num(str)
|
79
|
+
return "n:#{str}"
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Create both an output variable and an energy management system sensor and register them to the model
|
84
|
+
##
|
85
|
+
# @param [String] system_node_property One of the 'System Node Properties', see E+ IO reference node list outputs
|
86
|
+
# @param [OpenStudio::Model::Node] node Node of interest
|
87
|
+
# @param [String] ems_name Desired name for EMS variable
|
88
|
+
# @param [OpenStudio::Model::Model] model
|
89
|
+
# @param [String] reporting_frequency See E+ IO reference reporting frequency for options
|
90
|
+
# @param [Boolean] bcvtb Flag to export OutputVariable to bcvtb
|
91
|
+
def create_output_variable_and_ems_sensor(system_node_property:, node:, ems_name:, model:, reporting_frequency: 'timestep', bcvtb: true)
|
92
|
+
name = create_ems_str(ems_name)
|
93
|
+
output_variable = OpenStudio::Model::OutputVariable.new(system_node_property, model)
|
94
|
+
output_variable.setKeyValue(node.name.to_s)
|
95
|
+
output_variable.setReportingFrequency(reporting_frequency)
|
96
|
+
output_variable.setName(name)
|
97
|
+
output_variable.setExportToBCVTB(bcvtb)
|
98
|
+
|
99
|
+
# EMS sensors are used to declare an Erl variable that is linked to E+ output variables or meters
|
100
|
+
sensor = OpenStudio::Model::EnergyManagementSystemSensor.new(model, output_variable)
|
101
|
+
|
102
|
+
# The key reference for the specified output variable
|
103
|
+
sensor.setKeyName(node.handle.to_s)
|
104
|
+
|
105
|
+
# Unique name for the sensor that becomes the name of a variable for us in Erl programs.
|
106
|
+
sensor.setName("EMS_#{name}")
|
107
|
+
return output_variable
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_output_meter(model, meter_name, reporting_frequency: 'timestep')
|
111
|
+
meter = OpenStudio::Model::OutputMeter.new(model)
|
112
|
+
meter.setName(meter_name)
|
113
|
+
meter.setReportingFrequency(reporting_frequency)
|
114
|
+
return meter
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_point_timevars(outvar_time, siteRef)
|
118
|
+
# this function will add haystack tag to the time-variables created by user.
|
119
|
+
# the time-variables are also written to variables.cfg file to coupling energyplus
|
120
|
+
# the uuid is unique to be used for mapping purpose
|
121
|
+
# the point_json generated here caontains the tags for the tim-variables
|
122
|
+
point_json = {}
|
123
|
+
# id = outvar_time.keyValue.to_s + outvar_time.name.to_s
|
124
|
+
uuid = haystack_create_uuid
|
125
|
+
point_json[:id] = uuid
|
126
|
+
# point_json[:source] = create_str("EnergyPlus")
|
127
|
+
# point_json[:type] = "Output:Variable"
|
128
|
+
# point_json[:name] = create_str(outvar_time.name.to_s)
|
129
|
+
# point_json[:variable] = create_str(outvar_time.name)
|
130
|
+
point_json[:dis] = haystack_format_as_str(outvar_time.nameString)
|
131
|
+
point_json[:siteRef] = haystack_format_as_ref(siteRef)
|
132
|
+
point_json[:point] = 'm:'
|
133
|
+
point_json[:cur] = 'm:'
|
134
|
+
point_json[:curStatus] = 's:disabled'
|
135
|
+
|
136
|
+
return point_json, uuid
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_mapping_timevars(outvar_time, uuid)
|
140
|
+
# this function will use the uuid generated from create_point_timevars(), to make a mapping.
|
141
|
+
# the uuid is unique to be used for mapping purpose; uuid is the belt to connect point_json and mapping_json
|
142
|
+
# the mapping_json below contains all the necessary tags
|
143
|
+
mapping_json = {}
|
144
|
+
mapping_json[:id] = uuid
|
145
|
+
mapping_json[:source] = 'EnergyPlus'
|
146
|
+
mapping_json[:name] = 'EMS'
|
147
|
+
mapping_json[:type] = outvar_time.nameString
|
148
|
+
mapping_json[:variable] = ''
|
149
|
+
|
150
|
+
return mapping_json
|
151
|
+
end
|
152
|
+
|
153
|
+
def create_point_uuid(type, id, siteRef, equipRef, floorRef, where, what, measurement, kind, unit)
|
154
|
+
point_json = {}
|
155
|
+
uuid = haystack_create_uuid
|
156
|
+
point_json[:id] = uuid
|
157
|
+
point_json[:dis] = haystack_format_as_str(id)
|
158
|
+
point_json[:siteRef] = haystack_format_as_ref(siteRef)
|
159
|
+
point_json[:equipRef] = haystack_format_as_ref(equipRef)
|
160
|
+
point_json[:floorRef] = haystack_format_as_ref(floorRef)
|
161
|
+
point_json[:point] = 'm:'
|
162
|
+
point_json[type.to_s] = 'm:'
|
163
|
+
point_json[measurement.to_s] = 'm:'
|
164
|
+
point_json[where.to_s] = 'm:'
|
165
|
+
point_json[what.to_s] = 'm:'
|
166
|
+
point_json[:kind] = haystack_format_as_str(kind)
|
167
|
+
point_json[:unit] = haystack_format_as_str(unit)
|
168
|
+
point_json[:cur] = 'm:'
|
169
|
+
point_json[:curStatus] = 's:disabled'
|
170
|
+
return point_json, uuid
|
171
|
+
end
|
172
|
+
|
173
|
+
def create_mapping_output_uuid(emsName, uuid)
|
174
|
+
json = {}
|
175
|
+
json[:id] = haystack_format_as_ref(uuid)
|
176
|
+
json[:source] = 'Ptolemy'
|
177
|
+
json[:name] = ''
|
178
|
+
json[:type] = ''
|
179
|
+
json[:variable] = emsName
|
180
|
+
return json
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
require 'rdf'
|
36
|
+
require 'linkeddata'
|
37
|
+
require 'sparql/client'
|
38
|
+
|
39
|
+
module OpenStudio
|
40
|
+
module Metadata
|
41
|
+
##
|
42
|
+
# Class to serialize entities into Brick Graph
|
43
|
+
##
|
44
|
+
# @example Use BrickGraph to make a `ttl` from a list of entities
|
45
|
+
# entities = creator.entities
|
46
|
+
# brick_graph = BrickGraph.new
|
47
|
+
# brick_graph.create_graph_from_entities(entities)
|
48
|
+
# ttl = brick_graph.dump(:ttl)
|
49
|
+
class BrickGraph
|
50
|
+
# Returns new instance of BrickGraph
|
51
|
+
# @param building_namespace [String] used for `bldg` prefix in ttl
|
52
|
+
def initialize(building_namespace: 'http://example.com/mybuilding#')
|
53
|
+
@brick = RDF::Vocabulary.new('https://brickschema.org/schema/1.1/Brick#')
|
54
|
+
@bldg = RDF::Vocabulary.new(building_namespace)
|
55
|
+
@prefixes = {
|
56
|
+
rdf: RDF.to_uri,
|
57
|
+
rdfs: RDF::RDFS.to_uri,
|
58
|
+
brick: @brick,
|
59
|
+
bldg: @bldg
|
60
|
+
}
|
61
|
+
@g = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Creates graph from list of entities
|
66
|
+
##
|
67
|
+
# @param entities [Array<Hash>] list of entities from {Creator.entities}
|
68
|
+
def create_from_entities(entities)
|
69
|
+
@g = RDF::Repository.new
|
70
|
+
entities.each do |entity|
|
71
|
+
@g << RDF::Statement.new(@bldg[entity['id']], RDF.type, @brick[entity['type']])
|
72
|
+
@g << RDF::Statement.new(@bldg[entity['id']], RDF::RDFS.label, entity['dis'])
|
73
|
+
if entity.key? 'relationships'
|
74
|
+
entity['relationships'].each do |relationship, reference|
|
75
|
+
@g << RDF::Statement.new(@bldg[entity['id']], @brick[relationship], @bldg[reference])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Outputs Brick graph in desired `format`
|
83
|
+
##
|
84
|
+
# @param format [Symbol] A symbol declaring to format to dump the graph as
|
85
|
+
# @see https://rubydoc.info/github/ruby-rdf/rdf/RDF/Enumerable#dump-instance_method
|
86
|
+
##
|
87
|
+
# @return [String] A string representation of the graph in the desired format
|
88
|
+
#
|
89
|
+
def dump(format = :ttl)
|
90
|
+
return @g.dump(format, prefixes: @prefixes)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Class to serialize entities into a Haystack JSON
|
96
|
+
##
|
97
|
+
# @example Use Haystack to make JSON from list of entities
|
98
|
+
# entities = creator.entities
|
99
|
+
# haystack = Haystack.new
|
100
|
+
# haystack_json = haystack.create_haystack_from_entities(entities)
|
101
|
+
class Haystack
|
102
|
+
##
|
103
|
+
# Creates Haystack JSON from list of entities
|
104
|
+
##
|
105
|
+
# @param entities [Array<Hash>] list of entities from {Creator.entities}
|
106
|
+
##
|
107
|
+
# @return [String] Haystack JSON representation of entities
|
108
|
+
def create_from_entities(entities)
|
109
|
+
cols = []
|
110
|
+
rows = []
|
111
|
+
entities.each do |entity|
|
112
|
+
entity.keys.each do |k|
|
113
|
+
if k == 'add_tags'
|
114
|
+
(tags = entity[k]) && tags.each { |tag| entity.store(tag, ':m') && entity.delete(k) }
|
115
|
+
elsif k == 'type'
|
116
|
+
(t_tags = entity[k].split('-')) && t_tags.each { |t_tag| entity.store(t_tag, ':m') } && entity.delete(k)
|
117
|
+
elsif k == 'relationships'
|
118
|
+
relationships = entity[k]
|
119
|
+
relationships.each do |relationship, reference|
|
120
|
+
entity.store(relationship, reference)
|
121
|
+
end
|
122
|
+
entity.delete(k)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
rows.append(entity)
|
126
|
+
end
|
127
|
+
rows.each do |row|
|
128
|
+
row.keys.each do |k|
|
129
|
+
unless cols.include?('name' => k)
|
130
|
+
cols.append('name' => k)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
data = { 'meta' => { 'ver' => '3.0' },
|
135
|
+
'cols' => cols,
|
136
|
+
'rows' => rows }
|
137
|
+
return JSON.pretty_generate(data)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
|
36
|
+
module OpenStudio
|
37
|
+
module Metadata
|
38
|
+
VERSION = '0.0.1'.freeze
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
require 'json'
|
36
|
+
require 'yaml'
|
37
|
+
|
38
|
+
require 'linkeddata'
|
39
|
+
require 'sparql/client'
|
40
|
+
require 'openstudio'
|
41
|
+
|
42
|
+
module OpenStudio
|
43
|
+
module Metadata
|
44
|
+
##
|
45
|
+
# Class to write serialized metadata models to file
|
46
|
+
##
|
47
|
+
# @example Write Haystack JSON to file with Writer
|
48
|
+
# creator = OpenStudio::Metadata::Creator.new(path_to_model)
|
49
|
+
# creator.apply_mappings('Haystack')
|
50
|
+
# writer = OpenStudio::Metadata::Writer.new(creator: creator)
|
51
|
+
# writer.write_output_to_file(output_format: 'json')
|
52
|
+
class Writer
|
53
|
+
##
|
54
|
+
# Initialize Writer
|
55
|
+
##
|
56
|
+
# @param creator [Creator] creator
|
57
|
+
def initialize(creator:)
|
58
|
+
@creator = creator
|
59
|
+
@files_path = File.join(File.dirname(__FILE__), '../../files')
|
60
|
+
@metadata_type = @creator.metadata_type
|
61
|
+
@output_format = nil # set by write_output_to_file
|
62
|
+
@brick_graph = nil #
|
63
|
+
@haystack = nil
|
64
|
+
|
65
|
+
supported_metadata_types = ['Brick', 'Haystack']
|
66
|
+
raise "metadata_type must be one of #{supported_metadata_types}" unless supported_metadata_types.include? @metadata_type
|
67
|
+
end
|
68
|
+
|
69
|
+
# Generates BrickGraph or Haystack from entities
|
70
|
+
def create_output
|
71
|
+
case @metadata_type
|
72
|
+
when 'Brick'
|
73
|
+
@brick_graph = BrickGraph.new
|
74
|
+
@brick_graph.create_from_entities(@creator.entities)
|
75
|
+
when 'Haystack'
|
76
|
+
@haystack = Haystack.new
|
77
|
+
@haystack = @haystack.create_from_entities(@creator.entities)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Write metadata model to file
|
83
|
+
##
|
84
|
+
# @param [String] output_format One of: ['json', 'ttl', 'nq']
|
85
|
+
# @param [String] file_path Path to output folder
|
86
|
+
# @param [String] file_name_without_extension output name without extension
|
87
|
+
def write_output_to_file(output_format:, file_path: '.', file_name_without_extension: 'model')
|
88
|
+
@output_format = output_format
|
89
|
+
supported_haystack_formats = ['json']
|
90
|
+
supported_brick_formats = ['ttl', 'nq']
|
91
|
+
raise "Brick output format must be one of: #{supported_brick_formats}" if (@metadata_type == 'Brick') && !supported_brick_formats.include?(@output_format)
|
92
|
+
raise "Haystack output format must be one of: #{supported_haystack_formats}" if (@metadata_type == 'Haystack') && !supported_haystack_formats.include?(@output_format)
|
93
|
+
case @metadata_type
|
94
|
+
when 'Brick'
|
95
|
+
case @output_format
|
96
|
+
when 'ttl'
|
97
|
+
File.open(File.join(file_path, "#{file_name_without_extension}.ttl"), 'w') { |f| f << @brick_graph.dump(:ttl) }
|
98
|
+
when 'nq'
|
99
|
+
File.open(File.join(file_path, "#{file_name_without_extension}.nq"), 'w') { |f| f << @brick_graph.dump(:nquads) }
|
100
|
+
end
|
101
|
+
when 'Haystack'
|
102
|
+
File.open(File.join(file_path, "#{file_name_without_extension}.json"), 'w') { |f| f << @haystack }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
|
36
|
+
require 'openstudio/extension'
|
37
|
+
require_relative 'metadata/creator'
|
38
|
+
require_relative 'metadata/version'
|
39
|
+
require_relative 'metadata/writer'
|
40
|
+
require_relative 'metadata/serializer'
|
41
|
+
require_relative 'metadata/helpers'
|
42
|
+
require_relative 'metadata/controls'
|
43
|
+
|
44
|
+
module OpenStudio
|
45
|
+
module Metadata
|
46
|
+
class Metadata < OpenStudio::Extension::Extension
|
47
|
+
# Override parent class
|
48
|
+
def initialize
|
49
|
+
super
|
50
|
+
|
51
|
+
@root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'openstudio/metadata'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'openstudio/metadata/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'openstudio-metadata'
|
8
|
+
spec.version = OpenStudio::Metadata::VERSION
|
9
|
+
spec.authors = ['Austin Viveiros']
|
10
|
+
spec.email = ['']
|
11
|
+
|
12
|
+
spec.summary = 'library and measures for OpenStudio'
|
13
|
+
spec.description = 'library and measures for OpenStudio'
|
14
|
+
spec.homepage = 'https://openstudio.net'
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.0'
|
26
|
+
spec.add_development_dependency 'rake', '13.0'
|
27
|
+
spec.add_development_dependency 'rspec', '3.7.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.54.0'
|
29
|
+
|
30
|
+
spec.add_dependency 'openstudio-extension', '0.2.5'
|
31
|
+
spec.add_dependency 'openstudio-standards', '0.2.11'
|
32
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# require 'bundler/gem_tasks'
|
2
|
+
# require 'rspec/core/rake_task'
|
3
|
+
#
|
4
|
+
# RSpec::Core::RakeTask.new(:spec)
|
5
|
+
#
|
6
|
+
# require 'rubocop/rake_task'
|
7
|
+
# RuboCop::RakeTask.new
|
8
|
+
#
|
9
|
+
## Load in the rake tasks from the base openstudio-extension gem
|
10
|
+
require 'openstudio/extension/rake_task'
|
11
|
+
# require 'openstudio/metadata'
|
12
|
+
# os_extension = OpenStudio::Extension::RakeTask.new
|
13
|
+
# os_extension.set_extension_class(OpenStudio::Metadata::Metadata)
|
14
|
+
#
|
15
|
+
# task default: :spec
|