Skip to content

Commit

Permalink
EPBR-7646 Create RdSAP presenter and add tests for non-NI RdSAP schemas
Browse files Browse the repository at this point in the history
Create RdSAP certificate summary presenter and to_certificate_summary tests for all the non-NI RdSAP schema.
  • Loading branch information
Christine-horrocks committed Jan 23, 2025
1 parent e83d4d2 commit bb8d5af
Show file tree
Hide file tree
Showing 22 changed files with 3,358 additions and 0 deletions.
100 changes: 100 additions & 0 deletions lib/presenter/rd_sap/certificate_summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module Presenter
module RdSap
class CertificateSummary
TYPE_OF_ASSESSMENT = "RdSAP".freeze
private_constant :TYPE_OF_ASSESSMENT

def initialize(view_model)
@view_model = view_model
end

def to_certificate_summary
estimated_energy_cost =
Helper::EstimatedCostPotentialSavingHelper.new.estimated_cost(
@view_model.heating_cost_current,
@view_model.hot_water_cost_current,
@view_model.lighting_cost_current,
)
{
type_of_assessment: TYPE_OF_ASSESSMENT,
assessment_id: @view_model.assessment_id,
date_of_expiry: @view_model.date_of_expiry,
date_of_assessment: @view_model.date_of_assessment,
date_of_registration: @view_model.date_of_registration,
address: {
address_line1: @view_model.address_line1,
address_line2: @view_model.address_line2,
address_line3: @view_model.address_line3,
address_line4: nil,
town: @view_model.town,
postcode: @view_model.postcode,
},
assessor: {
scheme_assessor_id: @view_model.scheme_assessor_id,
name: @view_model.assessor_name,
contact_details: {
email: @view_model.assessor_email,
telephone: @view_model.assessor_telephone,
},
},
current_carbon_emission:
convert_to_big_decimal(@view_model.current_carbon_emission),
current_energy_efficiency_band: Helper::EnergyBandCalculator.domestic(@view_model.current_energy_rating),
current_energy_efficiency_rating: @view_model.current_energy_rating,
dwelling_type: @view_model.dwelling_type,
estimated_energy_cost:,
heat_demand: {
current_space_heating_demand:
@view_model.current_space_heating_demand&.to_i,
current_water_heating_demand:
@view_model.current_water_heating_demand&.to_i
},
heating_cost_current: @view_model.heating_cost_current,
heating_cost_potential: @view_model.heating_cost_potential,
hot_water_cost_current: @view_model.hot_water_cost_current,
hot_water_cost_potential: @view_model.hot_water_cost_potential,
lighting_cost_current: @view_model.lighting_cost_current,
lighting_cost_potential: @view_model.lighting_cost_potential,
potential_carbon_emission:
convert_to_big_decimal(@view_model.potential_carbon_emission),
potential_energy_efficiency_band: Helper::EnergyBandCalculator.domestic(@view_model.potential_energy_rating),
potential_energy_efficiency_rating: @view_model.potential_energy_rating,
potential_energy_saving:
Helper::EstimatedCostPotentialSavingHelper.new.potential_saving(
@view_model.heating_cost_potential,
@view_model.hot_water_cost_potential,
@view_model.lighting_cost_potential,
estimated_energy_cost,
),
property_summary: @view_model.property_summary,
recommended_improvements:
@view_model.improvements.map do |improvement|
improvement[:energy_performance_band_improvement] =
Helper::EnergyBandCalculator.domestic(improvement[:energy_performance_rating_improvement])
improvement
end,
lzc_energy_sources: @view_model.lzc_energy_sources,
related_party_disclosure_number: @view_model.respond_to?(:related_party_disclosure_number) ? @view_model.related_party_disclosure_number : nil,
related_party_disclosure_text:
@view_model.related_party_disclosure_text,
total_floor_area: convert_to_big_decimal(@view_model.total_floor_area),
status: @view_model.status,
co2_emissions_current_per_floor_area:
@view_model.co2_emissions_current_per_floor_area,
addendum: @view_model.addendum,
gas_smart_meter_present: @view_model.respond_to?(:gas_smart_meter_present) ? @view_model.gas_smart_meter_present : nil,
electricity_smart_meter_present: @view_model.respond_to?(:electricity_smart_meter_present) ? @view_model.electricity_smart_meter_present : nil,
country_code: @view_model.country_code,
}
end

private

def convert_to_big_decimal(node)
return "" unless node

BigDecimal(node, 0)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/view_model/rd_sap_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def initialize(xml_doc, schema_type, additional_data = {})
@schema_type = schema_type
@view_model = build_view_model(xml_doc, schema_type)
@summary = Presenter::RdSap::Summary.new(view_model)
@certificate_summary = Presenter::RdSap::CertificateSummary.new(view_model)
@report = Presenter::RdSap::Report.new(view_model, schema_type, additional_data)
@recommendation_report = Presenter::RdSap::RecommendationReport.new(view_model)
@domestic_digest = Presenter::RdSap::DomesticDigest.new(view_model, schema_type)
Expand All @@ -19,6 +20,10 @@ def to_hash
@summary.to_hash
end

def to_certificate_summary
@certificate_summary.to_certificate_summary
end

