Skip to content

Commit

Permalink
EPBR-6085 update service performance page to read new keys from the f…
Browse files Browse the repository at this point in the history
…etch stats API endpoint
  • Loading branch information
barryhalper committed Jun 20, 2024
1 parent 79bc752 commit 97b4eee
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 23 deletions.
33 changes: 30 additions & 3 deletions lib/views/partial__stats_accordion.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,30 @@
})
}},
{ heading: {
text: t('service_performance.contents.epcs_upload.tables.titles.england_wales'),
text: t('service_performance.contents.epcs_upload.tables.titles.england'),
prefix: t("service_performance.contents.epcs_upload.tables.hidden.certificates_uploaded_country.#{assessment_type.downcase}"),
},
content: {
html: erb(:partial__stats_table, locals: {
assessment_type: assessment_type,
country_key: "england_wales",
values: values["England & Wales"],
country_key: "england",
values: values["England"],
show_average_rating: show_average_rating,
})
}},
{ heading: {
text: t('service_performance.contents.epcs_upload.tables.titles.wales'),
prefix: t("service_performance.contents.epcs_upload.tables.hidden.certificates_uploaded_country.#{assessment_type.downcase}"),
},
content: {
html: erb(:partial__stats_table, locals: {
assessment_type: assessment_type,
country_key: "wales",
values: values["Wales"],
show_average_rating: show_average_rating,
})
}},

{ heading: {
text: t('service_performance.contents.epcs_upload.tables.titles.northern_ireland'),
prefix: t("service_performance.contents.epcs_upload.tables.hidden.certificates_uploaded_country.#{assessment_type.downcase}"),
Expand All @@ -38,7 +51,21 @@
show_average_rating: show_average_rating,
})
}},
{ heading: {
text: t('service_performance.contents.epcs_upload.tables.titles.other'),
prefix: t("service_performance.contents.epcs_upload.tables.hidden.certificates_uploaded_country.#{assessment_type.downcase}"),
},
content: {
html: erb(:partial__stats_table, locals: {
assessment_type: assessment_type,
country_key: "other",
values: values["Other"],
show_average_rating: show_average_rating,
})
}}
] %>
<%== erb :design_system__accordion, locals: {
items: sections,
id: "accordion-#{assessment_type.downcase}",
Expand Down
4 changes: 3 additions & 1 deletion locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,10 @@ cy:
tables:
titles:
all: "Pob rhanbarth"
england_wales: "Cymru a Lloegr"
northern_ireland: "Gogledd Iwerddon"
england: "Lloegr"
wales: "Cymru"
other: "Arall"
hidden:
certificates_uploaded_all:
sap: "Tystysgrifau SAP a uwchlwythwyd ym "
Expand Down
4 changes: 3 additions & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,10 @@ en:
tables:
titles:
all: "All regions"
england_wales: "England and Wales"
northern_ireland: "Northern Ireland"
england: "England"
wales: "Wales"
other: "Other"
hidden:
certificates_uploaded_all:
sap: "SAP certificates uploaded in "
Expand Down
4 changes: 3 additions & 1 deletion spec/acceptance/view_service_performance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@

it "has the correct download links for each region" do
expect(response.body).to have_link("Download a copy of the data for all regions", href: "service-performance/download-csv?country=all")
expect(response.body).to have_link("Download a copy of the data for England and Wales", href: "service-performance/download-csv?country=england-wales")
expect(response.body).to have_link("Download a copy of the data for England", href: "service-performance/download-csv?country=england")
expect(response.body).to have_link("Download a copy of the data for Northern Ireland", href: "service-performance/download-csv?country=northern-ireland")
expect(response.body).to have_link("Download a copy of the data for Wales", href: "service-performance/download-csv?country=wales")
expect(response.body).to have_link("Download a copy of the data for Other", href: "service-performance/download-csv?country=other")
end

it "ensure all ids are unique" do
Expand Down
63 changes: 56 additions & 7 deletions spec/test_doubles/service_performance/country_stats_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,48 @@ def self.statistics

private_class_method def self.assessments_stats
{ all: ServicePerformance::Stub.body[:data][:assessments],
englandWales: [
england: [
{
"numAssessments": 121_499,
"assessmentType": "RdSAP",
"ratingAverage": 61.7122807017544,
"month": "2021-09",
"country": "England & Wales",
"country": "England",
},
{
"numAssessments": 112_499,
"assessmentType": "SAP",
"ratingAverage": 61.7122807017544,
"month": "2021-09",
"country": "England & Wales",
"country": "England",
},
{
"numAssessments": 92_124,
"assessmentType": "CEPC",
"ratingAverage": 47.7122807017544,
"month": "2021-09",
"country": "England & Wales",
"country": "England",
},
{
"numAssessments": 367,
"assessmentType": "DEC",
"ratingAverage": 0.0,
"month": "2020-09",
"country": "England & Wales",
"country": "England",
},
{
"numAssessments": 36,
"assessmentType": "DEC-RR",
"ratingAverage": 0.0,
"month": "2020-09",
"country": "England & Wales",
"country": "England",
},
{
"numAssessments": 32,
"assessmentType": "AC-CERT",
"ratingAverage": 0.0,
"month": "2020-09",
"country": "England & Wales",
"country": "England",
},
],
northernIreland: [
Expand Down Expand Up @@ -102,6 +102,55 @@ def self.statistics
"month": "2020-09",
"country": "Northern Ireland",
},
],
wales: [
{
"numAssessments": 5779,
"assessmentType": "RdSAP",
"ratingAverage": 59.1234156,
"month": "2021-09",
"country": "Wales",
},
{
"numAssessments": 4892,
"assessmentType": "SAP",
"ratingAverage": 61.7122807017544,
"month": "2021-09",
"country": "Wales",
},
{
"numAssessments": 874,
"assessmentType": "CEPC",
"ratingAverage": 47.7122807017544,
"month": "2021-09",
"country": "Wales",
},

],
other: [
{
"numAssessments": 5779,
"assessmentType": "RdSAP",
"ratingAverage": 59.1234156,
"month": "2021-09",
"country": "Other",
},
{
"numAssessments": 4892,
"assessmentType": "SAP",
"ratingAverage": 61.7122807017544,
"month": "2021-09",
"country": "Other",
},

{
"numAssessments": 26,
"assessmentType": "CEPC",
"ratingAverage": 61.7122807017544,
"month": "2021-09",
"country": "Other",
},

] }
end
end
Expand Down
19 changes: 13 additions & 6 deletions spec/unit/gateway/statistics_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
expect(response[:data][:assessments][:all].first).to match hash_including({ assessmentType: "CEPC", month: "2020-11", numAssessments: 144_533, ratingAverage: 71.85 })
end

it "returns the expected json for England & Wales" do
expect(response[:data][:assessments][:englandWales].length).to eq(6)
expect(response[:data][:assessments][:englandWales].select { |i| i[:assessmentType] == "RdSAP" }.first).to match hash_including({ assessmentType: "RdSAP",
month: "2021-09",
numAssessments: 121_499,
ratingAverage: 61.7122807017544 })
it "returns the expected json for England" do
expect(response[:data][:assessments][:england].length).to eq(6)
expect(response[:data][:assessments][:england].select { |i| i[:assessmentType] == "RdSAP" }.first).to match hash_including({ assessmentType: "RdSAP",
month: "2021-09",
numAssessments: 121_499,
ratingAverage: 61.7122807017544 })
end

it "returns the expected json for Northern Ireland" do
Expand All @@ -30,5 +30,12 @@
numAssessments: 5779,
ratingAverage: 59.1234156 })
end

