Skip to content

Commit

Permalink
EPBR-5664: Update avg CO2 stubs to whole numbers
Browse files Browse the repository at this point in the history
As this will be more representative of the data returned from the warehouse and remove generation and presence of the text.html file
  • Loading branch information
al01010 committed Sep 23, 2024
1 parent 3b0d36c commit a0d7915
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8,790 deletions.
4 changes: 1 addition & 3 deletions spec/acceptance/service_performance_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def response_csv_header(body)
end

it "return a response 200 response" do
save_response_to_file(file: "test", content: response.body)
expect(response.status).to eq(200)
end

Expand Down Expand Up @@ -130,7 +129,7 @@ def response_csv_header(body)
end

it "has a csv with the correct body" do
expect(response.body).to match(/Sep-2021,23834,77.82,15.74,119033,61.74,10.88,7572,68.18,3298,402,861/)
expect(response.body).to match(/Sep-2021,23834,77.82,15,119033,61.74,10,7572,68.18,3298,402,861/)
end

it "produces a data set with correct number of rows" do
Expand All @@ -153,7 +152,6 @@ def response_csv_header(body)
end

it "return a response 200 response" do
File.write("test.html", response.body)
expect(response.status).to eq(200)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/view_service_performance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
end

it "the average CO2 values are output" do
expect(response.body).to have_css("#sap-england table.govuk-table td.average-co2-value", text: "15.74")
expect(response.body).to have_css("#rdsap-england table.govuk-table td.average-co2-value", text: "10.88")
expect(response.body).to have_css("#sap-england table.govuk-table td.average-co2-value", text: "15")
expect(response.body).to have_css("#rdsap-england table.govuk-table td.average-co2-value", text: "10")
expect(response.body).to have_css("table.govuk-table td.average-co2-value", text: "n/a")
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/test_doubles/average_co2_emissions/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def self.get_averages

def self.api_data
{ "data": [
{ "avgCo2Emission" => 10.0, "country" => "Northern Ireland", "yearMonth" => "2022-03" },
{ "avgCo2Emission" => 10.0, "country" => "England", "yearMonth" => "2022-05" },
{ "avgCo2Emission" => 10, "country" => "Northern Ireland", "yearMonth" => "2022-03" },
{ "avgCo2Emission" => 10, "country" => "England", "yearMonth" => "2022-05" },
] }.to_json
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ def self.statistics
end

