-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
149 lines (127 loc) · 4.99 KB
/
index.html
File metadata and controls
149 lines (127 loc) · 4.99 KB
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
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
font-size: 24px;
border-collapse: collapse;
width: 80%;
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 24px;
margin: 4px 2px;
cursor: pointer;
}
input {
font-size: 24px;
}
</style>
</head>
<body>
<h2>COVID-19 Rapid Antigen Test Probabilities</h2>
<p>
<b>Specificity</b> is how likely a test is to return a positive result if
you have COVID. By default, this is set to 80%, the minimum required for
an RAT to be sold.
</p>
<p>
<b>Sensitivity</b> is how likely a test is to return a negative result if
you don't have COVID. By default, this is set to 98%, the minimum required
for an RAT to be sold.
</p>
<p>
<b>Probability</b> is how likely you are to have COVID before the test.
This should be the percentage of people in your area who have COVID if you have no symptoms. If you do have symptoms, increase the probability accordingly. I don't have the maths yet.
</p>
<table>
<tr>
<th>Variable</th>
<th>Number</th>
</tr>
<tr>
<td><b>Specificity</b> (0-100%)</td>
<td>
<input type="text" id="specificity" name="specificity" value="80" />
<td></td>
</td>
</tr>
<tr>
<td><b>Sensitivity</b> (0-100%)</td>
<td>
<input type="text" id="sensitivity" name="sensitivity" value="98" />
<td></td>
</td>
</tr>
<tr>
<td><b>Probability</b> (0-100%)</td>
<td>
<input type="text" id="probability" name="probability" value="1" />
<td></td>
</td>
</tr>
</table>
<button onclick=createParagraph()>Calculate</button>
<p id=calculationText></p>
<script>
const createParagraph = () => {
const html = getCalculation();
document.getElementById("calculationText").innerHTML = html;
}
const roundCalculation = (calculation) => {
console.log(calculation)
roundTo = (calculation < 10 || calculation > 98) ? 1 : 0
console.log(roundTo)
return calculation.toFixed(roundTo);
}
const getCalculation = () => {
let specificity = document.getElementById("specificity").value;
let sensitivity = document.getElementById("sensitivity").value;
let probability = document.getElementById("probability").value;
let inputList = new Array(specificity, sensitivity, probability);
for (const element of inputList) {
if (isNaN(element)) {
return `All inputs must be numbers.`
}
if (element <= 0 || element > 100) {
return `All inputs must be between 0 and 100. Probability cannot be 0.`
}
}
specificity = specificity / 100;
sensitivity = sensitivity / 100;
probability = probability / 100;
let true_positive = specificity * probability
let false_positive = (1 - specificity) * probability
let true_negative = sensitivity * (1 - probability)
let false_negative = (1 - sensitivity) * (1 - probability)
let positive_chance = true_positive / (true_positive + false_negative) * 100
let negative_chance = false_positive / (false_positive + true_negative) * 100
positive_text = `If you test positive for COVID-19, the chance you actually have it is ${roundCalculation(positive_chance)}%.`
negative_text = `If you test negative for COVID-19, the chance you actually have it is ${roundCalculation(negative_chance)}%.`
details_header = `Details:`
tp_text = `True Positive: The chance you have COVID-19 and test positive is ${roundCalculation(true_positive * 100)}%.`
fp_text = `False Positive: The chance you have COVID-19 but test negative is ${roundCalculation(false_positive * 100)}%.`
tn_text = `True Negative: The chance you don't have COVID-19 and test negative is ${roundCalculation(true_negative * 100)}%.`
fn_text = `False Negative: The chance you don't have COVID-19 but test positive is ${roundCalculation(false_negative * 100)}%.`
text_html = `${positive_text}<br>${negative_text}<br><br>${details_header}<br><br>${tp_text}<br>${fp_text}<br>${tn_text}<br>${fn_text}`
return text_html;
}
</script>
</body>
</html>