epb_view_models 1.0.6 → 1.0.10
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +1 -0
- data/lib/epb_view_models.rb +1 -1
- data/lib/helper/xml_enums_to_output.rb +17 -18
- data/lib/presenter/rd_sap/report.rb +1 -1
- data/lib/presenter/xsd.rb +49 -0
- data/lib/view_model_boundary/node_not_found.rb +3 -0
- data/lib/view_model_boundary/xsd_files_not_found.rb +3 -0
- data/lib/view_model_domain/xsd_arguments.rb +12 -0
- data/lib/view_model_gateway/xsd_files_gateway.rb +55 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fe31a8b4317370e678562b7ce01baa5db0b8e48b8b185197c88285731a476b
|
4
|
+
data.tar.gz: 73542839d5a7ac83b87698248308e46faa5397f94c8a63758ebdfd4a93f42a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27154cc9e7eb4e48f595042cf2e100093647307e62fd6552f57d9e782d5926232fa67d0cb07c0f8767582fe6e123ec165db33efe62b7ca2fd73e237af87e9107
|
7
|
+
data.tar.gz: 2d05b80c15f37828f1da3ac56857843e21fc33b138c9bfd8109e7a74f9defb64042155a3a84fc6343e99ffea5353cc157f5d8ef6337ac2be30de29036e1c4b94
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/epb_view_models.rb
CHANGED
@@ -163,7 +163,7 @@ module Helper
|
|
163
163
|
"6" => "mechanical extract, decentralised (MEV dc)",
|
164
164
|
"7" => "balanced without heat recovery (MV)",
|
165
165
|
"8" => "balanced with heat recovery (MVHR)",
|
166
|
-
"9" => "natural with intermittent extract fans and/or passive vents.
|
166
|
+
"9" => "natural with intermittent extract fans and/or passive vents. For backwards compatibility only, do not use.",
|
167
167
|
"10" => "natural with intermittent extract fans and passive vents",
|
168
168
|
}.freeze
|
169
169
|
CYLINDER_INSULATION_THICKNESS = {
|
@@ -306,7 +306,7 @@ module Helper
|
|
306
306
|
end
|
307
307
|
|
308
308
|
def self.transaction_type(value, report_type = "2", schema_type = "")
|
309
|
-
types_of_ni = %
|
309
|
+
types_of_ni = %i[
|
310
310
|
RdSAP-Schema-NI-20.0.0
|
311
311
|
RdSAP-Schema-NI-19.0
|
312
312
|
RdSAP-Schema-NI-18.0
|
@@ -331,7 +331,7 @@ module Helper
|
|
331
331
|
end
|
332
332
|
|
333
333
|
def self.construction_age_band_lookup(value, schema_type, report_type)
|
334
|
-
types_of_sap_pre17 = %
|
334
|
+
types_of_sap_pre17 = %i[
|
335
335
|
SAP-Schema-16.3
|
336
336
|
SAP-Schema-16.2
|
337
337
|
SAP-Schema-16.1
|
@@ -346,7 +346,7 @@ module Helper
|
|
346
346
|
SAP-Schema-11.0
|
347
347
|
].freeze
|
348
348
|
|
349
|
-
schemes_that_use_not_recorded = %
|
349
|
+
schemes_that_use_not_recorded = %i[
|
350
350
|
SAP-Schema-16.3
|
351
351
|
SAP-Schema-16.2
|
352
352
|
SAP-Schema-16.1
|
@@ -357,7 +357,7 @@ module Helper
|
|
357
357
|
RdSAP-Schema-17.0
|
358
358
|
]
|
359
359
|
|
360
|
-
schemes_that_use_l = %
|
360
|
+
schemes_that_use_l = %i[
|
361
361
|
SAP-Schema-18.0.0
|
362
362
|
SAP-Schema-17.1
|
363
363
|
SAP-Schema-17.0
|
@@ -368,7 +368,7 @@ module Helper
|
|
368
368
|
RdSAP-Schema-17.0
|
369
369
|
]
|
370
370
|
|
371
|
-
schemes_that_use_0 = %
|
371
|
+
schemes_that_use_0 = %i[
|
372
372
|
SAP-Schema-16.3
|
373
373
|
SAP-Schema-16.2
|
374
374
|
SAP-Schema-16.1
|
@@ -386,7 +386,7 @@ module Helper
|
|
386
386
|
RdSAP-Schema-17.0
|
387
387
|
]
|
388
388
|
|
389
|
-
sap_schemas_ni = %
|
389
|
+
sap_schemas_ni = %i[
|
390
390
|
SAP-Schema-NI-18.0.0
|
391
391
|
SAP-Schema-NI-17.4
|
392
392
|
SAP-Schema-NI-17.3
|
@@ -402,7 +402,7 @@ module Helper
|
|
402
402
|
SAP-Schema-NI-13.0
|
403
403
|
]
|
404
404
|
|
405
|
-
rdsap_schemas_ni = %
|
405
|
+
rdsap_schemas_ni = %i[
|
406
406
|
RdSAP-Schema-NI-20.0.0
|
407
407
|
RdSAP-Schema-NI-19.0
|
408
408
|
RdSAP-Schema-NI-18.0
|
@@ -410,29 +410,29 @@ module Helper
|
|
410
410
|
RdSAP-Schema-NI-17.3
|
411
411
|
]
|
412
412
|
|
413
|
-
ni_schemas_pre_12 = %
|
413
|
+
ni_schemas_pre_12 = %i[
|
414
414
|
SAP-Schema-NI-12.0
|
415
415
|
SAP-Schema-NI-11.2
|
416
416
|
]
|
417
417
|
|
418
418
|
if value == "K" && rdsap_schemas_ni.include?(schema_type)
|
419
|
-
return CONSTRUCTION_AGE_BAND_NI["K-RdSAP-NI"]
|
419
|
+
return CONSTRUCTION_AGE_BAND_NI["K-RdSAP-NI"] || value
|
420
420
|
end
|
421
421
|
|
422
422
|
if value == "K" && sap_schemas_ni.include?(schema_type)
|
423
|
-
return CONSTRUCTION_AGE_BAND_NI["K-SAP-NI"]
|
423
|
+
return CONSTRUCTION_AGE_BAND_NI["K-SAP-NI"] || value
|
424
424
|
end
|
425
425
|
|
426
426
|
if ni_schemas_pre_12.include?(schema_type)
|
427
427
|
key = (value == "0" ? value : "#{value}-12.0")
|
428
|
-
return CONSTRUCTION_AGE_BAND_NI[key]
|
428
|
+
return CONSTRUCTION_AGE_BAND_NI[key] || value
|
429
429
|
end
|
430
430
|
|
431
431
|
if sap_schemas_ni.include?(schema_type) || rdsap_schemas_ni.include?(schema_type)
|
432
|
-
return CONSTRUCTION_AGE_BAND_NI[value]
|
432
|
+
return CONSTRUCTION_AGE_BAND_NI[value] || value
|
433
433
|
end
|
434
434
|
|
435
|
-
if value == "K" && schema_type == "SAP-Schema-12.0" && is_rdsap(report_type)
|
435
|
+
if value == "K" && schema_type == :"SAP-Schema-12.0" && is_rdsap(report_type)
|
436
436
|
return CONSTRUCTION_AGE_BAND["K-12.0"]
|
437
437
|
end
|
438
438
|
|
@@ -464,14 +464,13 @@ module Helper
|
|
464
464
|
end
|
465
465
|
|
466
466
|
def self.mechanical_ventilation(value, schema_type, report_type)
|
467
|
-
types_of_sap_pre12 = %
|
467
|
+
types_of_sap_pre12 = %i[
|
468
468
|
SAP-Schema-11.2
|
469
469
|
SAP-Schema-11.0
|
470
470
|
SAP-Schema-10.2
|
471
471
|
SAP-Schema-NI-11.2
|
472
472
|
].freeze
|
473
|
-
|
474
|
-
if types_of_sap_pre12.include?(schema_type.to_s) && is_rdsap(report_type)
|
473
|
+
if types_of_sap_pre12.include?(schema_type) && is_rdsap(report_type)
|
475
474
|
return MECHANICAL_VENTILATION["#{value}-pre12.0"]
|
476
475
|
end
|
477
476
|
|
@@ -499,7 +498,7 @@ module Helper
|
|
499
498
|
end
|
500
499
|
|
501
500
|
def self.ventilation_type(value, schema_type = "")
|
502
|
-
ni_sap = %
|
501
|
+
ni_sap = %i[
|
503
502
|
SAP-Schema-NI-16.1
|
504
503
|
SAP-Schema-NI-16.0
|
505
504
|
SAP-Schema-NI-15.0
|
@@ -31,7 +31,7 @@ module Presenter
|
|
31
31
|
co2_emissions_potential: @view_model.potential_carbon_emission,
|
32
32
|
construction_age_band:
|
33
33
|
Helper::XmlEnumsToOutput.construction_age_band_lookup(
|
34
|
-
@view_model.
|
34
|
+
@view_model.main_dwelling_construction_age_band_or_year,
|
35
35
|
@schema_type,
|
36
36
|
@view_model.report_type,
|
37
37
|
),
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Presenter
|
2
|
+
class Xsd
|
3
|
+
def get_enums_by_type(domain_arguments)
|
4
|
+
xsd_files_gateway = ViewModelGateway::XsdFilesGateway.new(domain_arguments)
|
5
|
+
|
6
|
+
begin
|
7
|
+
xsd_files = xsd_files_gateway.xsd_files
|
8
|
+
rescue ViewModelBoundary::XsdFilesNotFound => e
|
9
|
+
raise ViewModelBoundary::XsdFilesNotFound, e.message.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
hash = {}
|
13
|
+
xpath = "//xs:simpleType[@name='#{domain_arguments.simple_type}']//xs:enumeration"
|
14
|
+
|
15
|
+
xsd_files.each do |file|
|
16
|
+
doc = REXML::Document.new(File.read(file))
|
17
|
+
enums_hash = {}
|
18
|
+
REXML::XPath.each(doc, "#{xpath}/@value") do |node|
|
19
|
+
desc_path = "#{xpath}[@value='#{node.value}']//xs:annotation//xs:documentation"
|
20
|
+
enums_hash.merge!(node.value => REXML::XPath.first(doc, desc_path).children.first)
|
21
|
+
end
|
22
|
+
|
23
|
+
next if enums_hash.empty?
|
24
|
+
|
25
|
+
hash[xsd_files_gateway.schema_version(file)] = enums_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
raise ViewModelBoundary::NodeNotFound, "Node #{domain_arguments.simple_type} was not found in any of the xsd files in #{domain_arguments.xsd_dir_path} directory" if hash.empty?
|
29
|
+
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def unique_enums(domain_arguments)
|
34
|
+
uniq_enums = []
|
35
|
+
enums = get_enums_by_type(domain_arguments).values
|
36
|
+
|
37
|
+
enums.each_with_index do |_hash, i|
|
38
|
+
if i.positive? && (enums[i].to_a != enums[i + 1].to_a)
|
39
|
+
uniq_enums << enums[i]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
uniq_enums
|
43
|
+
end
|
44
|
+
|
45
|
+
def variation_between_schema_versions?(enums_hash)
|
46
|
+
enums_hash.values.flatten.uniq.count != 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ViewModelDomain
|
2
|
+
class XsdArguments
|
3
|
+
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :gem_path
|
4
|
+
|
5
|
+
def initialize(simple_type:, assessment_type:, xsd_dir_path: "/api/schemas/xml/**/", gem_path: "")
|
6
|
+
@simple_type = simple_type
|
7
|
+
@assessment_type = assessment_type
|
8
|
+
@xsd_dir_path = xsd_dir_path
|
9
|
+
@gem_path = gem_path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ViewModelGateway
|
2
|
+
class XsdFilesGateway
|
3
|
+
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :glob_path
|
4
|
+
|
5
|
+
def initialize(domain_arguments)
|
6
|
+
@simple_type = domain_arguments.simple_type
|
7
|
+
@assessment_type = domain_arguments.assessment_type
|
8
|
+
@xsd_dir_path = domain_arguments.xsd_dir_path
|
9
|
+
@dir_path = Dir.pwd if domain_arguments.gem_path.nil? || domain_arguments.gem_path.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def schema_version(file)
|
13
|
+
api_path = "api/schemas/xml/"
|
14
|
+
api_path_start = file.index(api_path) + api_path.length
|
15
|
+
schema_version = file[api_path_start..].split("/").first
|
16
|
+
sap_defnied_in_rdsap_dir?(file) ? "#{schema_version}/SAP" : schema_version
|
17
|
+
end
|
18
|
+
|
19
|
+
def xsd_files
|
20
|
+
files = case @assessment_type.downcase
|
21
|
+
when "sap"
|
22
|
+
sap_xsd_files
|
23
|
+
when "rdsap"
|
24
|
+
rdsap_xsd_files
|
25
|
+
when "cepc"
|
26
|
+
cepc_xsd_files
|
27
|
+
end
|
28
|
+
|
29
|
+
raise ViewModelBoundary::XsdFilesNotFound, "No xsd files were found in #{@glob_path} directory" if files.nil? || files.empty?
|
30
|
+
|
31
|
+
files
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def sap_defnied_in_rdsap_dir?(file)
|
37
|
+
assessment_type == "SAP" && file.end_with?("SAP-Domains.xsd")
|
38
|
+
end
|
39
|
+
|
40
|
+
def sap_xsd_files
|
41
|
+
@glob_path = "#{@dir_path + xsd_dir_path}*-Domains.xsd"
|
42
|
+
Dir.glob(@glob_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def rdsap_xsd_files
|
46
|
+
@glob_path = "#{@dir_path + xsd_dir_path}*-Domains.xsd"
|
47
|
+
Dir.glob(@glob_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def cepc_xsd_files
|
51
|
+
@glob_path = "#{@dir_path + xsd_dir_path}Reported-Data.xsd"
|
52
|
+
Dir.glob(@glob_path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epb_view_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MHCLG Energy Performance of Buildings
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -1661,6 +1661,7 @@ files:
|
|
1661
1661
|
- lib/presenter/sap/recommendation_report.rb
|
1662
1662
|
- lib/presenter/sap/report.rb
|
1663
1663
|
- lib/presenter/sap/summary.rb
|
1664
|
+
- lib/presenter/xsd.rb
|
1664
1665
|
- lib/view_model/ac_cert_wrapper.rb
|
1665
1666
|
- lib/view_model/ac_report_wrapper.rb
|
1666
1667
|
- lib/view_model/base_view_model.rb
|
@@ -1820,6 +1821,10 @@ files:
|
|
1820
1821
|
- lib/view_model/sap_schema_ni_174/common_schema.rb
|
1821
1822
|
- lib/view_model/sap_schema_ni_1800/common_schema.rb
|
1822
1823
|
- lib/view_model/sap_wrapper.rb
|
1824
|
+
- lib/view_model_boundary/node_not_found.rb
|
1825
|
+
- lib/view_model_boundary/xsd_files_not_found.rb
|
1826
|
+
- lib/view_model_domain/xsd_arguments.rb
|
1827
|
+
- lib/view_model_gateway/xsd_files_gateway.rb
|
1823
1828
|
homepage: https://github.com/communitiesuk/epb-view-models
|
1824
1829
|
licenses:
|
1825
1830
|
- MIT
|