-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
819 lines (803 loc) · 36.1 KB
/
bot.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
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
console.log('ObitBot is starting...');
// Ensure node packages are installed
var Twit = require('twit');
var config = require('./config');
var exec = require('child_process').exec;
var fs = require('fs');
var T = new Twit(config);
var epitaph = '';
var gender = ''
var causeOfDeath = '';
loop();
function loop() {
var now = new Date();
if ((now.getHours() % 2 !== 0) && now.getMinutes() === 0) {
tweetIt();
}
now = new Date(); // allow for time passing
var delay = 60000 - (now % 60000); // exact ms to next minute interval
setTimeout(loop, delay);
}
// Get random epitaph
function getRandomEpitaph() {
var r = Math.floor(Math.random() * 19);
switch(r) {
case 0:
epitaph = 'RIP.';
break;
case 1:
epitaph = 'Rest in peace.';
break;
case 2:
epitaph = 'In memory.';
break;
case 3:
epitaph = 'In loving memory.';
break;
case 4:
epitaph = 'Gone but not forgotten.';
break;
case 5:
epitaph = 'At rest.';
break;
case 6:
epitaph = 'Forever loved.';
break;
case 7:
epitaph = 'Forever asleep.';
break;
case 8:
epitaph = 'In remembrance.';
break;
case 9:
epitaph = 'Farewell.';
break;
case 10:
epitaph = 'Missed.';
break;
case 11:
epitaph = 'Missed by all.';
break;
case 12:
epitaph = 'Beloved.';
break;
case 13:
epitaph = 'Beloved by all.';
break;
case 14:
epitaph = 'At peace.';
break;
case 15:
epitaph = 'In our hearts.';
break;
case 16:
epitaph = 'In our thoughts.';
break;
case 17:
epitaph = 'Absent from the body.';
break;
case 18:
epitaph = 'A friend to all.';
break;
}
}
// Get random gender
function getRandomGender() {
var r = Math.floor(Math.random() * 2);
if (r == 0) {
gender = 'f';
} else {
gender = 'm';
}
}
// Get random cause of death
function getRandomCause() {
var r = Math.random() * 100;
var selector = 0;
switch (gender) {
case 'm':
if (r <= 0.0023) {
// ICD-10 Chapter 7 (Disease of the eye and adnexa)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the eye';
} else {
causeOfDeath = 'of a disease of the adnexa';
}
} else if (r <= (0.0023 + 0.0050)) {
// ICD-10 Chapter 8 (Disease of the ear and mastoid process)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the ear';
} else {
causeOfDeath = 'of a disease of the mastoid process';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422)) {
// ICD-10 Chapter 12 (Disease of the skin and subcutaneous tissue)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the skin';
} else {
causeOfDeath = 'of a disease of the subcutaneous tissue';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660)) {
// ICD-10 Chapter 13 (Disease of the musculoskeletal system and connective tissue)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the musculoskeletal system';
} else {
causeOfDeath = 'of a disease of the connective tissue';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537)) {
// ICD-10 Chapter 3 (Disease of blood and disorder of immune mechanism)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a disease of the blood';
} else if (selector == 1) {
causeOfDeath = 'of a disorder of the immune system';
} else {
causeOfDeath = 'of a form of anaemia';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439)) {
// ICD-10 Chapter 4 (Endocrine, nutritional and metabolic disease)
selector = Math.floor(Math.random() * 4);
if (selector == 0) {
causeOfDeath = 'of an endocrine disease';
} else if (selector == 1) {
causeOfDeath = 'of a nutritional disease';
} else if (selector == 2) {
causeOfDeath = 'of a metabolic disease';
} else {
selector = Math.random() * 100;
if (selector <= 6.4136) {
causeOfDeath = 'of malnutrition';
} else {
causeOfDeath = 'of diabetes mellitus'
}
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705)) {
// ICD-10 Chapter 17 (Congenital malformation, deformation and abnormality)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a congenital malformation';
} else if (selector == 1) {
causeOfDeath = 'of a congenital deformation';
} else {
causeOfDeath = 'of a congenital abnormality';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608)) {
// ICD-10 Chapter 16 (Condition originating in the perinatal period)
causeOfDeath = 'of a condition originating in the perinatal period';
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497)) {
// ICD-10 Chapter 5 (Mental and behavioural disorder)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a mental disorder';
} else if (selector == 1) {
causeOfDeath = 'of a behavioural disorder';
} else {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of Alzheimer\'s disease';
} else {
causeOfDeath = 'of a form of dementia';
}
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821)) {
// ICD-10 Chapter 14 (Disease of the genitourinary system)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the genitourinary system';
} else {
selector = Math.random() * 100;
if (selector <= 4.5054) {
causeOfDeath = 'of hyperplasia of the prostate';
} else {
selector = Math.floor(Math.random() * 2)
if (selector == 0) {
causeOfDeath = 'of a disorder of the kidney';
} else {
causeOfDeath = 'of a disorder of the ureter';
}
}
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575)) {
// ICD-10 Chapter 6 (Disease of the nervous system)
causeOfDeath = 'of a disease of the nervous system';
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575 + 3.5005)) {
// ICD-10 Chapter 18 (Symptom, sign and abnormal clinical and laboratory findings)
selector = Math.floor(Math.random() * 4);
if (selector == 0) {
causeOfDeath = 'of a symptom of abnormal laboratory findings';
} else if (selector == 1) {
causeOfDeath = 'of a sign of abnormal laboratory findings';
} else if (selector == 2) {
causeOfDeath = 'of a symptom of abnormal clinical findings';
} else {
causeOfDeath = 'of a sign of abnormal clinical findings';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575 + 3.5005 + 3.5005)) {
// ICD-10 Chapter 1 (Infectious and parasitic disease)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of an infectious disease';
} else if (selector == 1) {
causeOfDeath = 'of a parasitic disease';
} else {
selector = Math.random() * 100;
if (selector <= 0.0064) {
causeOfDeath = 'of diptheria';
} else if (selector <= (0.0064 + 0.0261)) {
causeOfDeath = 'of measles';
} else if (selector <= (0.0064 + 0.0261 + 0.0570)) {
causeOfDeath = 'of whooping cough';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083)) {
causeOfDeath = 'of poliomyelitis';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844)) {
causeOfDeath = 'of tetanus';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001)) {
causeOfDeath = 'of meningococcal infection';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001 + 0.3497)) {
causeOfDeath = 'of malaria';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001 + 0.3497 + 0.5823)) {
causeOfDeath = 'of a sexually-transmitted infection';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001 + 0.3497 + 0.5823 + 7.2395)) {
causeOfDeath = 'of viral hepatitis';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001 + 0.3497 + 0.5823 + 7.2395 + 11.2284)) {
causeOfDeath = 'of an intestinal infectious disease';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001 + 0.3497 + 0.5823 + 7.2395 + 11.2284 + 18.1738)) {
causeOfDeath = 'of HIV disease';
} else if (selector <= (0.0064 + 0.0261 + 0.0570 + 0.1083 + 0.2844 + 0.3001 + 0.3497 + 0.5823 + 7.2395 + 11.2284 + 18.1738 + 29.7720)) {
causeOfDeath = 'of tuberculosis';
} else {
causeOfDeath = 'of septicaemia';
}
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575 + 3.5005 + 3.5005 + 5.0241)) {
// ICD-10 Chapter 11 (Disease of the digestive system)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the digestive system';
} else {
selector = Math.random() * 100;
if (selector <= 9.6999) {
selector = Math.floor(Math.random() * 2);
if (selector = 0) {
causeOfDeath = 'of a gastric ulcer';
} else {
causeOfDeath = 'of a duodenal ulcer';
}
} else {
causeOfDeath = 'of a disease of the liver';
}
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575 + 3.5005 + 3.5005 + 5.0241 + 9.2260)) {
// ICD-10 Chapter 10 (Disease of the respiratory system)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the respiratory system';
} else {
selector = Math.random() * 100;
if (selector <= 0.6763) {
causeOfDeath = 'of influenza';
} else if (selector <= (0.6763 + 49.5280)) {
causeOfDeath = 'of a chronic lower respiratory disease';
} else {
causeOfDeath = 'of pneumonia';
}
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575 + 3.5005 + 3.5005 + 5.0241 + 9.2260 + 10.9316)) {
// ICD-10 Chapter 20 (External cause of morbidity and mortality)
selector = Math.random() * 100;
if (selector <= 1.6567) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of exposure to smoke';
} else if (selector == 1) {
causeOfDeath = 'of exposure to fire';
} else {
causeOfDeath = 'of exposure to flames';
}
} else if (selector <= (1.6567 + 4.2351)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of accidental drowning';
} else {
causeOfDeath = 'of accidental submersion';
}
} else if (selector <= (1.6567 + 4.2351 + 6.8039)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of accidental poisoning';
} else {
causeOfDeath = 'of accidental exposure to a noxious substance';
}
} else if (selector <= (1.6567 + 4.2351 + 6.8039 + 7.4330)) {
causeOfDeath = 'of a fall';
} else if (selector <= (1.6567 + 4.2351 + 6.8039 + 7.4330 + 15.4248)) {
causeOfDeath = 'as a victim of assault';
} else if (selector <= (1.6567 + 4.2351 + 6.8039 + 7.4330 + 15.4248 + 17.3186)) {
causeOfDeath = 'of intentional self-harm';
} else if (selector <= (1.6567 + 4.2351 + 6.8039 + 7.4330 + 15.4248 + 17.3186 + 20.0778)) {
causeOfDeath = 'of a transport accident';
} else {
causeOfDeath = 'of an undefined external cause of mortality';
}
} else if (r <= (0.0023 + 0.0050 + 0.1422 + 0.2660 + 0.3537 + 0.4439 + 0.5705 + 0.9608 + 1.6497 + 2.0821 + 2.5575 + 3.5005 + 3.5005 + 5.0241 + 9.2260 + 10.9316 + 21.4441)) {
// ICD-10 Chapter 2 (Neoplasm)
selector = Math.random() * 100;
if (selector <= 1.8612) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of melanoma';
} else {
causeOfDeath = 'of a form of skin cancer';
}
} else if (selector <= (1.8612 + 3.1796)) {
causeOfDeath = 'of a benign neoplasm';
} else if (selector <= (1.8612 + 3.1796 + 3.6920)) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the lip';
} else if (selector == 1) {
causeOfDeath = 'of a malignant neoplasm of the oral cavity';
} else {
causeOfDeath = 'of a malignant neoplasm of the pharynx';
}
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776)) {
causeOfDeath = 'of a malignant neoplasm of the bladder';
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838)) {
causeOfDeath = 'of leukaemia';
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331)) {
causeOfDeath = 'of a malignant neoplasm of the oesophagus';
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331 + 4.9090)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a malignant lymphoma';
} else {
causeOfDeath = 'of multiple myeloma';
}
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331 + 4.9090 + 6.4663)) {
causeOfDeath = 'of a malignant neoplasm of the pancreas';
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331 + 4.9090 + 6.4663 + 7.2110)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the liver';
} else {
causeOfDeath = 'of a malignant neoplasm of intrahepatic bile ducts';
}
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331 + 4.9090 + 6.4663 + 7.2110 + 8.4675)) {
causeOfDeath = 'of a malignant neoplasm of the stomach';
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331 + 4.9090 + 6.4663 + 7.2110 + 8.4675 + 10.9814)) {
causeOfDeath = 'of a malignant neoplasm of the prostate';
} else if (selector <= (1.8612 + 3.1796 + 3.6920 + 4.0776 + 4.0838 + 4.1331 + 4.9090 + 6.4663 + 7.2110 + 8.4675 + 10.9814 + 12.0702)) {
selector = Math.floor(Math.random() * 5);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the colon';
} else if (selector == 1) {
causeOfDeath = 'of a malignant neoplasm of the rectosigmoid junction';
} else if (selector == 2) {
causeOfDeath = 'of a malignant neoplasm of the rectum';
} else if (selector == 3) {
causeOfDeath = 'of a malignant neoplasm of the anus';
} else {
causeOfDeath = 'of a malignant neoplasm of the anal canal';
}
} else {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the trachea';
} else if (selector == 1) {
causeOfDeath = 'of a malignant neoplasm of the bronchus';
} else {
causeOfDeath = 'of a malignant neoplasm of the lung';
}
}
} else {
// ICD-10 Chapter 9 (Disease of the circulatory system)
selector = Math.floor(Math.random() * 100);
if (selector <= 0.5084) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of acute rheumatic fever';
} else {
causeOfDeath = 'of a chronic rheumatic heart disease';
}
} else if (selector <= (0.5084 + 6.3549)) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a disease of the arteries';
} else if (selector == 1) {
causeOfDeath = 'of a disease of the arterioles';
} else {
causeOfDeath = 'of a disease of the capillaries';
}
} else if (selector <= (0.5084 + 6.3549 + 9.1139)) {
causeOfDeath = 'of a hypertensive disease';
} else if (selector <= (0.5084 + 6.3549 + 9.1139 + 28.4372)) {
causeOfDeath = 'of a cerebrovascular disease';
} else {
causeOfDeath = 'of an ischaemic heart disease';
}
}
break;
case 'f':
if (r <= 0.0030) {
// ICD-10 Chapter 7 (Disease of the eye and adnexa)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the eye';
} else {
causeOfDeath = 'of a disease of the adnexa';
}
} else if (r <= (0.0030 + 0.0046)) {
// ICD-10 Chapter 8 (Disease of the ear and mastoid process)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the ear';
} else {
causeOfDeath = 'of a disease of the mastoid process';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296)) {
// ICD-10 Chapter 15 (Pregnancy, childbirth and the puerperium)
selector = Math.floor(Math.random() * 4);
if (selector == 0) {
causeOfDeath = 'during pregnancy';
} else if (selector == 1) {
causeOfDeath = 'during childbirth';
} else if (selector == 2) {
causeOfDeath = 'during the puerperium';
} else {
selector = math.random() * 100;
if (selector <= 8.7319) {
causeOfDeath = 'due to a pregnancy with an abortive outcome';
} else if (selector <= (8.7319 + 20.8202)) {
causeOfDeath = 'due to an undefined indirect obstetric cause';
} else {
causeOfDeath = 'due to an undefined direct obstetric cause';
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246)) {
// ICD-10 Chapter 12 (Disease of the skin and subcutaneous tissue)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the skin';
} else {
causeOfDeath = 'of a disease of the subcutaneous tissue';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439)) {
// ICD-10 Chapter 3 (Disease of blood and disorder of immune mechanism)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a disease of the blood';
} else if (selector == 1) {
causeOfDeath = 'of a disorder of the immune system';
} else {
causeOfDeath = 'of a form of anaemia';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499)) {
// ICD-10 Chapter 13 (Disease of the musculoskeletal system and connective tissue)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the musculoskeletal system';
} else {
causeOfDeath = 'of a disease of the connective tissue';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512)) {
// ICD-10 Chapter 17 (Congenital malformation, deformation and abnormality)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a congenital malformation';
} else if (selector == 1) {
causeOfDeath = 'of a congenital deformation';
} else {
causeOfDeath = 'of a congenital abnormality';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493)) {
// ICD-10 Chapter 16 (Condition originating in the perinatal period)
causeOfDeath = 'of a condition originating in the perinatal period';
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234)) {
// ICD-10 Chapter 14 (Disease of the genitourinary system)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the genitourinary system';
} else {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disorder of the kidney';
} else {
causeOfDeath = 'of a disorder of the ureter';
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568)) {
// ICD-10 Chapter 5 (Mental and behavioural disorder)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a mental disorder';
} else if (selector == 1) {
causeOfDeath = 'of a behavioural disorder';
} else {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of Alzheimer\'s disease';
} else {
causeOfDeath = 'of a form of dementia';
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853)) {
// ICD-10 Chapter 1 (Infectious and parasitic disease)
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of an infectious disease';
} else if (selector == 1) {
causeOfDeath = 'of a parasitic disease';
} else {
selector = Math.random() * 100;
if (selector <= 0.0134) {
causeOfDeath = 'of diptheria';
} else if (selector <= (0.0134 + 0.0377)) {
causeOfDeath = 'of measles';
} else if (selector <= (0.0134 + 0.0377 + 0.0804)) {
causeOfDeath = 'of whooping cough';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327)) {
causeOfDeath = 'of tetanus';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419)) {
causeOfDeath = 'of poliomyelitis';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754)) {
causeOfDeath = 'of malaria';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754 + 0.3436)) {
causeOfDeath = 'of meningococcal infection';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754 + 0.3436 + 0.4466)) {
causeOfDeath = 'of a sexually-transmitted infection';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754 + 0.3436 + 0.4466 + 6.7552)) {
causeOfDeath = 'of viral hepatitis';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754 + 0.3436 + 0.4466 + 6.7552 + 12.5068)) {
causeOfDeath = 'of HIV disease';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754 + 0.3436 + 0.4466 + 6.7552 + 12.5068 + 17.6612)) {
causeOfDeath = 'of an intestinal infectious disease';
} else if (selector <= (0.0134 + 0.0377 + 0.0804 + 0.1327 + 0.1419 + 0.2754 + 0.3436 + 0.4466 + 6.7552 + 12.5068 + 17.6612 + 18.1216)) {
causeOfDeath = 'of tuberculosis';
} else {
causeOfDeath = 'of septicaemia';
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029)) {
// ICD-10 Chapter 6 (Disease of the nervous system)
causeOfDeath = 'of a disease of the nervous system';
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029 + 4.0942)) {
// ICD-10 Chapter 11 (Disease of the digestive system)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the digestive system';
} else {
selector = Math.random() * 100;
if (selector <= 13.1626) {
selector = Math.floor(Math.random() * 2);
if (selector = 0) {
causeOfDeath = 'of a gastric ulcer';
} else {
causeOfDeath = 'of a duodenal ulcer';
}
} else {
causeOfDeath = 'of a disease of the liver';
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029 + 4.0942 + 4.2203)) {
// ICD-10 Chapter 4 (Endocrine, nutritional and metabolic disease)
selector = Math.floor(Math.random() * 4);
if (selector == 0) {
causeOfDeath = 'of an endocrine disease';
} else if (selector == 1) {
causeOfDeath = 'of a nutritional disease';
} else if (selector == 2) {
causeOfDeath = 'of a metabolic disease';
} else {
selector = Math.random() * 100;
if (selector <= 7.2464) {
causeOfDeath = 'of malnutrition';
} else {
causeOfDeath = 'of diabetes mellitus'
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029 + 4.0942 + 4.2203 + 4.2633)) {
// ICD-10 Chapter 20 (External cause of morbidity and mortality)
selector = Math.random() * 100;
if (selector <= 2.5565) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of exposure to smoke';
} else if (selector == 1) {
causeOfDeath = 'of exposure to fire';
} else {
causeOfDeath = 'of exposure to flames';
}
} else if (selector <= (2.5565 + 3.5119)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of accidental drowning';
} else {
causeOfDeath = 'of accidental submersion';
}
} else if (selector <= (2.5565 + 3.5119 + 6.6338)) {
causeOfDeath = 'as a victim of assault';
} else if (selector <= (2.5565 + 3.5119 + 6.6338 + 7.7557)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of accidental poisoning';
} else {
causeOfDeath = 'of accidental exposure to a noxious substance';
}
} else if (selector <= (2.5565 + 3.5119 + 6.6338 + 7.7557 + 14.3983)) {
causeOfDeath = 'of intentional self-harm';
} else if (selector <= (2.5565 + 3.5119 + 6.6338 + 7.7557 + 14.3983 + 16.4118)) {
causeOfDeath = 'of a transport accident';
} else if (selector <= (2.5565 + 3.5119 + 6.6338 + 7.7557 + 14.3983 + 16.4118 + 16.4542)) {
causeOfDeath = 'of a fall';
} else {
causeOfDeath = 'of an undefined external cause of mortality';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029 + 4.0942 + 4.2203 + 4.2633 + 6.2166)) {
// ICD-10 Chapter 18 (Symptom, sign and abnormal clinical and laboratory findings)
selector = Math.floor(Math.random() * 4);
if (selector == 0) {
causeOfDeath = 'of a symptom of abnormal laboratory findings';
} else if (selector == 1) {
causeOfDeath = 'of a sign of abnormal laboratory findings';
} else if (selector == 2) {
causeOfDeath = 'of a symptom of abnormal clinical findings';
} else {
causeOfDeath = 'of a sign of abnormal clinical findings';
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029 + 4.0942 + 4.2203 + 4.2633 + 6.2166 + 8.5463)) {
// ICD-10 Chapter 10 (Disease of the respiratory system)
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a disease of the respiratory system';
} else {
selector = Math.random() * 100;
if (selector <= 0.9594) {
causeOfDeath = 'of influenza';
} else if (selector <= (0.9594 + 45.0315)) {
causeOfDeath = 'of a chronic lower respiratory disease';
} else {
causeOfDeath = 'of pneumonia';
}
}
} else if (r <= (0.0030 + 0.0046 + 0.1296 + 0.2246 + 0.4439 + 0.5499 + 0.5512 + 0.8493 + 2.3234 + 2.8568 + 2.9853 + 3.4029 + 4.0942 + 4.2203 + 4.2633 + 6.2166 + 8.5463 + 19.2189)) {
// ICD-10 Chapter 2 (Neoplasm)
selector = Math.random() * 100;
if (selector <= 1.5256) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of melanoma';
} else {
causeOfDeath = 'of a form of skin cancer';
}
} else if (selector <= (1.5256 + 1.5278)) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the lip';
} else if (selector == 1) {
causeOfDeath = 'of a malignant neoplasm of the oral cavity';
} else {
causeOfDeath = 'of a malignant neoplasm of the pharynx';
}
} else if (selector <= (1.5256 + 1.5278 + 1.5431)) {
causeOfDeath = 'of a malignant neoplasm of the oesophagus';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720)) {
causeOfDeath = 'of a malignant neoplasm of the bladder';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684)) {
causeOfDeath = 'of a benign neoplasm';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176)) {
causeOfDeath = 'of a malignant neoplasm of the cervix uteri';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812)) {
causeOfDeath = 'of leukaemia';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451)) {
causeOfDeath = 'of a malignant neoplasm of the corpus uteri';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the liver';
} else {
causeOfDeath = 'of a malignant neoplasm of intrahepatic bile ducts';
}
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613 + 5.1003)) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of a malignant lymphoma';
} else {
causeOfDeath = 'of multiple myeloma';
}
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613 + 5.1003 + 5.5976)) {
causeOfDeath = 'of a malignant neoplasm of the ovary';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613 + 5.1003 + 5.5976 + 6.5416)) {
causeOfDeath = 'of a malignant neoplasm of the stomach';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613 + 5.1003 + 5.5976 + 6.5416 + 7.5945)) {
causeOfDeath = 'of a malignant neoplasm of the pancreas';
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613 + 5.1003 + 5.5976 + 6.5416 + 7.5945 + 13.2414)) {
selector = Math.floor(Math.random() * 5);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the colon';
} else if (selector == 1) {
causeOfDeath = 'of a malignant neoplasm of the rectosigmoid junction';
} else if (selector == 2) {
causeOfDeath = 'of a malignant neoplasm of the rectum';
} else if (selector == 3) {
causeOfDeath = 'of a malignant neoplasm of the anus';
} else {
causeOfDeath = 'of a malignant neoplasm of the anal canal';
}
} else if (selector <= (1.5256 + 1.5278 + 1.5431 + 1.7720 + 3.7684 + 3.9176 + 3.9812 + 4.0451 + 4.8613 + 5.1003 + 5.5976 + 6.5416 + 7.5945 + 13.2414 + 17.0955)) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a malignant neoplasm of the trachea';
} else if (selector == 1) {
causeOfDeath = 'of a malignant neoplasm of the bronchus';
} else {
causeOfDeath = 'of a malignant neoplasm of the lung';
}
} else {
causeOfDeath = 'of a malignant neoplasm of the breast';
}
} else {
// ICD-10 Chapter 9 (Disease of the circulatory system)
selector = Math.floor(Math.random() * 100);
if (selector <= 0.8421) {
selector = Math.floor(Math.random() * 2);
if (selector == 0) {
causeOfDeath = 'of acute rheumatic fever';
} else {
causeOfDeath = 'of a chronic rheumatic heart disease';
}
} else if (selector <= (0.8421 + 7.2596)) {
selector = Math.floor(Math.random() * 3);
if (selector == 0) {
causeOfDeath = 'of a disease of the arteries';
} else if (selector == 1) {
causeOfDeath = 'of a disease of the arterioles';
} else {
causeOfDeath = 'of a disease of the capillaries';
}
} else if (selector <= (0.8421 + 7.2596 + 11.2708)) {
causeOfDeath = 'of a hypertensive disease';
} else if (selector <= (0.8421 + 7.2596 + 11.2708 + 33.7179)) {
causeOfDeath = 'of a cerebrovascular disease';
} else {
causeOfDeath = 'of an ischaemic heart disease';
}
}
break;
}
}
function tweetIt() {
// Get text content
getRandomEpitaph();
getRandomGender();
getRandomCause();
// Path to Processing sketch
var cmd = 'tombstone/tombstone';
exec(cmd, processing);
function processing() {
var imgFilename = 'tombstone/output.png'; // Path to image file output from Processing
var imgParams = {
encoding: 'base64'
}
var imgTomb = fs.readFileSync(imgFilename, imgParams); // Read image
T.post('media/upload', { media_data: imgTomb }, uploaded); // Upload image before tweeting
function uploaded(err, data, response) {
var id = data.media_id_string; // Read uploaded image
var tweet = {
status: 'Here lies someone who died ' + causeOfDeath + '. ' + epitaph, // Tweet text content
media_ids: [id] // Tweet image content
}
T.post('statuses/update', tweet, tweeted); // Send tweet
}
function tweeted(err, data, response) {
if (err) {
console.log('Error! Tweet not sent.');
} else {
console.log('Success! Tweet sent.');
}
}
}
}