tbd 3.4.3 → 3.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  # BSD 3-Clause License
2
2
  #
3
- # Copyright (c) 2022-2024, Denis Bourgeois
3
+ # Copyright (c) 2022-2025, Denis Bourgeois
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -102,9 +102,9 @@ module OSlg
102
102
  end
103
103
 
104
104
  ##
105
- # Returns whether current status is WARN.
105
+ # Returns whether current status is WARNING.
106
106
  #
107
- # @return [Bool] whether current log status is WARN
107
+ # @return [Bool] whether current log status is WARNING
108
108
  def warn?
109
109
  @@status == WARN
110
110
  end
@@ -159,19 +159,20 @@ module OSlg
159
159
  end
160
160
 
161
161
  ##
162
- # Converts object to String and trims if necessary.
162
+ # Converts object to String, trims if requested.
163
163
  #
164
164
  # @param txt [#to_s] a stringable object
165
- # @param length [#to_i] maximum return string length
165
+ # @param len [Numeric] requested maximum string length (optional)
166
166
  #
167
- # @return [String] a trimmed message string (empty unless stringable)
168
- def trim(txt = "", length = 60)
169
- length = 60 unless length.respond_to?(:to_i)
170
- length = length.to_i if length.respond_to?(:to_i)
167
+ # @return [String] a (trimmed) string (empty unless stringable)
168
+ def trim(txt = "", len = nil)
171
169
  return "" unless txt.respond_to?(:to_s)
172
170
 
173
171
  txt = txt.to_s.strip
174
- txt = txt[0...length] + " ..." if txt.length > length
172
+
173
+ if len.is_a?(Numeric)
174
+ txt = txt[0...len.to_i] + " ..." if txt.length > len.to_i
175
+ end
175
176
 
176
177
  txt
177
178
  end
@@ -193,21 +194,28 @@ module OSlg
193
194
  end
194
195
 
195
196
  ##
196
- # Logs a new entry, if provided arguments are valid.
197
+ # Logs a new entry. Overall log status is raised if new level is greater
198
+ # than current level (e.g. FATAL > ERROR). Candidate log entry is ignored and
199
+ # status remains unchanged if the new level cannot be converted to an integer,
200
+ # if not an OSlg constant (once converted), or if new level is below the
201
+ # current log level. Relies on OSlg method 'trim()': candidate log message is
202
+ # ignored and status unchanged if message is not a valid string.
197
203
  #
198
204
  # @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL
199
205
  # @param message [#to_s] user-provided log message
206
+ # @param len [Numeric] maximum log message length (optional)
200
207
  #
201
208
  # @example A user warning
202
209
  # log(WARN, "Surface area < 100cm2")
203
210
  #
204
211
  # @return [DEBUG, INFO, WARN, ERROR, FATAL] updated/current status
205
- def log(lvl = DEBUG, message = "")
212
+ def log(lvl = DEBUG, message = "", len = nil)
206
213
  return @@status unless lvl.respond_to?(:to_i)
207
214
  return @@status unless message.respond_to?(:to_s)
208
215
 
209
216
  lvl = lvl.to_i
210
- message = message.to_s
217
+ message = trim(message, len)
218
+ return @@status if message.empty?
211
219
  return @@status if lvl < DEBUG
212
220
  return @@status if lvl > FATAL
213
221
  return @@status if lvl < @@level
@@ -220,19 +228,24 @@ module OSlg
220
228
 
221
229
  ##
222
230
  # Logs template 'invalid object' message, if provided arguments are valid.
231
+ # Relies on OSlg method 'log()': first check out its own operation, exit
232
+ # conditions and module side effects. Candidate log entry is ignored and
233
+ # status remains unchanged if 'ord' cannot be converted to an integer.
234
+ # Argument 'ord' is ignored unless > 0.
223
235
  #
224
236
  # @param id [#to_s] 'invalid object' identifier
225
237
  # @param mth [#to_s] calling method identifier
226
238
  # @param ord [#to_i] calling method argument order number of obj (optional)
