Skip to content

Commit 5f27027

Browse files
committed
code cleanup
1 parent 4a8fc0e commit 5f27027

17 files changed

+208
-225
lines changed

lib/measures/urban_geometry_creation/measure.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def run(model, runner, user_arguments)
127127
surface_elevation = feature.surface_elevation.to_f
128128
surface_elevation = OpenStudio.convert(surface_elevation, 'ft', 'm').get
129129
site.setElevation(surface_elevation)
130-
rescue
130+
rescue StandardError
131131
@runner.registerWarning("Surface elevation not set for building '#{name}'")
132132
end
133133

@@ -196,4 +196,4 @@ def run(model, runner, user_arguments)
196196
end
197197

198198
# register the measure to be used by the application
199-
UrbanGeometryCreation.new.registerWithApplication
199+
UrbanGeometryCreation.new.registerWithApplication

lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_one_building
4747

4848
geojson_file = File.absolute_path(File.join(File.dirname(__FILE__), 'nrel_stm_footprints.geojson'))
4949

50-
feature_id = '59a9ce2b42f7d007c059d2ee' #Energy Systems Integration Facility
50+
feature_id = '59a9ce2b42f7d007c059d2ee' # Energy Systems Integration Facility
5151

5252
surrounding_buildings = 'None'
5353
# surrounding_buildings = "ShadingOnly"
@@ -100,9 +100,8 @@ def test_one_building_w_surrounding_buildings
100100

101101
geojson_file = File.absolute_path(File.join(File.dirname(__FILE__), 'nrel_stm_footprints.geojson'))
102102

103-
feature_id = '59a9ce2b42f7d007c059d2f0' #Education Center
104-
105-
103+
feature_id = '59a9ce2b42f7d007c059d2f0' # Education Center
104+
106105
# surrounding_buildings = "None"
107106
surrounding_buildings = 'ShadingOnly'
108107
# surrounding_buildings = "All"

lib/measures/urban_geometry_creation_zoning/measure.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def run(model, runner, user_arguments)
131131
surface_elevation = feature.surface_elevation.to_f
132132
surface_elevation = OpenStudio.convert(surface_elevation, 'ft', 'm').get
133133
site.setElevation(surface_elevation)
134-
rescue
134+
rescue StandardError
135135
@runner.registerWarning("Surface elevation not set for building '#{name}'")
136136
end
137137

lib/measures/urban_geometry_creation_zoning/tests/urban_geometry_creation_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_one_building
4747

4848
geojson_file = File.absolute_path(File.join(File.dirname(__FILE__), 'nrel_stm_footprints.geojson'))
4949

50-
feature_id = '59a9ce2b42f7d007c059d2ee' #Energy Systems Integration Facility
50+
feature_id = '59a9ce2b42f7d007c059d2ee' # Energy Systems Integration Facility
5151

5252
surrounding_buildings = 'None'
5353
# surrounding_buildings = "ShadingOnly"
@@ -100,7 +100,7 @@ def test_one_building_w_surrounding_buildings
100100

101101
geojson_file = File.absolute_path(File.join(File.dirname(__FILE__), 'nrel_stm_footprints.geojson'))
102102

103-
feature_id = '59a9ce2b42f7d007c059d2f0' #Education Center
103+
feature_id = '59a9ce2b42f7d007c059d2f0' # Education Center
104104

105105
# surrounding_buildings = "None"
106106
surrounding_buildings = 'ShadingOnly'

lib/urbanopt/geojson/building.rb

+125-126
Large diffs are not rendered by default.

lib/urbanopt/geojson/district_system.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,21 @@
3333
module URBANopt
3434
module GeoJSON # :nodoc: all
3535
class DistrictSystem < Feature
36-
3736
def initialize(feature)
3837
super(feature)
3938
end
4039

4140
##
42-
# Used to describe the feature type using the base method from the Feature class.
41+
# Used to describe the feature type using the base method from the Feature class.
4342
def feature_type
4443
'District System'
45-
end
44+
end
4645

4746
##
4847
# Returns the district system properties schema.
4948
def schema_file
5049
return File.join(File.dirname(__FILE__), 'schema', 'district_system_properties.json')
5150
end
52-
5351
end
5452
end
5553
end

lib/urbanopt/geojson/extension.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
module URBANopt
3535
module GeoJSON
3636
class Extension < OpenStudio::Extension::Extension
37-
38-
3937
def initialize # :nodoc:
4038
@root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
4139
end
4240

43-
##
41+
##
4442
# Returns the absolute path of the measures or returns nil, in case no measures are
4543
# added. It can be used while configuring OSWs.
4644
def measures_dir
@@ -56,7 +54,7 @@ def files_dir
5654

5755
# The directory containing common files like copyright and license notices which are used to update measures and other code.
5856
# This method will only be applied to measures in the current repository and
59-
# returns the absolute path of the +doc_templates_dir+ or nil if there is none.
57+
# returns the absolute path of the +doc_templates_dir+ or nil if there is none.
6058
def doc_templates_dir
6159
return File.absolute_path(File.join(@root_dir, 'doc_templates'))
6260
end

