-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimport-vax.php
More file actions
104 lines (78 loc) · 2.13 KB
/
import-vax.php
File metadata and controls
104 lines (78 loc) · 2.13 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
<?php
require_once 'include.php';
use VAERS\CSVReader;
use VAERS\ESWriter;
$bulk_limit = 1000;
foreach ($years as $year)
{
echo "\n running year $year\n";
$index = ESWriter::getIndexName($year);
$vaers_vax = load_vax($year);
$es_writer = new ESWriter();
$documents = [];
foreach ($vaers_vax as $vaers_id => $vax_data)
{
if (!$vax_data ) continue;
$data = [
'VAERS_ID' => $vaers_id,
'VAX' => $vax_data['VAX_ARR'],
'NUM_VAX' => count($vax_data['VAX_ARR']),
'VAX_COMBOS' => $vax_data['COMBOS']
];
$documents[] = $data;
if (count($documents) >= $bulk_limit)
{
$es_writer->send_bulk($documents, $index,true);
$documents = [];
}
}
if ($documents) {
$es_writer->send_bulk($documents, $index,true);
}
}
/**
* @param $year
* @return array
*/
function load_vax($year): array
{
$headers_cb = function ($headers) {
return array_map(function ($header) {
return str_replace('VAX_', '', $header);
}, $headers);
};
$csv_reader = new CSVReader();
$csv_reader->setHeaderCB($headers_cb);
$data_generator = $csv_reader->lineGenerator(DATA_DIR . $year . "VAERSVAX.csv");
$vaers_vax = [];
foreach ($data_generator as $vax_row)
{
$vaers_id = $vax_row['VAERS_ID'];
unset($vax_row['VAERS_ID']);
if (!isset($vaers_vax[$vaers_id])) $vaers_vax[$vaers_id] = [];
$vaers_vax[$vaers_id][] = $vax_row;
}
//todo - foreach vaers, create VAX ngrams
$return = [];
foreach ($vaers_vax as $vaers_id => $vax_arr)
{
$vax_types = array_column($vax_arr,'TYPE');
sort($vax_types);
$combos = combos($vax_types);
$return[$vaers_id] = [
'VAX_ARR' => $vax_arr,
'COMBOS' => $combos
];
}
return $return;
}
function combos($words){
$combos = array();
$len = count($words);
for($i=0;$i+1<$len;$i++){
for($j=$i+1;$j<$len;$j++) {
$combos[]=$words[$i].'::'.$words[$j];
}
}
return $combos;
}