Skip to content

Commit 846feba

Browse files
authored
Merge pull request #743 from citizensadvice/CP-1062-add-contact-waiting-time-data
chore/Add contact waiting time data [CP-1062]
2 parents 1574baa + fee4892 commit 846feba

21 files changed

+619
-309
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.cads-grid-row
2+
.cads-grid-col-md-9
3+
.section-scores
4+
%h2 Contact waiting time
5+
.cads-prose
6+
%p
7+
How long can you expect to wait when contacting this supplier?
8+
= render CsrTable::DescriptionListComponent.new do |c|
9+
- c.with_descriptions(descriptions)
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# frozen_string_literal: true
2+
3+
module CsrTable
4+
class ContactWaitingTimeScoresComponent < ViewComponent::Base
5+
attr_reader :supplier, :renderer
6+
7+
def initialize(supplier)
8+
super()
9+
@supplier = supplier
10+
@renderer = Renderers::RichTextRenderer.new
11+
end
12+
13+
def render?
14+
supplier.present?
15+
end
16+
17+
# Not all suppliers will provide data for each of the customer contact channels;
18+
# and if a supplier provides synchronous data then they won't provide
19+
# asynchronous data, and vice versa. We therefore need to determine which fields
20+
# to render based on whether there is a value present or not
21+
def descriptions
22+
descriptions = [
23+
contact_time,
24+
contact_email,
25+
sync_data,
26+
async_data
27+
]
28+
descriptions.flatten.compact
29+
end
30+
31+
def sync_data
32+
[
33+
webchat_sync,
34+
whatsapp_sync,
35+
sms_sync,
36+
in_app_sync,
37+
portal_sync
38+
]
39+
end
40+
41+
def async_data
42+
[
43+
webchat_async,
44+
whatsapp_async,
45+
sms_async,
46+
in_app_async,
47+
portal_async
48+
]
49+
end
50+
51+
def contact_time
52+
{
53+
term: content_tag(:p, "Average call centre wait time"),
54+
description: content_tag(:p, format_sync_output(supplier.contact_time))
55+
}
56+
end
57+
58+
def contact_email
59+
{
60+
term: content_tag(:p, "Emails responded to within 2 days"),
61+
description: content_tag(:p, "#{supplier.contact_email}%")
62+
}
63+
end
64+
65+
def format_sync_output(time_str)
66+
intervals = time_str.split(":").map(&:to_i)
67+
waiting_time_in_seconds = (intervals[0] * 60 * 60) + (intervals[1] * 60) + intervals[2]
68+
human_readable_time = ActiveSupport::Duration.build(waiting_time_in_seconds).inspect
69+
70+
# Render the average waiting time in this format: 1 hour 56 minutes 23 seconds
71+
human_readable_time.gsub("and ", "").delete(",")
72+
end
73+
74+
def webchat_sync
75+
return unless supplier.contact_webchat_sync
76+
77+
{
78+
term: content_tag(:p, "Average Webchat response time"),
79+
description: content_tag(:p, format_sync_output(supplier.contact_webchat_sync))
80+
}
81+
end
82+
83+
def webchat_async
84+
return unless supplier.contact_webchat_async
85+
86+
{
87+
term: content_tag(:p, "Webchat messages responded to within 2 days"),
88+
description: content_tag(:p, "#{supplier.contact_webchat_async}%")
89+
}
90+
end
91+
92+
def whatsapp_sync
93+
return unless supplier.contact_whatsapp_sync
94+
95+
{
96+
term: content_tag(:p, "Average Whatsapp response time"),
97+
description: content_tag(:p, format_sync_output(supplier.contact_whatsapp_sync))
98+
}
99+
end
100+
101+
def whatsapp_async
102+
return unless supplier.contact_whatsapp_async
103+
104+
{
105+
term: content_tag(:p, "Whatsapp messages responded to within 2 days"),
106+
description: content_tag(:p, "#{supplier.contact_whatsapp_async}%")
107+
}
108+
end
109+
110+
def sms_sync
111+
return unless supplier.contact_sms_sync
112+
113+
{
114+
term: content_tag(:p, "Average SMS response time"),
115+
description: content_tag(:p, format_sync_output(supplier.contact_sms_sync))
116+
}
117+
end
118+
119+
def sms_async
120+
return unless supplier.contact_sms_async
121+
122+
{
123+
term: content_tag(:p, "SMS messages responded to within 2 days"),
124+
description: content_tag(:p, "#{supplier.contact_sms_async}%")
125+
}
126+
end
127+
128+
def in_app_sync
129+
return unless supplier.contact_in_app_sync
130+
131+
{
132+
term: content_tag(:p, "Average response time using the supplier's app"),
133+
description: content_tag(:p, format_sync_output(supplier.contact_in_app_sync))
134+
}
135+
end
136+
137+
def in_app_async
138+
return unless supplier.contact_in_app_async
139+
140+
{
141+
term: content_tag(:p, "Messages responded to within 2 days using the supplier's app"),
142+
description: content_tag(:p, "#{supplier.contact_in_app_async}%")
143+
}
144+
end
145+
146+
def portal_sync
147+
return unless supplier.contact_portal_sync
148+
149+
{
150+
term: content_tag(:p, "Average response time using a customer account portal"),
151+
description: content_tag(:p, format_sync_output(supplier.contact_portal_sync))
152+
}
153+
end
154+
155+
def portal_async
156+
return unless supplier.contact_portal_async
157+
158+
{
159+
term: content_tag(:p, "Messages responded to within 2 days using a customer account portal"),
160+
description: content_tag(:p, "#{supplier.contact_portal_async}%")
161+
}
162+
end
163+
end
164+
end

app/controllers/queries/supplier_detail.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ module Queries
2828
contactRating,
2929
contactSocialMedia,
3030
contactTime,
31+
contactWebchatSync,
32+
contactWebchatAsync,
33+
contactWhatsappSync,
34+
contactWhatsappAsync,
35+
contactInAppSync,
36+
contactInAppAsync,
37+
contactSmsSync,
38+
contactSmsAsync,
39+
contactPortalSync,
40+
contactPortalAsync,
3141
guaranteeRating,
3242
overallRating,
3343
dataAvailable,

app/models/supplier.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class Supplier
1212
:guarantee_list, :overall_rating, :data_available, :fuel_mix,
1313
:opening_hours, :bill_accuracy_and_metering_rating,
1414
:bills_accuracy_smart, :bills_accuracy_traditional,
15-
:smart_operating, to: :data
15+
:smart_operating, :contact_webchat_sync, :contact_webchat_async,
16+
:contact_whatsapp_sync, :contact_whatsapp_async,
17+
:contact_in_app_sync, :contact_in_app_async,
18+
:contact_sms_sync, :contact_sms_async, :contact_portal_sync,
19+
:contact_portal_async, to: :data
1620

1721
def self.fetch_all
1822
response = Contentful::Graphql::Client.query(Queries::Suppliers)

app/views/csr_table/suppliers/show.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
= link_to("Find out how the scores are worked out", country_url("/consumer/energy/energy-supply/get-a-better-energy-deal/compare-domestic-energy-suppliers-customer-service1/how-the-scores-are-worked-out/"))
3535
= render CsrTable::ComplaintsScoresComponent.new(supplier)
3636
= render CsrTable::BillingAndMeteringScoresComponent.new(supplier)
37+
= render CsrTable::ContactWaitingTimeScoresComponent.new(supplier)
3738

3839
- else
3940
= render CsrTable::OtherScoresComponent.new(supplier)

spec/cassettes/supplier/big-energy-inc-details-page-scotland.yml

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)