227
239
  # @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
228
240
  # @param res what to return (optional)
241
+ # @param len [Numeric] maximum log message length (optional)
229
242
  #
230
243
  # @example An invalid argument, logging a FATAL error, returning FALSE
231
244
  # return invalid("area", "sum", 0, FATAL, false) if area > 1000000
232
245
  #
233
246
  # @return user-provided object
234
247
  # @return [nil] if user hasn't provided an object to return
235
- def invalid(id = "", mth = "", ord = 0, lvl = DEBUG, res = nil)
248
+ def invalid(id = "", mth = "", ord = 0, lvl = DEBUG, res = nil, len = nil)
236
249
  return res unless id.respond_to?(:to_s)
237
250
  return res unless mth.respond_to?(:to_s)
238
251
  return res unless ord.respond_to?(:to_i)
@@ -250,7 +263,7 @@ module OSlg
250
263
  msg = "Invalid '#{id}' "
251
264
  msg += "arg ##{ord} " if ord > 0
252
265
  msg += "(#{mth})"
253
- log(lvl, msg)
266
+ log(lvl, msg, len)
254
267
 
255
268
  res
256
269
  end
@@ -266,13 +279,14 @@ module OSlg
266
279
  # @param mth [#to_s] calling method identifier (optional)
267
280
  # @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
268
281
  # @param res what to return (optional)
282
+ # @param len [Numeric] maximum log message length (optional)
269
283
  #
270
284
  # @example A mismatched argument instance/class
271
285
  # mismatch("area", area, Float, "sum") unless area.is_a?(Numeric)
272
286
  #
273
287
  # @return user-provided object
274
288
  # @return [nil] if user hasn't provided an object to return
275
- def mismatch(id = "", obj = nil, cl = nil, mth = "", lvl = DEBUG, res = nil)
289
+ def mismatch(id = "", obj = nil, cl = nil, mth = "", lvl = DEBUG, res = nil, len = nil)
276
290
  return res unless id.respond_to?(:to_s)
277
291
  return res unless mth.respond_to?(:to_s)
278
292
  return res unless cl.is_a?(Class)
@@ -287,7 +301,7 @@ module OSlg
287
301
  return res if lvl < DEBUG
288
302
  return res if lvl > FATAL
289
303
 
290
- log(lvl, "'#{id}' #{obj.class}? expecting #{cl} (#{mth})")
304
+ log(lvl, "'#{id}' #{obj.class}? expecting #{cl} (#{mth})", len)
291
305
 
292
306
  res
293
307
  end
@@ -302,13 +316,14 @@ module OSlg
302
316
  # @param mth [#to_s] calling method identifier
303
317
  # @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
304
318
  # @param res what to return (optional)
319
+ # @param len [Numeric] maximum log message length (optional)
305
320
  #
306
321
  # @example A missing Hash key
307
322
  # hashkey("floor area", floor, :area, "sum") unless floor.key?(:area)
308
323
  #
309
324
  # @return user-provided object
310
325
  # @return [nil] if user hasn't provided an object to return
311
- def hashkey(id = "", hsh = {}, key = "", mth = "", lvl = DEBUG, res = nil)
326
+ def hashkey(id = "", hsh = {}, key = "", mth = "", lvl = DEBUG, res = nil, len = nil)
312
327
  return res unless id.respond_to?(:to_s)
313
328
  return res unless hsh.is_a?(Hash)
314
329
  return res if hsh.key?(key)
@@ -323,7 +338,7 @@ module OSlg
323
338
  return res if lvl < DEBUG
324
339
  return res if lvl > FATAL
325
340
 
326
- log(lvl, "Missing '#{key}' key in '#{id}' Hash (#{mth})")
341
+ log(lvl, "Missing '#{key}' key in '#{id}' Hash (#{mth})", len)
327
342
 
328
343
  res
329
344
  end
@@ -335,13 +350,14 @@ module OSlg
335
350
  # @param mth [#to_s] calling method identifier
336
351
  # @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
337
352
  # @param res what to return (optional)
