-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotect.js
244 lines (208 loc) · 6.72 KB
/
protect.js
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
var g = {};
g.r0 = 7;
g.rate = 0;
g.l = 70;
g.show = 500;
g.hide = 200;
g.k = 0.125;
g.t = 1000;
g.i0 = 1;
g.zoom = 2;
g.a = 0;
function update () {
var b = g.r0 * g.k;
var immune = Math.round((g.t - g.i0) * (g.rate / 100.0));
var susceptible = g.t - g.i0 - immune;
var infect = Math.round(sir(g.t, g.i0, susceptible, b/g.t, g.k));
if (infect < 0)
infect = 0;
immuneP = Math.round(100.0 * immune / g.t);
infectP = Math.round(100.0 * infect / g.t);
protectP = 100 - infectP - immuneP;
if (protectP < 0)
protectP = 0;
$('#timmune').css('height',(100-immuneP)*g.zoom+'px');
$('#bimmune').css('height',immuneP*g.zoom+'px');
$('#nimmune').html(immuneP + '%');
$('#tinfect').css('height',(100-infectP)*g.zoom+'px');
$('#binfect').css('height',infectP*g.zoom+'px');
$('#ninfect').html(infectP + '%');
$('#tprotect').css('height',(100-protectP)*g.zoom+'px');
$('#bprotect').css('height',protectP*g.zoom+'px');
$('#nprotect').html(protectP + '%');
if (infectP == 0)
$('#hi').show(g.show);
else
$('#hi').hide(g.hide);
$('#anno1').html('R0=' + g.r0);
//g.a = Math.round(g.l / (g.r0 * (1.0 - immuneP / 100.0)));
//if (infectP > 0) {
// $('#anno2').show(700);
// $('#anno2').html('A=' + g.a);
// }
// else {
// $('#anno2').hide(700);
//}
}
function sir(t,i0,s0,b,k) {
var r0 = t-s0-i0;
var s1 = s0;
var i1 = i0;
var r1 = r0;
var cnt = 0;
var itot = i0;
var safe = 0;
while(1) {
safe++;
if (safe > 2000) {
//$('#debug').html('err');
break;
}
var inew = s1*i1*b;
itot += inew;
var rnew = k*i1;
var s2 = s1 - inew;
var i2 = i1 + inew - rnew;
var r2 = r1 + rnew;
if (inew < 0.1) {
cnt++;
if (cnt > 10)
break;
}
else {
cnt = 0;
}
s1=s2;
i1=i2;
r1=r2;
}
//console.log(safe);
return itot;
}
$(function() {
$('.diseasesel').click(function() {
g.disease = $(this).text();
$('#disease').html(g.disease);
update();
});
$('#vslider').slider({
min: 0,
max: 100,
value: g.rate,
tooltip: 'hide',
formater: function (v) {
return(v + "% vax");
}
});
$('#vslider').slider().on('slide', function(ev){
g.rate = ev.value;
update();
});
$('#vslider').slider().on('slideStop', function(ev){
g.rate = ev.value;
update();
});
$('#dslider').slider({
min: 2,
max: 20,
value: g.r0,
tooltip: 'hide',
formater: function (v) {
return('R0=' + v);
}
});
$('#dslider').slider().on('slide', function(ev){
g.r0 = ev.value;
update();
});
$('#dslider').slider().on('slideStop', function(ev){
g.r0 = ev.value;
update();
});
function x(tit,id) {
return '<button type="button" id="close" class="close pull-right" onclick="$("' + id + '").popover("hide");">×</button>' + '<div style="cursor: pointer;" onclick="$("' + id + '").popover("hide");" class="text-info"><strong>' + tit + '</strong></div>';
}
$('#about').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('About this demo','#about'),
content: 'This demonstration shows what happens when a partially vaccinated but otherwise susceptible population, \
is introduced to a single infection. \
<br><br>Notice that the indirectly protected percentage increases dramatically as the vaccinated percentage nears the herd immunity threshold. \
<br><br>Drag the blue slider right until a smiley face appears to find the herd immunity threshold.\
<br><br><b>Click on text (and any images that appear) for explanations</b>.'
});
$('#hi').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('Herd immunity','#hi'),
content: 'The vaccination rate is at or above the point at which the disease cannot get a hold \
and only a few people (maybe none at all) are additionally infected - the herd immunity threshold.\
<br><br>Seroconversion rates for all vaccines are less than 100% however, \
so vaccine strategies try and operate at over and above the herd immunity threshold.'
});
$('#aimmune').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('Vaccination rate','#aimmune'),
content: 'Blue slider.\
<br><br>The percentage of the population who have been vaccinated.\
<br><br>For the purposes if this demonstration a long lasting vaccine with 100% seroconversion is assumed.'
});
$('#ainfect').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('Infections','#ainfect'),
content: 'The percentage of the population who have become infected from the single infection.\
<br><br>As R0 decreases or the vaccination rate increases, \
the overall force of infection is reduced and fewer people are infected.'
});
$('#aprotect').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('Indirect protection','#aprotect'),
content: 'The percentage of the unvaccinated population who have escaped infection because they are \
indirectly protected by those who are vaccinated, or R0 is very low.\
<br><br>Those that cannot be vaccinated for age or health reasons rely on this indirect protection.\
<br><br>The effect is compromised when people don\'t vaccinate simply out of choice; freeloading. \
<br><br>Drag the blue slider left to mimick the effect of freeloaders.'
});
$('#anno1').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('Basic Reproduction Number','#anno1'),
content: 'Green slider.\
<br><br>A measure of the infectiousness of a disease. \
Higher numbers mean more infectious. \
Typical values are:-\
<br><br>Measles: 12-18\
<br>Pertussis: 12-17\
<br>Polio: 5-7\
<br>Rubella: 5-7\
<br>Mumps: 4-7\
<br>Chickenpox: 8-10\
<br>Smallpox: 5-7\
<br>Zombie infection: 20+'
});
$('#anno2').popover({
placement: 'bottom',
trigger: 'click',
html: true,
title: x('Average age of infection','#anno2'),
content: 'While mediocre vaccination rates can reduce infection and even provide some \
level of indirect protection, \
the average age of infection increases.\
<br><br>This is highly undesireable for those diseases where morbidity tends to increase with age, \
like chickenpox, \
for which good vaccination coverage and high seroconversion rate are essential.\
<br><br>A lifespan of ' + g.l + ' years is assumed for the average age calculation.'
});
$('#about').popover('show');
update();
});