private_class_method def self.assessments_stats
{ all: [{ "avgCo2Emission": 16.23655,
{ all: [{ "avgCo2Emission": 16,
"yearMonth": "2021-09",
"assessmentType": "SAP" },
{ "avgCo2Emission": 34.345225235,
{ "avgCo2Emission": 34,
"yearMonth": "2022-03",
"assessmentType": "SAP" },
{ "avgCo2Emission": 10.883267,
{ "avgCo2Emission": 10,
"yearMonth": "2021-09",
"assessmentType": "RdSAP" }],
northernIreland: [{ "avgCo2Emission": 34.345225235,
northernIreland: [{ "avgCo2Emission": 34,
"country": "Northern Ireland",
"yearMonth": "2022-03",
"assessmentType": "SAP" }],
england: [{ "avgCo2Emission": 15.7367,
england: [{ "avgCo2Emission": 15,
"country": "England",
"yearMonth": "2021-09",
"assessmentType": "SAP" },
{ "avgCo2Emission": 10.883267,
{ "avgCo2Emission": 10,
"country": "England",
"yearMonth": "2021-09",
"assessmentType": "RdSAP" }],
wales: [{ "avgCo2Emission": 16.7364,
wales: [{ "avgCo2Emission": 16,
"country": "Wales",
"yearMonth": "2022-05",
"assessmentType": "SAP" }],
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/domain/shared_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def england
{ "Month" => "Sep-2021",
"SAPs Lodged" => 23_834,
"Average SAP Energy Rating" => 77.82,
"Average SAP CO2/sqm emissions" => 15.74,
"Average SAP CO2/sqm emissions" => 15,
"RdSAPs Lodged" => 119_033,
"Average RdSAP Energy Rating" => 61.74,
"Average RdSAP CO2/sqm emissions" => 10.88,
"Average RdSAP CO2/sqm emissions" => 10,
"CEPCs Lodged" => 7572,
"Average CEPC Energy Rating" => 68.18,
"DECs Lodged" => 3298,
Expand Down Expand Up @@ -69,10 +69,10 @@ def all_countries
{ "Month" => "Sep-2021",
"SAPs Lodged" => 24_477,
"Average SAP Energy Rating" => 77.83,
"Average SAP CO2/sqm emissions" => 16.24,
"Average SAP CO2/sqm emissions" => 16,
"RdSAPs Lodged" => 121_499,
"Average RdSAP Energy Rating" => 61.71,
"Average RdSAP CO2/sqm emissions" => 10.88,
"Average RdSAP CO2/sqm emissions" => 10,
"CEPCs Lodged" => 7718,
"Average CEPC Energy Rating" => 68.27,
"DECs Lodged" => 3500,
Expand Down
18 changes: 9 additions & 9 deletions spec/unit/domain/statistics_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

describe "#match_with_warehouse" do
it "returns the matching value from the warehouse data" do
expect(domain.match_with_warehouse(month: "2021-09", country: :england, assessment_type: "RdSAP")).to eq [{ assessmentType: "RdSAP", avgCo2Emission: 10.883267, country: "England", yearMonth: "2021-09" }]
expect(domain.match_with_warehouse(month: "2022-03", country: :northernIreland, assessment_type: "SAP")).to eq [{ assessmentType: "SAP", avgCo2Emission: 34.345225235, country: "Northern Ireland", yearMonth: "2022-03" }]
expect(domain.match_with_warehouse(month: "2021-09", country: :england, assessment_type: "RdSAP")).to eq [{ assessmentType: "RdSAP", avgCo2Emission: 10, country: "England", yearMonth: "2021-09" }]
expect(domain.match_with_warehouse(month: "2022-03", country: :northernIreland, assessment_type: "SAP")).to eq [{ assessmentType: "SAP", avgCo2Emission: 34, country: "Northern Ireland", yearMonth: "2022-03" }]
end

context "when the value of the country key is ':all'" do
it "returns the matching value as expected without a country key in the data warehouse item" do
expect(domain.match_with_warehouse(month: "2021-09", country: :all, assessment_type: "SAP")).to eq [{ "avgCo2Emission": 16.23655, "yearMonth": "2021-09", "assessmentType": "SAP" }]
expect(domain.match_with_warehouse(month: "2021-09", country: :all, assessment_type: "SAP")).to eq [{ "avgCo2Emission": 16, "yearMonth": "2021-09", "assessmentType": "SAP" }]
end
end

Expand All @@ -28,8 +28,8 @@
describe "#avg_co2" do
context "when there is a match with the warehouse data" do
it "returns the average co2 for the matching data" do
matched_date_and_country = [{ assessmentType: "SAP", avgCo2Emission: 34.345225235, country: "Northern Ireland", yearMonth: "2022-03" }]
expect(domain.avg_co2(matched_date_and_country:)).to eq 34.35
matched_date_and_country = [{ assessmentType: "SAP", avgCo2Emission: 34, country: "Northern Ireland", yearMonth: "2022-03" }]
expect(domain.avg_co2(matched_date_and_country:)).to eq 34
end
end

Expand All @@ -45,7 +45,7 @@
context "when there is a CO2 value" do
it "updates the register data with the avg CO2 emission value" do
reg_data = [{ numAssessments: 20_444, assessmentType: "SAP", ratingAverage: 78.3304347826087, month: "2021-07" }]
avg_co2 = 13.56
avg_co2 = 13
date = "2021-07"
assessment_type = "SAP"
domain.update(list: reg_data, avg_co2:, date:, assessment_type:)
Expand All @@ -71,9 +71,9 @@
end

it "matches and joins the expected values" do
expect(domain.results[:england]).to include({ assessmentType: "SAP", avgCo2Emission: 15.74, country: "England", month: "2021-09", numAssessments: 112_499, ratingAverage: 61.7122807017544 })
expect(domain.results[:england]).to include({ assessmentType: "RdSAP", avgCo2Emission: 10.88, country: "England", month: "2021-09", numAssessments: 121_499, ratingAverage: 61.7122807017544 })
expect(domain.results[:all]).to include({ assessmentType: "RdSAP", avgCo2Emission: 10.88, month: "2021-09", numAssessments: 121_499, ratingAverage: 61.7122807017544 })
expect(domain.results[:england]).to include({ assessmentType: "SAP", avgCo2Emission: 15, country: "England", month: "2021-09", numAssessments: 112_499, ratingAverage: 61.7122807017544 })
expect(domain.results[:england]).to include({ assessmentType: "RdSAP", avgCo2Emission: 10, country: "England", month: "2021-09", numAssessments: 121_499, ratingAverage: 61.7122807017544 })
expect(domain.results[:all]).to include({ assessmentType: "RdSAP", avgCo2Emission: 10, month: "2021-09", numAssessments: 121_499, ratingAverage: 61.7122807017544 })
end

context "when there is no corresponding result from the warehouse data" do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/use_case/fetch_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

it "expects SAPs to have average CO2 emissions" do
england_result = results[:assessments][:grouped]["SAP"]["England"]
expect(england_result.first[:avgCo2Emission]).to eq 15.74
expect(england_result.first[:avgCo2Emission]).to eq 15
end
end

Expand Down
Loading

0 comments on commit a0d7915

Please sign in to comment.