epb_view_models 1.0.7 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- 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 +5 -6
- 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 +61 -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: f71a412d77bf50228e2736594bce2312c64b088dc80a7e0708b3606fcb9f3e2c
|
4
|
+
data.tar.gz: 4d2e94eafa908f2a26ea7aa09e2940fa2461ded527a620f0ebf6a29d9a34281e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82cb7dcc22da7a1d5033a65a3cd57ec67827a7dcbf31bcc45cc328de2746a376457feb120143cdc22a6f6367acb2bf5a722bb55044308d4f4cfe1bd1734914e1
|
7
|
+
data.tar.gz: 54c8b796430bb11ff37474b65b80db256fbddccdb88d516404baab6b720ff86c8ecbd2ad703bece026a0b61d0f3f75dfd0c3342100c4ee56c0bdce9d1027462a
|
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
|
@@ -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
|
@@ -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: "", 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,61 @@
|
|
1
|
+
module ViewModelGateway
|
2
|
+
class XsdFilesGateway
|
3
|
+
attr_reader :simple_type, :assessment_type, :xsd_dir_path, :glob_path
|
4
|
+
|
5
|
+
API_PATH = "api/schemas/xml/".freeze
|
6
|
+
XSD_DEFAULT_PATH = "/api/schemas/xml/**/".freeze
|
7
|
+
|
8
|
+
def initialize(domain_arguments)
|
9
|
+
@simple_type = domain_arguments.simple_type
|
10
|
+
@assessment_type = domain_arguments.assessment_type
|
11
|
+
@xsd_dir_path = domain_arguments.xsd_dir_path
|
12
|
+
@dir_path = Dir.pwd if domain_arguments.gem_path.nil? || domain_arguments.gem_path.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def schema_version(file)
|
16
|
+
api_path_start = file.index(API_PATH) + API_PATH.length
|
17
|
+
schema_version = file[api_path_start..].split("/").first
|
18
|
+
sap_defnied_in_rdsap_dir?(file) ? "#{schema_version}/SAP" : schema_version
|
19
|
+
end
|
20
|
+
|
21
|
+
def xsd_files
|
22
|
+
files = if @xsd_dir_path.nil? || @xsd_dir_path.empty?
|
23
|
+
case @assessment_type.downcase
|
24
|
+
when "sap"
|
25
|
+
sap_xsd_files
|
26
|
+
when "rdsap"
|
27
|
+
rdsap_xsd_files
|
28
|
+
when "cepc"
|
29
|
+
cepc_xsd_files
|
30
|
+
end
|
31
|
+
else
|
32
|
+
Dir.glob("#{@dir_path}#{@xsd_dir_path}")
|
33
|
+
end
|
34
|
+
|
35
|
+
raise ViewModelBoundary::XsdFilesNotFound, "No xsd files were found in #{@glob_path} directory" if files.nil? || files.empty?
|
36
|
+
|
37
|
+
files
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def sap_defnied_in_rdsap_dir?(file)
|
43
|
+
assessment_type == "SAP" && file.end_with?("SAP-Domains.xsd")
|
44
|
+
end
|
45
|
+
|
46
|
+
def sap_xsd_files
|
47
|
+
@glob_path = "#{@dir_path + XSD_DEFAULT_PATH}*-Domains.xsd"
|
48
|
+
Dir.glob(@glob_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def rdsap_xsd_files
|
52
|
+
@glob_path = "#{@dir_path + XSD_DEFAULT_PATH}*-Domains.xsd"
|
53
|
+
Dir.glob(@glob_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def cepc_xsd_files
|
57
|
+
@glob_path = "#{@dir_path + XSD_DEFAULT_PATH}Reported-Data.xsd"
|
58
|
+
Dir.glob(@glob_path)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
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.11
|
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-13 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
|