avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 1 | <?php |
| 2 | if (php_sapi_name() != "cli") |
| 3 | exit(); |
| 4 | |
| 5 | // Font dels nombres d'habitants: https://catsalut.gencat.cat/web/.content/minisite/catsalut/proveidors_professionals/registres_catalegs/documents/poblacio-referencia.pdf |
| 6 | $HABITANTS = [ |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 7 | "AltPirineuAran" => 67277, |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 8 | "Lleida" => 362850, |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 9 | "CampDeTarragona" => 607999, |
| 10 | "TerresDeLEbre" => 176817, |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 11 | "Girona" => 861753, |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 12 | "CatalunyaCentral" => 526959, |
avm99963 | 0b3b407 | 2020-05-17 02:39:07 +0200 | [diff] [blame] | 13 | "Barcelona" => 5050190, |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 14 | "BarcelonaCiutat" => 1693449, |
| 15 | "MetropolitaSud" => 1370709, |
| 16 | "MetropolitaNord" => 1986032, |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 17 | ]; |
| 18 | |
| 19 | $CODENAME = [ |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 20 | "7100" => "AltPirineuAran", |
| 21 | "6100" => "Lleida", |
| 22 | "6200" => "CampDeTarragona", |
| 23 | "6300" => "TerresDeLEbre", |
| 24 | "6400" => "Girona", |
| 25 | "6700" => "CatalunyaCentral", |
| 26 | "7803" => "BarcelonaCiutat", |
| 27 | "7801" => "MetropolitaSud", |
| 28 | "7802" => "MetropolitaNord", |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 29 | ]; |
| 30 | |
avm99963 | c3b457a | 2020-07-21 14:23:15 +0200 | [diff] [blame] | 31 | require_once(__DIR__."/includes/generation.php"); |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 32 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 33 | // Demanem una llista del nombre de casos cada dia a cada regió sanitària |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 34 | $data = query("SELECT data, regiosanitariacodi AS regio, sum(numcasos) AS sum_numcasos |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 35 | WHERE |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 36 | ( |
| 37 | resultatcoviddescripcio = 'Positiu PCR' OR |
| 38 | resultatcoviddescripcio = 'Positiu TAR' |
| 39 | ) AND |
| 40 | regiosanitariacodi <> '0000' |
| 41 | GROUP BY regiosanitariacodi, data |
| 42 | ORDER BY data ASC, regiosanitariacodi |
avm99963 | 7e562d4 | 2020-07-15 23:27:38 +0200 | [diff] [blame] | 43 | LIMIT 50000"); |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 44 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 45 | // Fem un array que tindrà com a elements un array per cada regió amb el |
| 46 | // contingut de totes les files d'aquella regió |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 47 | $dataPerRegio = []; |
| 48 | foreach ($data as $row) { |
| 49 | if (!isset($dataPerRegio[$row["regio"]])) $dataPerRegio[$row["regio"]] = []; |
| 50 | $dataPerRegio[$row["regio"]][] = $row; |
| 51 | } |
| 52 | |
| 53 | $summary = []; |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 54 | foreach ($dataPerRegio as $regioRaw => $dataRegio) { // Per a cada regió |
| 55 | $regio = mb_strtolower($regioRaw); |
| 56 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 57 | if (!in_array($regio, array_keys($CODENAME))) |
| 58 | die("[fatal error] No tenim contemplada la regió '".$regio."'.\n"); |
| 59 | |
avm99963 | c3b457a | 2020-07-21 14:23:15 +0200 | [diff] [blame] | 60 | // Generem les dades |
avm99963 | 89b0a42 | 2021-01-05 12:02:57 +0100 | [diff] [blame^] | 61 | $summary[$regio] = generateSummary($dataRegio, $HABITANTS[$CODENAME[$regio]]); |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 62 | } |
| 63 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 64 | // Posem les dades a diversos fitxers per tal que les pugui llegir el gnuplot |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 65 | foreach ($summary as $regio => $summaryRegio) { |
| 66 | $file = fopen("/tmp/covid19graphgenerator-".$CODENAME[$regio].".dat", "w"); |
| 67 | |
avm99963 | 73e1314 | 2020-08-31 01:59:30 +0200 | [diff] [blame] | 68 | $i = 0; |
| 69 | foreach ($summaryRegio as $row) { |
| 70 | fwrite($file, $row["data"]." ".$row["ia14"]." ".$row["rho7"]." ".$i."\n"); |
| 71 | ++$i; |
| 72 | } |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 73 | |
| 74 | fclose($file); |
| 75 | } |