it "contains the the expected countries" do
assessments = response[:data][:assessments]
%i[england wales northernIreland other].each do |country|
expect(assessments.key?(country)).to be true
end
end
end
end
14 changes: 10 additions & 4 deletions spec/unit/use_case/fetch_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@

it "contains expected json for assessments" do
expect(results[:assessments][:all].length).to eq(17)
expect(results[:assessments][:englandWales].length).to eq(6)
expect(results[:assessments][:england].length).to eq(6)
expect(results[:assessments][:northernIreland].length).to eq(6)
cepc = results[:assessments][:all].select { |i| i[:assessmentType] == "CEPC" && i[:month] == "2020-11" }

expect(cepc.first).to eq({ assessmentType: "CEPC", month: "2020-11", numAssessments: 144_533, ratingAverage: 71.85, country: "all" })
end

it "groups the assessments data by the assessment types and country" do
it "groups the assessments data by the assessment types and country", :aggregate_failures do
assessment_types = %w[SAP RdSAP CEPC DEC AC-CERT DEC-RR]
expect(results[:assessments][:grouped].length).to eq(assessment_types.length)
expect(results[:assessments][:grouped].keys - assessment_types).to eq([])

expect(results[:assessments][:grouped]["CEPC"]).to eq({
"England & Wales" => [
{ assessmentType: "CEPC", country: "England & Wales", month: "2021-09", numAssessments: 92_124, ratingAverage: 47.7122807017544 },
"England" => [
{ assessmentType: "CEPC", country: "England", month: "2021-09", numAssessments: 92_124, ratingAverage: 47.7122807017544 },
],
"Wales" => [
{ assessmentType: "CEPC", country: "Wales", month: "2021-09", numAssessments: 874, ratingAverage: 47.7122807017544 },
],
"Northern Ireland" => [
{ assessmentType: "CEPC", country: "Northern Ireland", month: "2021-09", numAssessments: 874, ratingAverage: 47.7122807017544 },
],
"Other" => [
{ assessmentType: "CEPC", country: "Other", month: "2021-09", numAssessments: 26, ratingAverage: 61.7122807017544 },
],
"all" => [
{ assessmentType: "CEPC", country: "all", month: "2020-11", numAssessments: 144_533, ratingAverage: 71.85 },
{ assessmentType: "CEPC", country: "all", month: "2021-11", numAssessments: 2837, ratingAverage: 66.24 },
Expand Down

0 comments on commit 97b4eee

Please sign in to comment.