353
+ # @param len [Numeric] maximum log message length (optional)
338
354
  #
339
355
  # @example An uninitialized variable, logging an ERROR, returning FALSE
340
356
  # empty("zone", "conditioned?", FATAL, false) if space.thermalZone.empty?
341
357
  #
342
358
  # @return user-provided object
343
359
  # @return [nil] if user hasn't provided an object to return
344
- def empty(id = "", mth = "", lvl = DEBUG, res = nil)
360
+ def empty(id = "", mth = "", lvl = DEBUG, res = nil, len = nil)
345
361
  return res unless id.respond_to?(:to_s)
346
362
  return res unless mth.respond_to?(:to_s)
347
363
  return res unless lvl.respond_to?(:to_i)
@@ -354,7 +370,7 @@ module OSlg
354
370
  return res if lvl < DEBUG
355
371
  return res if lvl > FATAL
356
372
 
357
- log(lvl, "Empty '#{id}' (#{mth})")
373
+ log(lvl, "Empty '#{id}' (#{mth})", len)
358
374
 
359
375
  res
360
376
  end
@@ -366,13 +382,14 @@ module OSlg
366
382
  # @param mth [#to_s] calling method identifier
367
383
  # @param lvl [#to_i] DEBUG, INFO, WARN, ERROR or FATAL (optional)
368
384
  # @param res what to return (optional)
385
+ # @param len [Numeric] maximum log message length (optional)
369
386
  #
370
387
  # @example A near-zero variable
371
388
  # zero("floor area", "sum") if floor[:area].abs < TOL
372
389
  #
373
390
  # @return user-provided object
374
391
  # @return [nil] if user hasn't provided an object to return
375
- def zero(id = "", mth = "", lvl = DEBUG, res = nil)
392
+ def zero(id = "", mth = "", lvl = DEBUG, res = nil, len = nil)
376
393
  return res unless id.respond_to?(:to_s)
377
394
  return res unless mth.respond_to?(:to_s)
378
395
  return res unless lvl.respond_to?(:to_i)
@@ -386,7 +403,7 @@ module OSlg
386
403
  return res if lvl < DEBUG
387
404
  return res if lvl > FATAL
388
405
 
389
- log(lvl, "Zero '#{id}' (#{mth})")
406
+ log(lvl, "Zero '#{id}' (#{mth})", len)
390
407
 
391
408
  res
392
409
  end
@@ -398,13 +415,14 @@ module OSlg
398
415
  # @param mth [String] calling method identifier
399
416
  # @param lvl [Integer] DEBUG, INFO, WARN, ERROR or FATAL (optional)
400
417
  # @param res [Object] what to return (optional)
418
+ # @param len [Numeric] maximum log message length (optional)
401
419
  #
402
420
  # @example A negative variable
403
421
  # negative("floor area", "sum") if floor[:area] < 0
404
422
  #
405
423
  # @return user-provided object
406
424
  # @return [nil] if user hasn't provided an object to return
407
- def negative(id = "", mth = "", lvl = DEBUG, res = nil)
425
+ def negative(id = "", mth = "", lvl = DEBUG, res = nil, len = nil)
408
426
  return res unless id.respond_to?(:to_s)
409
427
  return res unless mth.respond_to?(:to_s)
410
428
  return res unless lvl.respond_to?(:to_i)
@@ -417,7 +435,7 @@ module OSlg
417
435
  return res if lvl < DEBUG
418
436
  return res if lvl > FATAL
419
437
 
420
- log(lvl, "Negative '#{id}' (#{mth})")
438
+ log(lvl, "Negative '#{id}' (#{mth})", len)
421
439
 
422
440
  res
423
441
  end
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
  #
3
- # Copyright (c) 2020-2024 Denis Bourgeois & Dan Macumber
3
+ # Copyright (c) 2020-2025 Denis Bourgeois & Dan Macumber
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the "Software"), to deal
@@ -1678,8 +1678,8 @@ module TBD
1678
1678
  # around edge with respect to a reference vector (perpendicular to the
