-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsim.html
188 lines (164 loc) · 10.3 KB
/
testsim.html
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
<!DOCTYPE html>
<html>
<script src="./lib/simulation.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.1/Chart.bundle.min.js"></script>
<script src="./lib/linechart.js"></script>
<script src="./lib/simulation_display.js"></script>
<div id=base_form style="width: 100%; height: 100%">
<canvas id="line_chart"></canvas>
Core Model Parameters <br />
Population <input id=population_size type=text value=10000 /><br/>
Initial Infected Pct <input type=text id=initial_infected value=0.03 /><br/>
Testing interval (in days) <input type=text id=testing_interval_days value=3 /><br/>
Population performing interval testing <input type=text id=testing_rate value=0.6 /><br/>
PCR Random Testing Daily Rate <input type=text id=testing_rate_random_pcr value=0.003 /><br/>
Daily Vaccination Rate <input type=text id=vaccination_rate value=0.003 /><br/>
<input id="testing_rate_slider" type="range" min="0" max="100" step="1" style="display:none">
<div id="advancedParameters" style="display:none" >
<br>Advance Parameters<br>
Self-isolating symptomatic (with or without test) <input type=text id=self_isolation_rate value=0.1><br />
Self-isolating days <input type=text id=positive_test_isolation_interval value=14><br />
Daily interactions (avg) <input type=text id=num_interactions value=2.05><br />
Daily interactions (STD) <input type=text id=num_interactions_std value=0.02><br />
<br>
Rapid Testing Parameters <br />
Daily random testing rate <input type=text id=testing_rate_random value=0.0 /><br/>
False Positive percent <input type=text id=false_positive value=0.01 /><br/>
False Negative percent <input type=text id=false_negative value="0.02" /><br/>
<br>
PCR Testing Parameters <br />
Percent of population interval testing <input type=text id=testing_rate_pcr value=0.000 /><br/>
Testing interval (in days) <input type=text id=testing_interval_days_pcr value=3 /><br/>
False Positive percent <input type=text id=false_positive_pcr value=0.01 /><br/>
False Negative percent <input type=text id=false_negative_pcr value="0.02" /><br/>
Days To Results <input type=text id=days_to_pcr_reults value="1.5" /><br/>
<br>
Vaccination Parameters<br />
Delay to protection <input type=text id=vaccination_delay value="28" /><br/>
Efficacy <input type=text id=vaccination_efficacy value="0.95" /><br/>
<br>
Disease Parameters <br />
Days to Contagious <input type=text id=days_to_contagious value=3 /><br/>
Days to Detectable <input type=text id=days_to_detectable value=3.5 /><br/>
Days to Symptoms <input type=text id=days_to_symptoms value=5.5 /><br/>
Days to Recovery <input type=text id=days_to_recovery value=14.0 /><br/>
Mortality Rate <input type=text id=mortality_rate value=0.01 /><br/>
Asymptomatic Rate <input type=text id=asymptomatic_rate value=0.2 /><br/>
Recovered Resistance <input type=text id=recovered_resistance value=0.98 /><br/>
</div>
<button id="advancedParametersButton">Toggle Advanced</button>
<button id="run_simulation">Run Simulation</button>
</div>
<script>
console.log("Start");
document.getElementById('base_form').style.display='none';
function getFormParameters(form_name) {
var parameters = new SimulationParameters();
// Population Parameters
parameters.populationSize = parseInt(document.getElementById(form_name + "_" + 'population_size').value);
parameters.startingInfectionRate = parseFloat(document.getElementById(form_name + "_" + 'initial_infected').value);
parameters.positiveTestIsolationInterval = parseFloat(document.getElementById(form_name + "_" + 'positive_test_isolation_interval').value);
parameters.numInteractions = parseFloat(document.getElementById(form_name + "_" + 'num_interactions').value);
parameters.numInteractionsSTD = parseFloat(document.getElementById(form_name + "_" + 'num_interactions_std').value);
// Testing Parameters
parameters.testingInterval = parseFloat(document.getElementById(form_name + "_" + 'testing_interval_days').value);
parameters.testingRate = parseFloat(document.getElementById(form_name + "_" + 'testing_rate').value);
parameters.testingRateRandom = parseFloat(document.getElementById(form_name + "_" + 'testing_rate_random').value);
parameters.falsePositiveRate = parseFloat(document.getElementById(form_name + "_" + 'false_positive').value);
parameters.falseNegative = parseFloat(document.getElementById(form_name + "_" + 'false_negative').value);
// PCR Testing Parameters
parameters.testingRatePcr = parseFloat(document.getElementById(form_name + "_" + 'testing_rate_pcr').value);
parameters.testingRateRandomPcr = parseFloat(document.getElementById(form_name + "_" + 'testing_rate_random_pcr').value);
parameters.testingIntervalPcr = parseFloat(document.getElementById(form_name + "_" + 'testing_interval_days_pcr').value);
parameters.daysToPcrResults = parseFloat(document.getElementById(form_name + "_" + 'days_to_pcr_reults').value);
parameters.falsePositiveRatePcr = parseFloat(document.getElementById(form_name + "_" + 'false_positive_pcr').value);
parameters.falseNegativePcr = parseFloat(document.getElementById(form_name + "_" + 'false_negative_pcr').value);
// Vaccination Parameters
parameters.vaccinationRate = parseFloat(document.getElementById(form_name + "_" + 'vaccination_rate').value);
parameters.vaccinationDelay = parseFloat(document.getElementById(form_name + "_" + 'vaccination_delay').value);
parameters.vaccinationEfficacy = parseFloat(document.getElementById(form_name + "_" + 'vaccination_efficacy').value);
// Disease Parameters
parameters.daysToContagious = parseFloat(document.getElementById(form_name + "_" + 'days_to_contagious').value);
parameters.daysToDetectable = parseFloat(document.getElementById(form_name + "_" + 'days_to_detectable').value);
parameters.daysToSymptoms = parseFloat(document.getElementById(form_name + "_" + 'days_to_symptoms').value);
parameters.daysToRecovery = parseFloat(document.getElementById(form_name + "_" + 'days_to_recovery').value);
parameters.mortalityRate = parseFloat(document.getElementById(form_name + "_" + 'mortality_rate').value);
parameters.asymptomaticRate = parseFloat(document.getElementById(form_name + "_" + 'asymptomatic_rate').value);
parameters.recoveredResistance = parseFloat(document.getElementById(form_name + "_" + 'recovered_resistance').value);
// console.log(parameters.populationSize);
// console.log(parameters.startingInfectionRate);
// console.log(parameters.testingInterval);
// console.log(parameters.testingRate);
// console.log(parameters.populationSize);
// console.log(parameters.populationSize);
// console.log(parameters.populationSize);
// console.log(parameters.populationSize);
// console.log(parameters.populationSize);
// console.log(parameters.populationSize);
return parameters;
}
function toggleElement(name) {
var x = document.getElementById( name );
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function setupForm(form_name) {
base_form = base_form;
new_form = base_form.cloneNode(true); ;
new_form.setAttribute('id', form_name + "_form");
child_elements = new_form.children;
function iterateRename(child_elements) {
for (cur_element of child_elements) {
if (cur_element.id == null || cur_element.id == "") {
continue;
}
cur_element.setAttribute('id', form_name + "_" + cur_element.id );
if(cur_element.children.length>0) {
iterateRename(cur_element.children)
}
}
}
iterateRename(child_elements);
new_form.style.display = 'block';
base_form.parentNode.insertBefore(new_form, base_form.nextSibling);
line_chart_element = document.getElementById(form_name + "_line_chart");
let simulation_display;
document.getElementById(form_name + '_run_simulation').addEventListener('click', function() {
parameters = getFormParameters(form_name);
line_chart_element = document.getElementById(form_name + "_line_chart");
simulation_display=runSimulation(simulation_display,line_chart_element,parameters);
});
document.getElementById(form_name + '_advancedParametersButton').addEventListener('click', function() {
toggleElement(form_name + "_advancedParameters");
});
document.getElementById(form_name + '_testing_rate_slider').addEventListener('change', function() {
testingRate = parseFloat(document.getElementById(form_name + "_" + 'testing_rate_slider').value)/100.0;
document.getElementById(form_name + "_" + 'testing_rate').value=testingRate;
parameters = getFormParameters(form_name);
line_chart_element = document.getElementById(form_name + "_line_chart");
console.log("Fast run simulation test.");
simulation_display=runSimulation(simulation_display,line_chart_element,parameters,0);
});
}
setupForm('boop');
//setupForm('boop_badoop');
function runSimulation(simulation_display,line_chart_element, parameters,timeout=5) {
if (simulation_display) {
old_simulation_display = simulation_display;
old_simulation_display.stop();
simulation_display = new SimulationDisplay(parameters, 500);
simulation_display.getChart(old_simulation_display);
simulation_display.resetData();
simulation_display.start(timeout);
} else {
simulation_display = new SimulationDisplay(parameters, 500);
simulation_display.initChart (line_chart_element);
simulation_display.start(timeout);
}
return simulation_display;
}
</script>
</html>