oslg 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/pull_request.yml +20 -4
- data/LICENSE +1 -1
- data/README.md +7 -7
- data/lib/oslg/oslog.rb +98 -71
- data/lib/oslg/version.rb +2 -2
- data/lib/oslg.rb +1 -1
- data/oslg.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d9b0ecd08d5975a017a4133b83cd7deea1a21427d923651ff629347ee4b8e83
|
4
|
+
data.tar.gz: 637c081134c0fc036048c62a17bf7e95087c807c34921bd80ebb3d53f0996346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf5fddfd6703ac80fdcc94818db3f9c5d58c27a9f7617db8d04b92b78b9e442937551857fa4c7c9a1d470703f89499a484d55f49c1b8e30ebb72cd8266d63676
|
7
|
+
data.tar.gz: 36411cd8958dd7e387e34ecd901c9cc12ff62cf37fb483e3c5d88954732857eaf796609cc358dea417ece8fe06f11f1e5526e2e1760a5444c3ffcdbdcd3d14a2
|
@@ -7,7 +7,7 @@ on:
|
|
7
7
|
|
8
8
|
jobs:
|
9
9
|
test_300x:
|
10
|
-
runs-on: ubuntu-
|
10
|
+
runs-on: ubuntu-22.04
|
11
11
|
steps:
|
12
12
|
- name: Check out repository
|
13
13
|
uses: actions/checkout@v2
|
@@ -23,7 +23,7 @@ jobs:
|
|
23
23
|
docker exec -t test bundle exec rake
|
24
24
|
docker kill test
|
25
25
|
test_321x:
|
26
|
-
runs-on: ubuntu-
|
26
|
+
runs-on: ubuntu-22.04
|
27
27
|
steps:
|
28
28
|
- name: Check out repository
|
29
29
|
uses: actions/checkout@v2
|
@@ -39,7 +39,7 @@ jobs:
|
|
39
39
|
docker exec -t test bundle exec rake
|
40
40
|
docker kill test
|
41
41
|
test_330x:
|
42
|
-
runs-on: ubuntu-
|
42
|
+
runs-on: ubuntu-22.04
|
43
43
|
steps:
|
44
44
|
- name: Check out repository
|
45
45
|
uses: actions/checkout@v2
|
@@ -55,7 +55,7 @@ jobs:
|
|
55
55
|
docker exec -t test bundle exec rake
|
56
56
|
docker kill test
|
57
57
|
test_340x:
|
58
|
-
runs-on: ubuntu-
|
58
|
+
runs-on: ubuntu-22.04
|
59
59
|
steps:
|
60
60
|
- name: Check out repository
|
61
61
|
uses: actions/checkout@v2
|
@@ -70,3 +70,19 @@ jobs:
|
|
70
70
|
docker exec -t test bundle update
|
71
71
|
docker exec -t test bundle exec rake
|
72
72
|
docker kill test
|
73
|
+
test_351x:
|
74
|
+
runs-on: ubuntu-22.04
|
75
|
+
steps:
|
76
|
+
- name: Check out repository
|
77
|
+
uses: actions/checkout@v2
|
78
|
+
- name: Run Tests
|
79
|
+
run: |
|
80
|
+
echo $(pwd)
|
81
|
+
echo $(ls)
|
82
|
+
docker pull nrel/openstudio:3.5.1
|
83
|
+
docker run --name test --rm -d -t -v $(pwd):/work -w /work nrel/openstudio:3.5.1
|
84
|
+
docker exec -t test pwd
|
85
|
+
docker exec -t test ls
|
86
|
+
docker exec -t test bundle update
|
87
|
+
docker exec -t test bundle exec rake
|
88
|
+
docker kill test
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -39,7 +39,7 @@ FATAL
|
|
39
39
|
|
40
40
|
DEBUG messages aren't benign at all, but are certainly less informative for the typical Measure user.
|
41
41
|
|
42
|
-
Initially, __oslg__ sets 2x internal
|
42
|
+
Initially, __oslg__ sets 2x internal attributes: `level` (INFO) and `status` (< DEBUG). The `level` attribute is a user-set threshold below which less severe logs (e.g. DEBUG) are ignored. For instance, if `level` were _reset_ to DEBUG (e.g. `M.reset(M::DEBUG)`), then all DEBUG messages would also be logged. The `status` attribute is reset with each new log entry if the latter's log level is more severe than its predecessor (e.g. `status == M::FATAL` if there is a single log entry registered as FATAL). To check the curent __oslg__ `status` (true or false):
|
43
43
|
|
44
44
|
```
|
45
45
|
M.debug?
|
@@ -48,7 +48,7 @@ M.error?
|
|
48
48
|
M.fatal?
|
49
49
|
```
|
50
50
|
|
51
|
-
It's sometimes not a bad idea to rely on a _clean_ slate (e.g. within RSpecs). The following
|
51
|
+
It's sometimes not a bad idea to rely on a _clean_ slate (e.g. within RSpecs). The following purges all previous logs and resets `level` (INFO) and `status` (< DEBUG) - use with caution in production code!
|
52
52
|
|
53
53
|
```
|
54
54
|
M.clean!
|
@@ -60,7 +60,7 @@ EnergyPlus will run, with e.g. out-of-range material or fluid properties, while
|
|
60
60
|
M.log(M::FATAL, "Missing input JSON file")
|
61
61
|
```
|
62
62
|
|
63
|
-
Consider logging non-fatal __ERROR__ messages when encountering invalid OpenStudio file entries, i.e. well-defined, yet invalid vis-à-vis EnergyPlus limitations. The invalid object could be simply ignored, while the measure pursues its (otherwise valid) calculations ... with OpenStudio ultimately launching an EnergyPlus simulation. If a simulation indeed ran (ultimately a go/no-go decision made by the EnergyPlus simulation engine), it would be up to users to decide if simulation results were valid or useful, given the context - maybe based on __oslg__ logged messages. In short, non-fatal ERROR logs should ideally point to bad input users can fix.
|
63
|
+
Consider logging non-fatal __ERROR__ messages when encountering invalid OpenStudio file entries, i.e. well-defined, yet invalid vis-à-vis EnergyPlus limitations. The invalid object could be simply ignored, while the measure pursues its (otherwise valid) calculations ... with OpenStudio ultimately launching an EnergyPlus simulation. If a simulation indeed ran (ultimately a go/no-go decision made by the EnergyPlus simulation engine), it would be up to users to decide if simulation results were valid or useful, given the context - maybe based on __oslg__ logged messages. In short, non-fatal ERROR logs should ideally point to bad input (that users can fix).
|
64
64
|
|
65
65
|
```
|
66
66
|
M.log(M::ERROR, "Measure won't process MASSLESS materials")
|
@@ -96,7 +96,7 @@ These logs can be first _mapped_ to other structures (then edited), depending on
|
|
96
96
|
|
97
97
|
### Preset log templates
|
98
98
|
|
99
|
-
Typically, developers would first catch bad input, log an error message and possibly exit by returning
|
99
|
+
Typically, developers would first catch bad input, log an error message and possibly exit by returning an object (e.g. __false__, __nil__), e.g.:
|
100
100
|
|
101
101
|
```
|
102
102
|
unless var.is_a?(Array)
|
@@ -105,7 +105,7 @@ unless var.is_a?(Array)
|
|
105
105
|
end
|
106
106
|
```
|
107
107
|
|
108
|
-
The following are __oslg__ one-liner methods that _log & return_ in one go. These are for some of the most common checks OpenStudio SDK Ruby developers are likely to need. The methods require _valid_ arguments for __oslg__ to actually log. Although often expecting strings as arguments, the methods will try to convert other types to strings (e.g. classes, numbers, even entire arrays) if possible.
|
108
|
+
The following are __oslg__ one-liner methods that _log & return_ in one go. These are for some of the most common checks OpenStudio SDK Ruby developers are likely to need. The methods require _valid_ arguments for __oslg__ to actually log. Although often expecting either strings or integers as arguments, the methods will try to convert other types to strings (e.g. classes, numbers, even entire arrays) or integers if possible.
|
109
109
|
|
110
110
|
---
|
111
111
|
|
@@ -125,8 +125,8 @@ The 3rd argument (e.g. _0_) is ignored unless `> 0` - a useful option when asser
|
|
125
125
|
|
126
126
|
```
|
127
127
|
def sum(areas, units)
|
128
|
-
return M.invalid("areas", "sum", 1) unless areas
|
129
|
-
return M.invalid("units", "sum", 2) unless units
|
128
|
+
return M.invalid("areas", "sum", 1) unless areas.respond_to?(:to_f)
|
129
|
+
return M.invalid("units", "sum", 2) unless units.respond_to?(:to_s)
|
130
130
|
...
|
131
131
|
end
|
132
132
|
```
|
data/lib/oslg/oslog.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BSD 3-Clause License
|
2
2
|
#
|
3
|
-
# Copyright (c) 2022, Denis Bourgeois
|
3
|
+
# Copyright (c) 2022-2023, Denis Bourgeois
|
4
4
|
# All rights reserved.
|
5
5
|
#
|
6
6
|
# Redistribution and use in source and binary forms, with or without
|
@@ -127,6 +127,7 @@ module OSlg
|
|
127
127
|
# @return [String] "DEBUG", "INFO", "WARN", "ERROR" or "FATAL"
|
128
128
|
def tag(level)
|
129
129
|
return @@tag[level] if level >= DEBUG && level <= FATAL
|
130
|
+
|
130
131
|
""
|
131
132
|
end
|
132
133
|
|
@@ -138,6 +139,7 @@ module OSlg
|
|
138
139
|
# @return [String] preset OSlg message
|
139
140
|
def msg(status)
|
140
141
|
return @@msg[status] if status >= DEBUG && status <= FATAL
|
142
|
+
|
141
143
|
""
|
142
144
|
end
|
143
145
|
|
@@ -163,6 +165,7 @@ module OSlg
|
|
163
165
|
@@logs << {level: level, message: message}
|
164
166
|
@@status = level if level > @@status
|
165
167
|
end
|
168
|
+
|
166
169
|
@@status
|
167
170
|
end
|
168
171
|
|
@@ -171,29 +174,34 @@ module OSlg
|
|
171
174
|
#
|
172
175
|
# @param id [String] invalid object identifier
|
173
176
|
# @param mth [String] calling method identifier
|
174
|
-
# @param ord [
|
177
|
+
# @param ord [Integer] calling method argument order number of obj (optional)
|
175
178
|
# @param lvl [Integer] DEBUG, INFO, WARN, ERROR or FATAL (optional)
|
176
179
|
# @param res [Object] what to return (optional)
|
177
180
|
#
|
178
181
|
# @return [Object] return object if specified by user
|
179
|
-
# @return [Nil] nil if return object
|
182
|
+
# @return [Nil] nil if return object undefined
|
180
183
|
def invalid(id = "", mth = "", ord = 0, lvl = DEBUG, res = nil)
|
181
|
-
return
|
182
|
-
return res unless
|
183
|
-
return res unless
|
184
|
-
return res unless
|
185
|
-
|
184
|
+
return res unless id.respond_to?(:to_s)
|
185
|
+
return res unless mth.respond_to?(:to_s)
|
186
|
+
return res unless ord.respond_to?(:to_i)
|
187
|
+
return res unless lvl.respond_to?(:to_i)
|
188
|
+
|
189
|
+
id = id.to_s.strip
|
186
190
|
mth = mth.to_s.strip
|
187
|
-
|
188
|
-
|
189
|
-
|
191
|
+
ord = ord.to_i
|
192
|
+
lvl = lvl.to_i
|
193
|
+
|
190
194
|
id = id[0...60] + " ..." if id.length > 60
|
191
195
|
return res if id.empty?
|
192
|
-
|
193
|
-
|
196
|
+
|
197
|
+
mth = mth[0...60] + " ..." if mth.length > 60
|
198
|
+
return res if mth.empty?
|
199
|
+
|
200
|
+
msg = "Invalid '#{id}' "
|
201
|
+
msg += "arg ##{ord} " if ord > 0
|
194
202
|
msg += "(#{mth})"
|
195
|
-
lvl = lvl.to_i unless lvl.is_a?(Integer)
|
196
203
|
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
|
204
|
+
|
197
205
|
res
|
198
206
|
end
|
199
207
|
|
@@ -208,25 +216,27 @@ module OSlg
|
|
208
216
|
# @param res [Object] what to return (optional)
|
209
217
|
#
|
210
218
|
# @return [Object] return object if specified by user
|
211
|
-
# @return [Nil] nil if return object
|
219
|
+
# @return [Nil] nil if return object undefined
|
212
220
|
def mismatch(id = "", obj = nil, cl = nil, mth = "", lvl = DEBUG, res = nil)
|
213
|
-
return
|
214
|
-
return res unless
|
215
|
-
return res
|
216
|
-
return res unless
|
217
|
-
return res unless
|
218
|
-
|
221
|
+
return res unless id.respond_to?(:to_s)
|
222
|
+
return res unless cl.is_a?(Class)
|
223
|
+
return res if obj.is_a?(cl)
|
224
|
+
return res unless mth.respond_to?(:to_s)
|
225
|
+
return res unless lvl.respond_to?(:to_i)
|
226
|
+
|
219
227
|
mth = mth.to_s.strip
|
220
|
-
|
221
|
-
|
222
|
-
|
228
|
+
id = id.to_s.strip
|
229
|
+
lvl = lvl.to_i
|
230
|
+
|
223
231
|
id = id[0...60] + " ..." if id.length > 60
|
224
232
|
return res if id.empty?
|
225
|
-
|
226
|
-
|
233
|
+
|
234
|
+
mth = mth[0...60] + " ..." if mth.length > 60
|
235
|
+
return res if mth.empty?
|
236
|
+
|
227
237
|
msg = "'#{id}' #{obj.class}? expecting #{cl} (#{mth})"
|
228
|
-
lvl = lvl.to_i unless lvl.is_a?(Integer)
|
229
238
|
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
|
239
|
+
|
230
240
|
res
|
231
241
|
end
|
232
242
|
|
@@ -241,25 +251,27 @@ module OSlg
|
|
241
251
|
# @param res [Object] what to return (optional)
|
242
252
|
#
|
243
253
|
# @return [Object] return object if specified by user
|
244
|
-
# @return [Nil] nil if return object
|
254
|
+
# @return [Nil] nil if return object undefined
|
245
255
|
def hashkey(id = "", hsh = {}, key = "", mth = "", lvl = DEBUG, res = nil)
|
246
|
-
return
|
247
|
-
return res unless
|
248
|
-
return res
|
249
|
-
return res unless
|
250
|
-
return res unless
|
251
|
-
|
256
|
+
return res unless id.respond_to?(:to_s)
|
257
|
+
return res unless hsh.is_a?(Hash)
|
258
|
+
return res if hsh.key?(key)
|
259
|
+
return res unless mth.respond_to?(:to_s)
|
260
|
+
return res unless lvl.respond_to?(:to_i)
|
261
|
+
|
262
|
+
id = id.to_s.strip
|
252
263
|
mth = mth.to_s.strip
|
253
|
-
|
254
|
-
|
255
|
-
id = id.to_s.strip
|
264
|
+
lvl = lvl.to_i
|
265
|
+
|
256
266
|
id = id[0...60] + " ..." if id.length > 60
|
257
267
|
return res if id.empty?
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
268
|
+
|
269
|
+
mth = mth[0...60] + " ..." if mth.length > 60
|
270
|
+
return res if mth.empty?
|
271
|
+
|
272
|
+
msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
|
262
273
|
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
|
274
|
+
|
263
275
|
res
|
264
276
|
end
|
265
277
|
|
@@ -272,21 +284,25 @@ module OSlg
|
|
272
284
|
# @param res [Object] what to return (optional)
|
273
285
|
#
|
274
286
|
# @return [Object] return object if specified by user
|
275
|
-
# @return [Nil] nil if return object
|
287
|
+
# @return [Nil] nil if return object undefined
|
276
288
|
def empty(id = "", mth = "", lvl = DEBUG, res = nil)
|
277
|
-
return
|
278
|
-
return res unless
|
279
|
-
return res unless
|
280
|
-
|
289
|
+
return res unless id.respond_to?(:to_s)
|
290
|
+
return res unless mth.respond_to?(:to_s)
|
291
|
+
return res unless lvl.respond_to?(:to_i)
|
292
|
+
|
293
|
+
id = id.to_s.strip
|
281
294
|
mth = mth.to_s.strip
|
282
|
-
|
283
|
-
|
284
|
-
id = id.to_s.strip
|
295
|
+
lvl = lvl.to_i
|
296
|
+
|
285
297
|
id = id[0...60] + " ..." if id.length > 60
|
286
298
|
return res if id.empty?
|
287
|
-
|
288
|
-
|
299
|
+
|
300
|
+
mth = mth[0...60] + " ..." if mth.length > 60
|
301
|
+
return res if mth.empty?
|
302
|
+
|
303
|
+
msg = "Empty '#{id}' (#{mth})"
|
289
304
|
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
|
305
|
+
|
290
306
|
res
|
291
307
|
end
|
292
308
|
|
@@ -299,21 +315,26 @@ module OSlg
|
|
299
315
|
# @param res [Object] what to return (optional)
|
300
316
|
#
|
301
317
|
# @return [Object] return object if specified by user
|
302
|
-
# @return [Nil] nil if return object
|
318
|
+
# @return [Nil] nil if return object undefined
|
303
319
|
def zero(id = "", mth = "", lvl = DEBUG, res = nil)
|
304
|
-
return
|
305
|
-
return res unless
|
306
|
-
return res unless
|
307
|
-
|
320
|
+
return res unless id.respond_to?(:to_s)
|
321
|
+
return res unless mth.respond_to?(:to_s)
|
322
|
+
return res unless lvl.respond_to?(:to_i)
|
323
|
+
|
324
|
+
id = id.to_s.strip
|
308
325
|
mth = mth.to_s.strip
|
309
|
-
|
310
|
-
|
311
|
-
|
326
|
+
ord = ord.to_i
|
327
|
+
lvl = lvl.to_i
|
328
|
+
|
312
329
|
id = id[0...60] + " ..." if id.length > 60
|
313
330
|
return res if id.empty?
|
314
|
-
|
315
|
-
|
331
|
+
|
332
|
+
mth = mth[0...60] + " ..." if mth.length > 60
|
333
|
+
return res if mth.empty?
|
334
|
+
|
335
|
+
msg = "Zero '#{id}' (#{mth})"
|
316
336
|
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
|
337
|
+
|
317
338
|
res
|
318
339
|
end
|
319
340
|
|
@@ -326,21 +347,26 @@ module OSlg
|
|
326
347
|
# @param res [Object] what to return (optional)
|
327
348
|
#
|
328
349
|
# @return [Object] return object if specified by user
|
329
|
-
# @return [Nil] nil if return object
|
350
|
+
# @return [Nil] nil if return object undefined
|
330
351
|
def negative(id = "", mth = "", lvl = DEBUG, res = nil)
|
331
|
-
return
|
332
|
-
return res unless
|
333
|
-
return res unless
|
334
|
-
|
352
|
+
return res unless id.respond_to?(:to_s)
|
353
|
+
return res unless mth.respond_to?(:to_s)
|
354
|
+
return res unless lvl.respond_to?(:to_i)
|
355
|
+
|
356
|
+
id = id.to_s.strip
|
335
357
|
mth = mth.to_s.strip
|
336
|
-
|
337
|
-
|
338
|
-
|
358
|
+
ord = ord.to_i
|
359
|
+
lvl = lvl.to_i
|
360
|
+
|
339
361
|
id = id[0...60] + " ..." if id.length > 60
|
340
362
|
return res if id.empty?
|
341
|
-
|
342
|
-
|
363
|
+
|
364
|
+
mth = mth[0...60] + " ..." if mth.length > 60
|
365
|
+
return res if mth.empty?
|
366
|
+
|
367
|
+
msg = "Negative '#{id}' (#{mth})"
|
343
368
|
log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
|
369
|
+
|
344
370
|
res
|
345
371
|
end
|
346
372
|
|
@@ -351,6 +377,7 @@ module OSlg
|
|
351
377
|
def clean!
|
352
378
|
@@status = 0
|
353
379
|
@@logs = []
|
380
|
+
|
354
381
|
@@level
|
355
382
|
end
|
356
383
|
|
data/lib/oslg/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BSD 3-Clause License
|
2
2
|
#
|
3
|
-
# Copyright (c) 2022, Denis Bourgeois
|
3
|
+
# Copyright (c) 2022-2023, Denis Bourgeois
|
4
4
|
# All rights reserved.
|
5
5
|
#
|
6
6
|
# Redistribution and use in source and binary forms, with or without
|
@@ -29,5 +29,5 @@
|
|
29
29
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
30
|
|
31
31
|
module OSlg
|
32
|
-
VERSION = "0.2.
|
32
|
+
VERSION = "0.2.6".freeze
|
33
33
|
end
|
data/lib/oslg.rb
CHANGED
data/oslg.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_development_dependency "rake", "~> 13.0"
|
32
32
|
s.add_development_dependency "rspec", "~> 3.11"
|
33
33
|
|
34
|
-
s.metadata["homepage_uri"]
|
34
|
+
s.metadata["homepage_uri" ] = s.homepage
|
35
35
|
s.metadata["source_code_uri"] = "#{s.homepage}/tree/v#{s.version}"
|
36
36
|
s.metadata["bug_tracker_uri"] = "#{s.homepage}/issues"
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oslg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Bourgeois
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,7 +76,7 @@ licenses:
|
|
76
76
|
- BSD-3-Clause
|
77
77
|
metadata:
|
78
78
|
homepage_uri: https://github.com/rd2/oslg
|
79
|
-
source_code_uri: https://github.com/rd2/oslg/tree/v0.2.
|
79
|
+
source_code_uri: https://github.com/rd2/oslg/tree/v0.2.6
|
80
80
|
bug_tracker_uri: https://github.com/rd2/oslg/issues
|
81
81
|
post_install_message:
|
82
82
|
rdoc_options: []
|