-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart.html
1338 lines (1236 loc) · 51.3 KB
/
chart.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
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<meta charset="UTF-8" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/Chart.min.css">
<link rel="stylesheet" href="css/app.css">
<script src="js/jquery.min.js"></script>
<script src="js/popper.min.js"></script>
<!-- <script src="js/Chart.bundle.min.js"></script> -->
<script src="js/bootstrap.min.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/chartjs-plugin-zoom.js"></script>
<!-- Latest compiled and minified JavaScript -->
<title>Group Testing for COVID-19</title>
<style>
.pool-inner {
border-radius: 30px;
width: calc(100% - 10px);
height: calc(100% - 10px);
border-style: solid;
border-width: 1px;
margin: 5px;
}
.pool-grid {
/* border-style: solid; */
width: calc(100% - 20px);
height: calc(100% - 20px);
border-width: 0px;
margin: 10px;
display: grid;
grid-column-gap: 5px;
grid-template-columns: auto auto auto auto auto;
justify-content: center;
align-content: space-around;
}
.pool-outer {
width: 250px;
height: 250px;
border-style: solid;
border-width: 1px;
margin: 20px;
float: left;
}
.grid {
border-radius: 25pt;
width: 25px;
height: 25px;
border-width: 1px;
border-style: solid;
justify-content: space-around;
text-align: center;
vertical-align: middle;
}
.caption {
text-align: center;
}
.row {
padding-bottom: 20px;
}
table.table-bordered > thead > tr > th{
border:1px solid rgb(96,96,96);
}
table.table-bordered > tbody > tr > td{
border:1px solid rgb(96,96,96);
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Group Testing for COVID-19</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Introduction</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="chart.html">Simulation <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
<main role="main" class="container">
<div class="row">
<div class="col-9">
<div id="platplot" style="display: none;">
<div id="plates" class="row">
<div class="pool-outer" style="display: none;" id="pool1">
<div class="pool-inner">
<div class="pool-grid">
</div>
</div>
<div class="caption">Plate 1 (◎ patients)</div>
</div>
</div>
<div class="row">
<div id="positive">
<div class="pool-outer" style="display: none;" id="ppool">
<div class="pool-inner">
<div class="pool-grid">
</div>
</div>
<div class="caption">Number of Positive Tests</div>
</div>
</div>
<div id="patient">
<div class="pool-outer" style="display: none;" id="ppatient">
<div class="pool-inner">
<div class="pool-grid">
</div>
</div>
<div class="caption">Positive Patients</div>
</div>
</div>
</div>
<div class="row" style="padding-top: 1em;">
<div class="col-sm-4">
<div class="pool-status1 card">
<div class="card-header">Usage Ratio</div>
<div class="card-body" id="status-usage"></div>
</div>
</div>
<div class="col-sm-4">
<div class="pool-status1 card">
<div class="card-header">Sensitivity</div>
<div class="card-body" id="status-sensi"></div>
</div>
</div>
<div class="col-sm-4">
<div class="pool-status1 card">
<div class="card-header">Specificity</div>
<div class="card-body" id="status-speci"></div>
</div>
</div>
</div>
</div>
<div id="dashboard_new" class="dashboard jumbotron">
<div class="row plot_title">
<div class="d-flex flex-fill align-items-center">
<h6>Summary</h6>
</div>
<div class="d-flex flex-column justify-content-end align-items-end">
</div>
</div>
<canvas id="summary_plot"></canvas>
</div>
<div id="dashboard_compare" class="dashboard jumbotron" style="display: none;">
<div class="row plot_title">
<div class="d-flex flex-fill align-items-center">
<h6>Methods Comparison</h6>
</div>
<div class="d-flex flex-column justify-content-end align-items-end">
</div>
</div>
<canvas id="compare_plot1"></canvas>
<canvas id="compare_plot2"></canvas>
<canvas id="compare_plot3"></canvas>
</div>
<div id="compare2" style="display: none;">
<div id="dashboard_new" class="dashboard jumbotron">
<div id="opt-Comp"></div>
</div>
</div>
</div>
<div class="col-3">
<form>
<div class="form-group">Enter the method: <font color=red><span id="opt-method"></span></font><br>
<div class="form-check form-check-inline">
<input name="method_selected" id="method-1" type="radio" required>
<label class="form-check-label" for="method-1">Dorfman</label>
</div>
<div class="form-check form-check-inline">
<input name="method_selected" id="method-2" type="radio" required>
<label class="form-check-label" for="method-2">2-Grid</label>
</div>
<div class="form-check form-check-inline">
<input name="method_selected" id="method-3" type="radio" required checked>
<label class="form-check-label" for="method-3">3-Grid</label>
</div>
</div>
<div class="form-group">Infection level (p): <font color=red><span id="opt-p"></span></font><br>
<input name="range-p" id="var-p" value="40" type="range" class="form-control-range custom-range" min="1"
max="1000" />
</div>
<div class="form-group">Pool size of Dorfman's method / (w)idth of grid: <font color=red><span id="opt-N"></span></font><br>
<input name="range-N" id="var-N" value="5" type="range" class="form-control-range custom-range" min="4"
max="32" />
</div>
<!--
<div class="form-group">Enter the number of tests (K): <font color=red><span id="opt-K"></span></font><br>
<input name="range-K" id="var-K" value="1" type="range" class="form-control-range" min="1" max="1000" />
</div>
-->
<div class="form-group">
FNR of Single Test: <font color=red><span id="opt-FNR"></span></font><br>
<input name="range-FNR" value="5" id="var-FNR" type="range" class="form-control-range custom-range" min="0"
max="100" />
</div>
<div class="form-group">
FNR of Group Test: <font color=red><span id="opt-GFNR"></span></font><br>
<input name="range-GFNR" id="var-GFNR" value="10" type="range" class="form-control-range custom-range"
min="0" max="100" />
</div>
<div class="form-group">
FPR of Single Test: <font color=red><span id="opt-FPR"></span></font><br>
<input name="range-FPR" value="0" id="var-FPR" type="range" class="form-control-range custom-range" min="0"
max="100" />
</div>
<div class="form-group">
FPR of Group Test: <font color=red><span id="opt-GFPR"></span></font><br>
<input name="range-GFPR" id="var-GFPR" value="0" type="range" class="form-control-range custom-range" min="0"
max="100" />
</div>
<div class="form-group compare2" style="display: none;">
Number of confirm cases: <font color=red><span id="opt-NCC"></span></font><br>
<input name="v-confirmcase" id="var-NCC" value="17652" type="input" class="form-control" />
</div>
<div class="form-group compare2" style="display: none;">
Number of tests: <font color=red><span id="opt-NTS"></span></font><br>
<input name="v-tests" id="var-NTS" value="606375" type="input" class="form-control" />
</div>
</form>
<div class="btn-group-vertical">
<input type="button" value="Test Once" class="btn btn-outline-primary" onclick="test_once(1)">
<!--
<input type="button" value="Two-Way Group Test" class="btn btn-outline-primary" onclick="Group_Test_2W()">
<input type="button" value="Three-Way Group Test" class="btn btn-outline-primary" onclick="Group_Test_3W()">
-->
<input type="button" value="Summary" class="btn btn-outline-primary" onclick="Summary()">
<input type="button" value="Comparison" class="btn btn-outline-primary"
onclick="Methods_Comparison()">
<input type="button" value="Comparison 2" class="btn btn-outline-primary"
onclick="Methods_Comparison2()">
</div>
</div>
</div>
<!-- <span id="opt-GD"></span><br><span id="opt-G"></span><br> -->
<!-- <span id="opt-GT1"></span><br>
<span id="opt-GT2"></span><br>
<span id="opt-GT3"></span> -->
</main>
</body>
<script>
var cprofile1 = ["#0000ff", "#00ffff", "#00ff00", "#ffff00", "#ff0000"]
var cprofile2 = ["#112F41", "#0894A1", "#47AB6C", "#F2B134", "#ED553B"]
var cprofile3 = ["#955BA5", "#2D95BF", "#4EBA6F", "#F0C419", "#F15A5A"]
var pcolor = [["#C8E1B8", "#F28774"], ["#C8E1B8", "#FCD9D5", "#F28774"], ["#C8E1B8", "#FCD9D5", "#F9BDB2", "#F28774"]]
var ppatcolor = ["#20B157", "#D04753"]
var cprofile = cprofile3;
var total_line = [];
var ctx1 = document.getElementById('summary_plot').getContext('2d');
var comp1 = document.getElementById('compare_plot1').getContext('2d');
var comp2 = document.getElementById('compare_plot2').getContext('2d');
var comp3 = document.getElementById('compare_plot3').getContext('2d');
var scatterChart;
var compareChart = [];
$(document).ready(function () {
scatterChart = createPlot(ctx1, 'Infection level (p)', 'Ratio', '');
compareChart[0] = createPlot(comp1, 'Infection level (p)', 'Usage Ratio', 'Usage Ratio');
compareChart[1] = createPlot(comp2, 'Infection level (p)', 'Sensitivity', 'Sensitivity');
compareChart[2] = createPlot(comp3, 'Infection level (p)', 'Specificity', 'Specificity');
$("#summary_plot").dblclick(function () {
scatterChart.resetZoom();
});
$("#compare_plot1").dblclick(function () {
compareChart[0].resetZoom();
});
$("#compare_plot2").dblclick(function () {
compareChart[1].resetZoom();
});
$("#compare_plot3").dblclick(function () {
compareChart[2].resetZoom();
});
});
function createPlot(context, x_label, y_label, title) {
var newchart = new Chart(context, {
type: 'scatter',
options: {
scales: {
xAxes: [{
scaleLabel: {
display: true,
labelString: x_label
},
type: 'linear',
position: 'bottom'
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: y_label
},
type: 'linear',
position: 'left'
//ticks: {
// max: 1,
// min: 0,
// stepSize: 0.1
//}
}]
},
title: {
display: (title ? true : false),
text: title
},
plugins: {
zoom: {
// Container for pan options
pan: {
// Boolean to enable panning
enabled: true,
mode: 'xy',
rangeMin: {
// Format of min pan range depends on scale type
x: null,
y: null
},
rangeMax: {
// Format of max pan range depends on scale type
x: null,
y: null
},
},
// Container for zoom options
zoom: {
// Boolean to enable zooming
enabled: true,
// Enable drag-to-zoom behavior
drag: true,
// Drag-to-zoom rectangle style can be customized
drag: {
borderColor: 'rgba(0,0,0,1)',
borderWidth: 0.5,
backgroundColor: 'rgb(225,225,225,0)'
},
mode: 'xy',
rangeMin: {
// Format of min zoom range depends on scale type
x: null,
y: null
},
rangeMax: {
// Format of max zoom range depends on scale type
x: null,
y: null
},
// Speed of zoom via mouse wheel
// (percentage of zoom on a wheel event)
speed: 1,
}
}
}
}
});
total_line[newchart.id] = []
return newchart;
}
function addData(chart, label, data) {
var line_id = total_line[chart.id].length
var index = chart.data.datasets.push(
{
label: label,
data: data,
pointRadius: 2,
showLine: true,
fill: false,
borderColor: cprofile[line_id % 5]
});
chart.update();
return index;
}
function updateData(chart, label, data) {
chart.data.datasets[label].data = data;
chart.update();
}
function plotData(chart, label, data) {
if (total_line[chart.id].indexOf(label) != -1) {
updateData(chart, total_line[chart.id].indexOf(label), data);
} else {
addData(chart, label, data);
total_line[chart.id].push(label);
}
}
</script>
<script type="text/javascript">
var maxN = 40;
var method_radio = document.getElementsByName("method_selected");
var mrad1 = document.getElementById("method-1");
var mrad2 = document.getElementById("method-2");
var mrad3 = document.getElementById("method-3");
var method_selected;
var slider_p = document.getElementById("var-p");
var slider_N = document.getElementById("var-N");
slider_N.max = maxN - 1;
//var slider_K = document.getElementById("var-K");
var slider_FNR = document.getElementById("var-FNR");
var slider_GFNR = document.getElementById("var-GFNR");
slider_GFNR.min = slider_FNR.value;
var slider_FPR = document.getElementById("var-FPR");
var slider_GFPR = document.getElementById("var-GFPR");
slider_GFPR.min = slider_FPR.value;
var p = Number(slider_p.value) / Number(slider_p.max);
var N = Number(slider_N.value);
var N1 = N;
var K = 1000;//Number(slider_K.value);
var TPR = 1.0 - Number(slider_FNR.value) / 100.0;
var GTPR = 1.0 - Number(slider_GFNR.value) / 100.0;
var TNR = 1.0 - Number(slider_FPR.value) / 100.0;
var GTNR = 1.0 - Number(slider_GFPR.value) / 100.0;
var GTTPR, GTTNR, GTRat;
for (var i = 0; i < method_radio.length; ++i) {
if (method_radio[i].checked) {
method_selected = i + 1;
break;
}
}
// G: The status(patient: 1/normal: 0) in the grid.
var G = new Array(maxN);
var GTEST;
for (var i = 0; i < G.length; ++i) {
G[i] = new Array(maxN);
}
// H: The predicted status(patient: 1/normal: 0) in the grid
var H = new Array(maxN);
for (var i = 0; i < H.length; ++i) {
H[i] = new Array(maxN);
}
// Number of Positive Tests in each group test
var X = new Array(maxN);
for (var i = 0; i < X.length; ++i) {
X[i] = new Array(maxN);
}
// Positive Test in diagonal direction
var Diag = new Array(maxN);
document.getElementById("opt-method").innerHTML = method_selected;
document.getElementById("opt-p").innerHTML = p;
document.getElementById("opt-N").innerHTML = N;
//document.getElementById("opt-K").innerHTML = K;
document.getElementById("opt-FNR").innerHTML = Number(slider_FNR.value) + "%";
document.getElementById("opt-GFNR").innerHTML = Number(slider_GFNR.value) + "%";
document.getElementById("opt-FPR").innerHTML = Number(slider_FPR.value) + "%";
document.getElementById("opt-GFPR").innerHTML = Number(slider_GFPR.value) + "%";
//var maxTime = 1; // seconds
//var time = maxTime;
var idleStart = false;
//$('body').on('keydown mousemove mousedown', function(e) {
// time = maxTime; // reset
//});
var intervalId = setInterval(function () {
//time--;
//if (time <= 0) {
if (idleStart == true) {
Summary();
idleStart = false;
}
//}
}, 1000);
mrad1.oninput = function () {
for (var i = 0; i < method_radio.length; ++i) {
if (method_radio[i].checked) {
method_selected = i + 1;
break;
}
}
document.getElementById("opt-method").innerHTML = method_selected;
}
mrad2.oninput = function () {
for (var i = 0; i < method_radio.length; ++i) {
if (method_radio[i].checked) {
method_selected = i + 1;
break;
}
}
document.getElementById("opt-method").innerHTML = method_selected;
}
mrad3.oninput = function () {
for (var i = 0; i < method_radio.length; ++i) {
if (method_radio[i].checked) {
method_selected = i + 1;
break;
}
}
document.getElementById("opt-method").innerHTML = method_selected;
}
slider_p.oninput = function () {
p = Number(slider_p.value) / Number(slider_p.max);
N = Math.ceil(Math.sqrt(1.0 / p));
if (N < 4) N = 4;
if (N > slider_N.max) N = slider_N.max;
slider_N.value = N;
document.getElementById("opt-N").innerHTML = N;
document.getElementById("opt-p").innerHTML = p;
//Group_Test();
idleStart = false;
}
slider_N.oninput = function () {
N = Number(slider_N.value);
//var Np = Math.floor(Number(slider_p.max) / N / N);
//p = Np / Number(slider_p.max);
//slider_p.value = Np;
//document.getElementById("opt-p").innerHTML = p;
document.getElementById("opt-N").innerHTML = N;
//Group_Test();
idleStart = false;
}
/*
slider_K.oninput = function () {
K = Number(slider_K.value);
document.getElementById("opt-K").innerHTML = Number(slider_K.value);
Group_Test_3W();
idleStart = false;
}
*/
slider_FNR.oninput = function () {
TPR = 1 - Number(slider_FNR.value) / 100.0;
slider_GFNR.min = slider_FNR.value;
document.getElementById("opt-FNR").innerHTML = Number(slider_FNR.value) + "%";
document.getElementById("opt-GFNR").innerHTML = Number(slider_GFNR.value) + "%";
Group_Test();
idleStart = true;
}
slider_GFNR.oninput = function () {
GTPR = 1 - Number(slider_GFNR.value) / 100.0;
document.getElementById("opt-GFNR").innerHTML = Number(slider_GFNR.value) + "%";
Group_Test();
idleStart = true;
}
slider_FPR.oninput = function () {
TNR = 1 - Number(slider_FPR.value) / 100.0;
slider_GFPR.min = slider_FPR.value;
document.getElementById("opt-FPR").innerHTML = Number(slider_FPR.value) + "%";
document.getElementById("opt-GFPR").innerHTML = Number(slider_GFPR.value) + "%";
Group_Test();
idleStart = true;
}
slider_GFPR.oninput = function () {
GTNR = 1 - Number(slider_GFPR.value) / 100.0;
document.getElementById("opt-GFPR").innerHTML = Number(slider_GFPR.value) + "%";
Group_Test();
idleStart = true;
}
function generate(opt) {
var i, j;
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
if (Math.random() < p) {
G[i][j] = 1;
} else {
G[i][j] = 0;
}
}
G[i][N] = 0;//'N';
}
for (j = 0; j < N; ++j) {
G[N][j] = 0;//'N';
}
if (opt == 1) output_grid(0);
return;
}
function test_once(opt) {
p = Number(slider_p.value) / Number(slider_p.max);
N = Number(slider_N.value);
$("#dashboard_new").hide();
$("#dashboard_compare").hide();
$("#compare2").hide();
$(".compare2").hide();
$("#platplot").show();
var Kold = K;
K = 1;
$("#pool2").remove();
$("#pool3").remove();
if (method_selected == 1) {
N1 = 1;
Group_Test_1W();
N1 = N;
} else if (method_selected == 2) {
$("#pool1").clone().attr('id', 'pool2').insertAfter("#pool1").children('.caption').html('Plate 2(◎ patients)');
Group_Test_2W();
} else {
$("#pool1").clone().attr('id', 'pool2').insertAfter("#pool1").children('.caption').html('Plate 2(◎ patients)');
$("#pool1").clone().attr('id', 'pool3').insertAfter("#pool2").children('.caption').html('Plate 3(◎ patients)');
Group_Test_3W();
}
K = Kold;
return;
}
function output_grid(Show_Test) {
var i, j, s = "<table><tr>";
$(".pool-status").width(300);
$(".pool-status").show();
if (Show_Test >= 2) {
$(".pool-grid").html('').css('grid-template-columns', 'auto '.repeat(N));
$(".pool-outer").width(N * 25 + (N + 1) * 5 + 20);
$(".pool-outer").height(N * 25 + (N + 1) * 5 + 20).show();
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
s = s + "<td width='14pt'>" + String(G[i][j]) + "</td>";
if (G[i][j]) {
var ptext = '◎';
} else {
var ptext = '';
}
$(".pool-grid").append('<div class="grid">' + ptext + '</div>');
}
if (Show_Test >= 2) {
if (G[i][N] == 1) {
s = s + "<td>P</td>";
for (j = 0; j < N; ++j) {
$("#pool1").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', "#FCD9D5")
}
} else {
s = s + "<td>N</td>";
}
}
s = s + "</tr>";
}
}else{
$(".pool-grid").html('').css('grid-template-columns', 'auto '.repeat(N));
$(".pool-outer").width(N * 25 + (N + 1) * 5 + 20);
$(".pool-outer").height(50).show();
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
if (G[i][j]) {
var ptext = '◎';
} else {
var ptext = '';
}
$(".pool-grid").append('<div class="grid">' + ptext + '</div>');
}
}
}
if (Show_Test == 1) {
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
if (G[i][j]==1) {
$("#pool1").find('.pool-grid').children().css('background-color', "#FCD9D5");
}
}
}
}
if (Show_Test >= 2) {
s = s + "<tr>";
for (j = 0; j < N; ++j) {
if (G[N][j] == 1) {
s = s + "<td>P</td>";
for (i = 0; i < N; ++i) {
$("#pool2").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', "#FCD9D5")
}
} else {
s = s + "<td>N</td>";
}
}
s = s + "</tr>";
}
s = s + "</table>";
if (Show_Test >= 2) {
$("#ppool").show();
s = s + "<br>Number of Postive Tests:<br><table><tr>";
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
// s = s + "<td width='14pt'>" + String(X[i][j]) + "</td>";
$("#ppool").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', pcolor[Show_Test - 1][X[i][j]]).html(String(X[i][j]))
}
s = s + "</tr>";
}
s = s + "</table>";
} else {
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
if (GTEST == 1) {
$("#ppool").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', pcolor[Show_Test][1]).html(String(1))
if (H[i][j] == 1) {
$("#ppool").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', pcolor[Show_Test][2]).html(String(2))
}
}else{
$("#ppool").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', pcolor[Show_Test][0]).html(String(0))
}
}
}
}
if (Show_Test >= 2) {
s = s + "<br>Positive Patients:<br><table><tr>";
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
// s = s + "<td width='14pt'>" + String(H[i][j]) + "</td>";
$("#ppatient").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', ppatcolor[H[i][j]])
}
s = s + "</tr>";
}
}else{
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
$("#ppatient").find('.pool-grid').children('div:nth-child(' + String(i * N + j + 1) + ')').css('background-color', ppatcolor[H[i][j]])
}
}
}
s = s + "</table>";
// document.getElementById("opt-G").innerHTML = s;
if (Show_Test >= 3) {
s = "Diagonal Test Result(i-j=0,1,2,...,N-1):";
for (i = 0; i < N; ++i) {
if (Diag[i] == 1) {
s = s + "P";
} else {
s = s + "N";
}
}
// document.getElementById("opt-GD").innerHTML = s;
for (i = 0; i < N; ++i) {
if (Diag[i] == 1) {
for (j = 0; j < N; ++j) {
$("#pool3").find('.pool-grid').children('div:nth-child(' + String((i + j) % N * N + j + 1) + ')').css('background-color', "#FCD9D5")
}
}
}
}
return;
}
function Group_Test() {
if (method_selected == 1) Group_Test_1W();
else if (method_selected == 2) Group_Test_2W();
else Group_Test_3W();
}
function Group_Test_1W() {
// Dorfman's pooling test
var i, j, k, s, t, N_TP = 0, N_TN = 0, N_FP = 0, N_FN = 0, N_Test = 0;
var NM = Number(slider_N.max);
// var GTEST;
var GNTPR = GTPR;//1.0*(TPR*(NM-N)+GTPR*(N-1))/(NM-1);
var GNTNR = GTNR;//1.0*(TNR*(NM-N)+GTNR*(N-1))/(NM-1);
for (k = 0; k < K; ++k) {
generate(0);
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
H[i][j] = 0;
//X[i][j] = 0;
}
}
t = 0;
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
if (G[i][j] == 1) {
t = 1;
break;
}
}
if (t == 1) break;
}
if (Math.random() > t * (1.0 - GNTPR) + (1 - t) * GNTNR) {
GTEST = 1;
//G[N][0] = 1;
//for (i = 0; i < N; ++i) {
// for (j = 0; j < N; ++j) X[i][j]++;
//}
} else {
GTEST = 0;
//G[N][0] = 0;
}
if (GTEST == 1) {
for (i = 0; i < N1; ++i) {
for (j = 0; j < N; ++j) {
t = G[i][j];
if (Math.random() > t * (1.0 - TPR) + (1 - t) * TNR) {
H[i][j] = 1;
} else {
H[i][j] = 0;
}
}
}
N_Test += N1 * N;
}
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
if (G[i][j] == 1 && H[i][j] == 1) {
N_TP++;
} else if (G[i][j] == 1 && H[i][j] == 0) {
N_FN++;
} else if (G[i][j] == 0 && H[i][j] == 1) {
N_FP++;
} else if (G[i][j] == 0 && H[i][j] == 0) {
N_TN++;
}
}
}
N_Test += 1;
}
if (K == 1) {
output_grid(1);
}
GTTPR = 1.0 * N_TP / (N_TP + N_FN);
GTTNR = 1.0 * N_TN / (N_FP + N_TN);
GTRat = 1.0 * N_Test / (N1 * N * K);
if (K == 1) {
s = "Usage Ratio:<br>" + String(N_Test) + "/" + String(N1 * N * K) + "~" + Math.round(10000.0 * GTRat) / 100.0 + "%"
+ "<br>Sensitivity:<br>" + N_TP + "/" + (N_TP + N_FN) + "~" + Math.round(10000.0 * GTTPR) / 100.0 + "%<br>Specificity:<br>"
+ N_TN + "/" + (N_FP + N_TN) + "~" + Math.round(10000.0 * GTTNR) / 100.0 + "%<br>";
// document.getElementById("opt-GT").innerHTML = s;
document.getElementById("status-usage").innerHTML = String(N_Test) + "/" + String(N1 * N * K) + "~" + Math.round(10000.0 * GTRat) / 100.0 + "%";
document.getElementById("status-sensi").innerHTML = N_TP + "/" + (N_TP + N_FN) + "~" + Math.round(10000.0 * GTTPR) / 100.0 + "%";
document.getElementById("status-speci").innerHTML = N_TN + "/" + (N_FP + N_TN) + "~" + Math.round(10000.0 * GTTNR) / 100.0 + "%";
}
return;
}
function Group_Test_2W() {
var i, j, k, s, t, N_TP = 0, N_TN = 0, N_FP = 0, N_FN = 0, N_Test = 0;
var NM = Number(slider_N.max);
var GNTPR = GTPR;//1.0*(TPR*(NM-N)+GTPR*(N-1))/(NM-1);
var GNTNR = GTNR;//1.0*(TNR*(NM-N)+GTNR*(N-1))/(NM-1);
for (k = 0; k < K; ++k) {
generate(0);
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
H[i][j] = 0;
X[i][j] = 0;
}
}
for (i = 0; i < N; ++i) {
t = 0;
for (j = 0; j < N; ++j) {
if (G[i][j] == 1) {
t = 1;
break;
}
}
if (Math.random() > t * (1.0 - GNTPR) + (1 - t) * GNTNR) {
G[i][N] = 1;
for (j = 0; j < N; ++j) X[i][j]++;
} else {
G[i][N] = 0;
}
}
for (j = 0; j < N; ++j) {
t = 0;
for (i = 0; i < N; ++i) {
if (G[i][j] == 1) {
t = 1;
break;
}
}
if (Math.random() > t * (1.0 - GNTPR) + (1 - t) * GNTNR) {
G[N][j] = 1;
for (i = 0; i < N; ++i) X[i][j]++;
} else {
G[N][j] = 0;
}
}
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
if (X[i][j] == 2) {
t = G[i][j];
N_Test++;
if (Math.random() > t * (1.0 - TPR) + (1 - t) * TNR) {
H[i][j] = 1;
} else {
H[i][j] = 0;
}
} else {
H[i][j] = 0;
}
if (G[i][j] == 1 && H[i][j] == 1) {
N_TP++;
} else if (G[i][j] == 1 && H[i][j] == 0) {
N_FN++;
} else if (G[i][j] == 0 && H[i][j] == 1) {
N_FP++;
} else if (G[i][j] == 0 && H[i][j] == 0) {
N_TN++;
}
}
}
N_Test += 2 * N;
}
if (K == 1) {
output_grid(2);
}
GTTPR = 1.0 * N_TP / (N_TP + N_FN);
GTTNR = 1.0 * N_TN / (N_FP + N_TN);
GTRat = 1.0 * N_Test / (N * N * K);
if (K == 1) {
s = "Usage Ratio:<br>" + String(N_Test) + "/" + String(N * N * K) + "~" + Math.round(10000.0 * GTRat) / 100.0 + "%"
+ "<br>Sensitivity:<br>" + N_TP + "/" + (N_TP + N_FN) + "~" + Math.round(10000.0 * GTTPR) / 100.0 + "%<br>Specificity:<br>"
+ N_TN + "/" + (N_FP + N_TN) + "~" + Math.round(10000.0 * GTTNR) / 100.0 + "%<br>";
// document.getElementById("opt-GT").innerHTML = s;
document.getElementById("status-usage").innerHTML = String(N_Test) + "/" + String(N * N * K) + "~" + Math.round(10000.0 * GTRat) / 100.0 + "%";
document.getElementById("status-sensi").innerHTML = N_TP + "/" + (N_TP + N_FN) + "~" + Math.round(10000.0 * GTTPR) / 100.0 + "%";
document.getElementById("status-speci").innerHTML = N_TN + "/" + (N_FP + N_TN) + "~" + Math.round(10000.0 * GTTNR) / 100.0 + "%";
}
return;
}
function Group_Test_3W() {
var i, j, k, s, t, N_TP = 0, N_TN = 0, N_FP = 0, N_FN = 0, N_Test = 0;
var NM = Number(slider_N.max);
var GNTPR = GTPR;//1.0*(TPR*(NM-N)+GTPR*(N-1))/(NM-1);
var GNTNR = GTNR;//1.0*(TNR*(NM-N)+GTNR*(N-1))/(NM-1);
for (k = 0; k < K; ++k) {
generate(0);
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
H[i][j] = 0;
X[i][j] = 0;
}
}
for (i = 0; i < N; ++i) {
t = 0;
for (j = 0; j < N; ++j) {
if (G[i][j] == 1) {
t = 1;
break;
}
}
if (Math.random() > t * (1.0 - GNTPR) + (1 - t) * GNTNR) {
G[i][N] = 1;
for (j = 0; j < N; ++j) X[i][j]++;
} else {
G[i][N] = 0;
}
}
for (j = 0; j < N; ++j) {