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 = [ |
| 7 | "Alt Pirineu i Aran" => 67277, |
| 8 | "Lleida" => 362850, |
| 9 | "Camp de Tarragona" => 607999, |
| 10 | "Terres de l'Ebre" => 176817, |
| 11 | "Girona" => 861753, |
| 12 | "Catalunya Central" => 526959, |
avm99963 | 0b3b407 | 2020-05-17 02:39:07 +0200 | [diff] [blame] | 13 | "Barcelona" => 5050190, |
| 14 | "Barcelona Ciutat" => 1693449, |
| 15 | "Metropolità Sud" => 1370709, |
| 16 | "Metropolità Nord" => 1986032, |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 17 | ]; |
| 18 | |
| 19 | $CODENAME = [ |
| 20 | "Alt Pirineu i Aran" => "AltPirineuAran", |
| 21 | "Lleida" => "Lleida", |
| 22 | "Camp de Tarragona" => "CampDeTarragona", |
| 23 | "Terres de l'Ebre" => "TerresDeLEbre", |
| 24 | "Girona" => "Girona", |
| 25 | "Catalunya Central" => "CatalunyaCentral", |
avm99963 | 0b3b407 | 2020-05-17 02:39:07 +0200 | [diff] [blame] | 26 | "Barcelona" => "Barcelona", |
| 27 | "Barcelona Ciutat" => "BarcelonaCiutat", |
| 28 | "Metropolità Sud" => "MetropolitaSud", |
| 29 | "Metropolità Nord" => "MetropolitaNord", |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 30 | ]; |
| 31 | |
avm99963 | c3b457a | 2020-07-21 14:23:15 +0200 | [diff] [blame^] | 32 | require_once(__DIR__."/includes/generation.php"); |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 33 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 34 | // Demanem una llista del nombre de casos cada dia a cada regió sanitària |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 35 | $data = query("SELECT data, regiosanitariadescripcio AS regio, sum(numcasos) AS sum_numcasos |
| 36 | WHERE |
avm99963 | 4b07f16 | 2020-06-04 13:35:57 +0200 | [diff] [blame] | 37 | resultatcoviddescripcio = 'Positiu PCR' AND |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 38 | regiosanitariadescripcio <> 'No classificat' |
| 39 | GROUP BY regiosanitariadescripcio, data |
avm99963 | 7e562d4 | 2020-07-15 23:27:38 +0200 | [diff] [blame] | 40 | ORDER BY data ASC, regiosanitariadescripcio |
| 41 | LIMIT 50000"); |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 42 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 43 | // Fem un array que tindrà com a elements un array per cada regió amb el |
| 44 | // contingut de totes les files d'aquella regió |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 45 | $dataPerRegio = []; |
| 46 | foreach ($data as $row) { |
| 47 | if (!isset($dataPerRegio[$row["regio"]])) $dataPerRegio[$row["regio"]] = []; |
| 48 | $dataPerRegio[$row["regio"]][] = $row; |
| 49 | } |
| 50 | |
| 51 | $summary = []; |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 52 | foreach ($dataPerRegio as $regio => $dataRegio) { // Per a cada regió |
| 53 | if (!in_array($regio, array_keys($CODENAME))) |
| 54 | die("[fatal error] No tenim contemplada la regió '".$regio."'.\n"); |
| 55 | |
avm99963 | c3b457a | 2020-07-21 14:23:15 +0200 | [diff] [blame^] | 56 | // Generem les dades |
| 57 | $summary[$regio] = generateSummary($dataRegio, $HABITANTS[$regio]); |
avm99963 | 00a4003 | 2020-05-07 21:02:32 +0200 | [diff] [blame] | 58 | } |
| 59 | |
avm99963 | 227cbb0 | 2020-06-09 13:51:25 +0200 | [diff] [blame] | 60 | // 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] | 61 | foreach ($summary as $regio => $summaryRegio) { |
| 62 | $file = fopen("/tmp/covid19graphgenerator-".$CODENAME[$regio].".dat", "w"); |
| 63 | |
| 64 | foreach ($summaryRegio as $row) |
| 65 | fwrite($file, $row["data"]." ".$row["ia14"]." ".$row["rho7"]."\n"); |
| 66 | |
| 67 | fclose($file); |
| 68 | } |