-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathenergy-grants-calculator.rb
449 lines (390 loc) · 13.9 KB
/
energy-grants-calculator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
module SmartAnswer
class EnergyGrantsCalculatorFlow < Flow
def define
content_id "20c0a04d-1db4-4828-bd40-bc99954ca5f9"
name 'energy-grants-calculator'
status :published
satisfies_need "100259"
# Q1
multiple_choice :what_are_you_looking_for? do
option :help_with_fuel_bill
option :help_energy_efficiency
option :help_boiler_measure
option :all_help
save_input_as :which_help
calculate :flat_type do
nil
end
calculate :may_qualify_for_affordable_warmth_obligation do
nil
end
calculate :incomesupp_jobseekers_1 do
nil
end
calculate :incomesupp_jobseekers_2 do
nil
end
calculate :age_variant do
nil
end
calculate :bills_help do |response|
%w(help_with_fuel_bill).include?(response) ? :bills_help : nil
end
calculate :measure_help do |response|
%w(help_energy_efficiency help_boiler_measure).include?(response) ? :measure_help : nil
end
calculate :both_help do |response|
%w(all_help).include?(response) ? :both_help : nil
end
calculate :warm_home_discount_amount do
''
end
next_node(permitted: :auto) do |response|
case response
when 'help_with_fuel_bill'
question :what_are_your_circumstances? # Q2
else
question :what_are_your_circumstances_without_bills_help? # Q2A
end
end
end
# Q2
checkbox_question :what_are_your_circumstances? do
option :benefits
option :property
option :permission
option :social_housing
calculate :circumstances do |response|
response.split(",")
end
calculate :benefits_claimed do
[]
end
validate(:error_perm_prop_house) { |r| ! r.include?('permission,property,social_housing') }
validate(:error_prop_house) { |r| ! r.include?('property,social_housing') }
validate(:error_perm_prop) { |r| ! r.include?('permission,property') }
validate(:error_perm_house) { |r| ! r.include?('permission,social_housing')}
next_node(:date_of_birth?) # Q3
end
# Q2A
checkbox_question :what_are_your_circumstances_without_bills_help? do
option :benefits
option :property
option :permission
calculate :circumstances do |response|
response.split(",")
end
calculate :benefits_claimed do
[]
end
validate(:error_perm_prop) { |r| ! r.include?('permission,property') }
next_node_calculation(:measure) {
%w(help_energy_efficiency help_boiler_measure).include?(which_help)
}
next_node(permitted: :auto) do |response|
if both_help
question :date_of_birth?
elsif measure
if response == 'benefits'
question :which_benefits?
else
question :when_property_built?
end
end
end
end
# Q3
date_question :date_of_birth? do
date_of_birth_defaults
calculate :age_variant do |response|
dob = response
if dob < Date.new(1951, 7, 5)
:winter_fuel_payment
elsif dob < 60.years.ago(Date.today + 1)
:over_60
end
end
next_node(permitted: :auto) do
if circumstances.include?('benefits')
question :which_benefits?
elsif bills_help
outcome :outcome_help_with_bills # outcome 1
else
question :when_property_built? # Q6
end
end
end
# Q4
checkbox_question :which_benefits? do
option :pension_credit
option :income_support
option :jsa
option :esa
option :child_tax_credit
option :working_tax_credit
option :universal_credit
calculate :benefits_claimed do |response|
response.split(",")
end
calculate :incomesupp_jobseekers_2 do |response|
if %w(working_tax_credit).include?(response)
if age_variant == :over_60
:incomesupp_jobseekers_2
end
end
end
next_node_calculation(:disabled_or_have_children_question) do |response|
response == 'income_support' ||
response == 'jsa' ||
response == 'esa' ||
response == 'working_tax_credit' ||
response.include?('universal_credit') ||
%w{child_tax_credit esa income_support jsa pension_credit}.all? {|key| response.include? key} ||
%w{child_tax_credit esa income_support pension_credit}.all? {|key| response.include? key} ||
%w{child_tax_credit esa jsa pension_credit}.all? {|key| response.include? key}
end
next_node(permitted: :auto) do |response|
if %w{pension_credit child_tax_credit}.include?(response)
if bills_help
outcome :outcome_help_with_bills # outcome 1
else
question :when_property_built? # Q6
end
elsif disabled_or_have_children_question
question :disabled_or_have_children? # Q5
elsif bills_help
outcome :outcome_help_with_bills # outcome 1
else
question :when_property_built? # Q6
end
end
end
# Q5
checkbox_question :disabled_or_have_children? do
option :disabled
option :disabled_child
option :child_under_5
option :child_under_16
option :pensioner_premium
option :work_support_esa
calculate :incomesupp_jobseekers_1 do |response|
case response
when 'disabled', 'disabled_child', 'child_under_5', 'pensioner_premium'
:incomesupp_jobseekers_1
end
end
calculate :incomesupp_jobseekers_2 do |response|
case response
when 'child_under_16', 'work_support_esa'
if circumstances.include?('social_housing') || (benefits_claimed.include?('working_tax_credit') && age_variant != :over_60)
nil
else
:incomesupp_jobseekers_2
end
end
end
calculate :may_qualify_for_affordable_warmth_obligation do |response|
response != 'none' && benefits_claimed.include?('universal_credit')
end
next_node(permitted: :auto) do
if bills_help
outcome :outcome_help_with_bills # outcome 1
else
question :when_property_built? # Q6
end
end
end
# Q6
multiple_choice :when_property_built? do
option :"on-or-after-1995"
option :"1940s-1984"
option :"before-1940"
save_input_as :property_age
calculate :modern do |response|
%w(on-or-after-1995).include?(response)
end
calculate :older do |response|
%w(1940s-1984).include?(response)
end
calculate :historic do |response|
%w(before-1940).include?(response)
end
next_node :type_of_property?
end
# Q7a
multiple_choice :type_of_property? do
option :house
option :flat
save_input_as :property_type
next_node(permitted: :auto) do |response|
case response
when 'house'
if modern
question :home_features_modern?
elsif older
question :home_features_older?
else
question :home_features_historic?
end
else
question :type_of_flat?
end
end
end
# Q7b
multiple_choice :type_of_flat? do
option :top_floor
option :ground_floor
save_input_as :flat_type
next_node(permitted: :auto) do
if modern
question :home_features_modern?
elsif older
question :home_features_older?
else
question :home_features_historic?
end
end
end
# Q8a modern
checkbox_question :home_features_modern? do
option :mains_gas
option :electric_heating
option :loft_attic_conversion
option :draught_proofing
calculate :features do |response|
response.split(",")
end
next_node_calculation(:modern_and_gas_and_electric_heating) do |response|
modern && response.include?('mains_gas') && response.include?('electric_heating')
end
next_node_calculation(:measure_help_and_property_permission_circumstance) do
measure_help && (circumstances & %w(property permission)).any?
end
next_node_calculation(:no_benefits) { circumstances.exclude?('benefits') }
next_node_calculation(:property_permission_circumstance_and_benefits) do
(circumstances & %w(property permission)).any? and ((benefits_claimed & %w(child_tax_credit esa pension_credit)).any? or incomesupp_jobseekers_1 or incomesupp_jobseekers_2)
end
next_node(permitted: :auto) do
if modern_and_gas_and_electric_heating
outcome :outcome_no_green_deal_no_energy_measures
elsif measure_help_and_property_permission_circumstance
outcome :outcome_measures_help_green_deal
elsif no_benefits
outcome :outcome_bills_and_measures_no_benefits
elsif property_permission_circumstance_and_benefits
outcome :outcome_bills_and_measures_on_benefits_eco_eligible
else
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible
end
end
end
# Q8b
checkbox_question :home_features_historic? do
option :mains_gas
option :electric_heating
option :modern_double_glazing
option :loft_attic_conversion
option :loft_insulation
option :solid_wall_insulation
option :modern_boiler
option :draught_proofing
calculate :features do |response|
response.split(",")
end
next_node_calculation(:measure_help_and_property_permission_circumstance) do
measure_help && (circumstances & %w(property permission)).any?
end
next_node_calculation(:no_benefits) { circumstances.exclude?('benefits') }
next_node_calculation(:property_permission_circumstance_and_benefits) do
(circumstances & %w(property permission)).any? and ((benefits_claimed & %w(child_tax_credit esa pension_credit)).any? or incomesupp_jobseekers_1 or incomesupp_jobseekers_2)
end
next_node(permitted: :auto) do
if measure_help_and_property_permission_circumstance
outcome :outcome_measures_help_green_deal
elsif no_benefits
outcome :outcome_bills_and_measures_no_benefits
elsif property_permission_circumstance_and_benefits
outcome :outcome_bills_and_measures_on_benefits_eco_eligible
else
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible
end
end
end
# Q8c
checkbox_question :home_features_older? do
option :mains_gas
option :electric_heating
option :modern_double_glazing
option :loft_attic_conversion
option :loft_insulation
option :solid_wall_insulation
option :cavity_wall_insulation
option :modern_boiler
option :draught_proofing
calculate :features do |response|
response.split(",")
end
next_node_calculation(:measure_help_and_property_permission_circumstance) do
measure_help && (circumstances & %w(property permission)).any?
end
next_node_calculation(:no_benefits) { circumstances.exclude?('benefits') }
next_node_calculation(:property_permission_circumstance_and_benefits) do
(circumstances & %w(property permission)).any? and ((benefits_claimed & %w(child_tax_credit esa pension_credit)).any? or incomesupp_jobseekers_1 or incomesupp_jobseekers_2)
end
next_node(permitted: :auto) do
if measure_help_and_property_permission_circumstance
outcome :outcome_measures_help_green_deal
elsif no_benefits
outcome :outcome_bills_and_measures_no_benefits
elsif property_permission_circumstance_and_benefits
outcome :outcome_bills_and_measures_on_benefits_eco_eligible
else
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible
end
end
end
outcome :outcome_help_with_bills do
precalculate :may_qualify_for_affordable_warmth_obligation do
may_qualify_for_affordable_warmth_obligation
end
precalculate :incomesupp_jobseekers_1 do
incomesupp_jobseekers_1
end
end
outcome :outcome_measures_help_green_deal do
precalculate :flat_type do
flat_type
end
end
outcome :outcome_bills_and_measures_no_benefits do
precalculate :flat_type do
flat_type
end
end
outcome :outcome_bills_and_measures_on_benefits_eco_eligible do
precalculate :may_qualify_for_affordable_warmth_obligation do
may_qualify_for_affordable_warmth_obligation
end
precalculate :incomesupp_jobseekers_1 do
incomesupp_jobseekers_1
end
precalculate :flat_type do
flat_type
end
end
outcome :outcome_bills_and_measures_on_benefits_not_eco_eligible do
precalculate :may_qualify_for_affordable_warmth_obligation do
may_qualify_for_affordable_warmth_obligation
end
precalculate :incomesupp_jobseekers_1 do
incomesupp_jobseekers_1
end
precalculate :flat_type do
flat_type
end
end
outcome :outcome_no_green_deal_no_energy_measures
end
end
end