lib/urbanopt/geojson/feature.rb

+13-14
Original file line numberDiff line numberDiff line change
@@ -53,49 +53,48 @@ def method_missing(name, *args, &blk)
5353
end
5454

5555
##
56-
# Returns the id of the feature.
56+
# Returns the id of the feature.
5757

5858
def id
5959
return @feature_json[:properties][:id]
6060
end
6161

6262
##
63-
# Returns the name of the feature.
63+
# Returns the name of the feature.
6464

6565
def name
6666
return @feature_json[:properties][:name]
6767
end
6868

6969
##
70-
# Raises an error if the +feature_type+ is not specified the the Feature's class.
70+
# Raises an error if the +feature_type+ is not specified the the Feature's class.
7171

7272
def feature_type
7373
raise 'feature_type not implemented for Feature, override in your class'
7474
end
75-
75+
7676
##
77-
# Raises an error if the +schema_file+ is not specified the the Feature's class.
78-
77+
# Raises an error if the +schema_file+ is not specified the the Feature's class.
78+
7979
def schema_file
8080
raise 'schema_file not implemented for Feature, override in your class'
8181
end
82-
8382

8483
def schema
8584
if @@feature_schema[feature_type].nil?
8685
@@schema_file_lock.synchronize do
8786
File.open(schema_file, 'r') do |file|
8887
@@feature_schema[feature_type] = JSON.parse(file.read, symbolize_names: true)
89-
90-
#Allows additional properties.
88+
89+
# Allows additional properties.
9190
@@feature_schema[feature_type][:additionalProperties] = true
9291
end
9392
end
9493
end
9594

9695
return @@feature_schema[feature_type]
9796
end
98-
97+
9998
##
10099
# Returns coordinate with the minimum longitute and latitude within a given +building_json+ .
101100
def get_min_lon_lat
@@ -119,7 +118,7 @@ def get_min_lon_lat
119118
# [Parameters]
120119
# +json+
121120
#
122-
# For example:
121+
# For example:
123122
#
124123
# polygon = {
125124
# 'geometry': {
@@ -167,7 +166,7 @@ def create_origin_lat_lon(runner)
167166

168167
private
169168

170-
##
169+
##
171170
# Used to validate the feature by checking +feature_id+ , +geometry+, +properties+
172171
# and +geometry_type+ .
173172

@@ -186,7 +185,7 @@ def validate_feat(feature) #:doc:
186185
raise("No properties found in '#{feature}'")
187186
return false
188187
end
189-
188+
190189
errors = JSON::Validator.fully_validate(schema, feature[:properties])
191190
if !errors.empty?
192191
raise("Invalid properties for '#{feature}'\n #{errors.join('\n ')}")
@@ -204,4 +203,4 @@ def validate_feat(feature) #:doc:
204203
end
205204
end
206205
end
207-
end
206+
end

lib/urbanopt/geojson/geo_file.rb

+7-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GeoFile < URBANopt::Core::FeatureFile
4242
@@schema_file_lock = Mutex.new
4343

4444
##
45-
# Raises an error in case the GeoJSON file is not valid.
45+
# Raises an error in case the GeoJSON file is not valid.
4646
#
4747
# [Parameters]
4848
#
@@ -55,12 +55,11 @@ def initialize(data, path = nil)
5555
end
5656
end
5757

58-
5958
##
6059
# [Parameters]
6160
#
6261
# Used to check the GeoJSON file path.
63-
# * +path+ - _Type:String_ - GeoJSON file path.
62+
# * +path+ - _Type:String_ - GeoJSON file path.
6463
def self.from_file(path)
6564
if path.nil? || path.empty?
6665
raise "GeoJSON file '#{path}' could not be found"
@@ -81,10 +80,8 @@ def json
8180
@geojson
8281
end
8382

84-
def path
85-
@path
86-
end
87-
83+
attr_reader :path
84+
8885
##
8986
# This method loops through all the features in the GeoJSON file, creates new
9087
# Buildings or District Systems based on the feature type, and returns the features.
@@ -122,7 +119,7 @@ def get_feature_by_id(feature_id)
122119
end
123120

124121
##
125-
# Returns the file path for the +geojson_schema.json+ .
122+
# Returns the file path for the +geojson_schema.json+ .
126123
def schema_file
127124
return File.join(File.dirname(__FILE__), 'schema', 'geojson_schema.json')
128125
end
@@ -142,17 +139,16 @@ def schema
142139
end
143140

144141
##
145-
# Validates the GeoJSON file against the schema.
142+
# Validates the GeoJSON file against the schema.
146143
def valid?
147144
return JSON::Validator.validate(schema, @geojson)
148145
end
149146

150147
##
151-
# Returns detailed validation results.
148+
# Returns detailed validation results.
152149
def validation_errors
153150
return JSON::Validator.fully_validate(schema, @geojson)
154151
end
155-
156152
end
157153
end
158154
end

0 commit comments

Comments
 (0)