def to_hash_ni
@report.to_hash_ni
end
Expand Down
182 changes: 182 additions & 0 deletions spec/fixtures/assertions/RdSAP-Schema-17.0/to_certificate_summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"type_of_assessment":"RdSAP",
"assessment_id":"0000-0000-0000-0000-0000",
"date_of_expiry":"2030-05-03",
"date_of_assessment":"2020-05-04",
"date_of_registration":"2020-05-04",
"address": {
"address_line1":"1 Some Street",
"address_line2":"",
"address_line3":"",
"address_line4":null,
"town":"Whitbury",
"postcode":"A0 0AA"
},
"assessor":{
"scheme_assessor_id":"SPEC000000",
"name":"Testa Sessor",
"contact_details":{
"email":"a@b.c",
"telephone":"0555 497 2848"
}
},
"current_carbon_emission":2.4,
"current_energy_efficiency_band":"e",
"current_energy_efficiency_rating":50,
"dwelling_type":"Mid-terrace house",
"estimated_energy_cost":"689.83",
"heat_demand":{
"current_space_heating_demand":13120,
"current_water_heating_demand":2285
},
"heating_cost_current":"365.98",
"heating_cost_potential":"250.34",
"hot_water_cost_current":"200.40",
"hot_water_cost_potential":"180.43",
"lighting_cost_current":"123.45",
"lighting_cost_potential":"84.23",
"potential_carbon_emission":1.4,
"potential_energy_efficiency_band":"c",
"potential_energy_efficiency_rating":72,
"potential_energy_saving":"174.83",
"property_summary":[
{
"energy_efficiency_rating": 1,
"environmental_efficiency_rating": 1,
"name": "wall",
"description": "Solid brick, as built, no insulation (assumed)"
},
{
"energy_efficiency_rating": 4,
"environmental_efficiency_rating": 4,
"name": "wall",
"description": "Cavity wall, as built, insulated (assumed)"
},
{
"energy_efficiency_rating": 2,
"environmental_efficiency_rating": 2,
"name": "roof",
"description": "Pitched, 25 mm loft insulation"
},
{
"energy_efficiency_rating": 4,
"environmental_efficiency_rating": 4,
"name": "roof",
"description": "Pitched, 250 mm loft insulation"
},
{
"energy_efficiency_rating": 0,
"environmental_efficiency_rating": 0,
"name": "floor",
"description": "Suspended, no insulation (assumed)"
},
{
"energy_efficiency_rating": 0,
"environmental_efficiency_rating": 0,
"name": "floor",
"description": "Solid, insulated (assumed)"
},
{
"energy_efficiency_rating": 3,
"environmental_efficiency_rating": 3,
"name": "window",
"description": "Fully double glazed"
},
{
"energy_efficiency_rating": 3,
"environmental_efficiency_rating": 1,
"name": "main_heating",
"description": "Boiler and radiators, anthracite"
},
{
"energy_efficiency_rating": 4,
"environmental_efficiency_rating": 4,
"name": "main_heating",
"description": "Boiler and radiators, mains gas"
},
{
"energy_efficiency_rating": 4,
"environmental_efficiency_rating": 4,
"name": "main_heating_controls",
"description": "Programmer, room thermostat and TRVs"
},
{
"energy_efficiency_rating": 5,
"environmental_efficiency_rating": 5,
"name": "main_heating_controls",
"description": "Time and temperature zone control"
},
{
"energy_efficiency_rating": 4,
"environmental_efficiency_rating": 4,
"name": "hot_water",
"description": "From main system"
},
{
"energy_efficiency_rating": 4,
"environmental_efficiency_rating": 4,
"name": "lighting",
"description": "Low energy lighting in 50% of fixed outlets"
},
{
"energy_efficiency_rating": 0,
"environmental_efficiency_rating": 0,
"name": "secondary_heating",
"description": "Room heaters, electric"
}
],
"recommended_improvements":[
{
"energy_performance_rating_improvement": 50,
"environmental_impact_rating_improvement": 50,
"green_deal_category_code": "1",
"improvement_category": "6",
"improvement_code": "5",
"improvement_description": null,
"improvement_title": "",
"improvement_type": "Z3",
"indicative_cost": "£100 - £350",
"sequence": 1,
"typical_saving": "360",
"energy_performance_band_improvement": "e"
},
{
"energy_performance_rating_improvement": 60,
"environmental_impact_rating_improvement": 64,
"green_deal_category_code": "3",
"improvement_category": "2",
"improvement_code": "1",
"improvement_description": null,
"improvement_title": "",
"improvement_type": "Z2",
"indicative_cost": "2000",
"sequence": 2,
"typical_saving": "99",
"energy_performance_band_improvement": "d"
},
{
"energy_performance_rating_improvement": 60,
"environmental_impact_rating_improvement": 64,
"green_deal_category_code": "3",
"improvement_category": "2",
"improvement_code": null,
"improvement_description": "Improvement desc",
"improvement_title": "",
"improvement_type": "Z2",
"indicative_cost": "1000",
"sequence": 3,
"typical_saving": "99",
"energy_performance_band_improvement": "d"
}
],
"lzc_energy_sources":null,
"related_party_disclosure_number":null,
"related_party_disclosure_text":"No related party",
"total_floor_area":55.0,
"status":"ENTERED",
"co2_emissions_current_per_floor_area":"20",
"addendum":null,
"gas_smart_meter_present":null,
"electricity_smart_meter_present":null,
"country_code":"EAW"
}
Loading

0 comments on commit bb8d5af

Please sign in to comment.