1679
1679
  # edge), +clockwise as one is looking in the opposite position of the edge
1680
1680
  # vector. For instance, a vertical edge has a reference vector pointing
1681
- # North - surfaces eastward of the edge are (0°,180°], while surfaces
1682
- # westward of the edge are (180°,360°].
1681
+ # North - surfaces eastward of the edge are (0deg,180deg], while surfaces
1682
+ # westward of the edge are (180deg,360deg].
1683
1683
  #
1684
1684
  # Much of the following code is of a topological nature, and should ideally
1685
1685
  # (or eventually) become available functionality offered by Topolys. Topolys
@@ -1741,7 +1741,7 @@ module TBD
1741
1741
 
1742
1742
  angle = reference_V.angle(farthest_V)
1743
1743
  angle = 0 if angle.nil?
1744
- adjust = false # adjust angle [180°, 360°] if necessary
1744
+ adjust = false # adjust angle [180deg, 360deg] if necessary
1745
1745
 
1746
1746
  if vertical
1747
1747
  adjust = true if east.dot(farthest_V) < -TOL
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
  #
3
- # Copyright (c) 2020-2024 Denis Bourgeois & Dan Macumber
3
+ # Copyright (c) 2020-2025 Denis Bourgeois & Dan Macumber
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
  #
3
- # Copyright (c) 2020-2024 Denis Bourgeois & Dan Macumber
3
+ # Copyright (c) 2020-2025 Denis Bourgeois & Dan Macumber
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the "Software"), to deal
@@ -422,8 +422,8 @@ module TBD
422
422
  # @param [Hash] s TBD surfaces (keys: Openstudio surface names)
423
423
  # @option s [Bool] :deratable whether surface is deratable, s[][:deratable]
424
424
  # @option s [:wall, :ceiling, :floor] :type TBD surface type
425
- # @option s [#to_f] :heating applicable heating setpoint temperature in °C
426
- # @option s [#to_f] :cooling applicable cooling setpoint temperature in °C
425
+ # @option s [#to_f] :heating applicable heating setpoint temperature in C
426
+ # @option s [#to_f] :cooling applicable cooling setpoint temperature in C
427
427
  # @option s [Hash] :windows TBD surface-specific windows e.g. s[][:windows]
428
428
  # @option s [Hash] :doors TBD surface-specific doors
429
429
  # @option s [Hash] :skylights TBD surface-specific skylights
@@ -466,7 +466,7 @@ module TBD
466
466
  ref = 1 / 5.46
467
467
  ref = 1 / 3.60 if surface[:type] == :wall
468
468
 
469
- # Adjust for lower heating setpoint (assumes -25°C design conditions).
469
+ # Adjust for lower heating setpoint (assumes -25C design conditions).
470
470
  ref *= 43 / (heating + 25) if heating < 18 && cooling > 40
471
471
 
472
472
  surface[:ref] = ref
@@ -628,8 +628,8 @@ module TBD
628
628
  end
629
629
 
630
630
  # Set up 2x heating setpoint (HSTP) "blocks" (or bins):
631
- # bloc1: spaces/zones with HSTP >= 18°C
632
- # bloc2: spaces/zones with HSTP < 18°C
631
+ # bloc1: spaces/zones with HSTP >= 18C
632
+ # bloc2: spaces/zones with HSTP < 18C
633
633
  # (ref: 2021 Quebec energy code 3.3. UA' trade-off methodology)
634
634
  # (... can be extended in the future to cover other standards)
635
635
  #
@@ -1000,7 +1000,7 @@ module TBD
1000
1000
  model = "* modèle : #{ua[:file]}" if ua.key?(:file) && lang == :fr
1001
1001
  model += " (v#{ua[:version]})" if ua.key?(:version)
1002
1002
  report << model unless model.empty?
1003
- report << "* TBD : v3.4.3"
1003
+ report << "* TBD : v3.4.5"
1004
1004
  report << "* date : #{ua[:date]}"
1005
1005
 
1006
1006
  if lang == :en