blob: 363f3460499dac7e93234514e60bfd50b5092e48 [file] [log] [blame]
avm9996300a40032020-05-07 21:02:32 +02001<?php
2if (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,
avm999630b3b4072020-05-17 02:39:07 +020013 "Barcelona" => 5050190,
14 "Barcelona Ciutat" => 1693449,
15 "Metropolità Sud" => 1370709,
16 "Metropolità Nord" => 1986032,
avm9996300a40032020-05-07 21:02:32 +020017];
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",
avm999630b3b4072020-05-17 02:39:07 +020026 "Barcelona" => "Barcelona",
27 "Barcelona Ciutat" => "BarcelonaCiutat",
28 "Metropolità Sud" => "MetropolitaSud",
29 "Metropolità Nord" => "MetropolitaNord",
avm9996300a40032020-05-07 21:02:32 +020030];
31
avm99963c3b457a2020-07-21 14:23:15 +020032require_once(__DIR__."/includes/generation.php");
avm9996300a40032020-05-07 21:02:32 +020033
avm99963227cbb02020-06-09 13:51:25 +020034// Demanem una llista del nombre de casos cada dia a cada regió sanitària
avm9996300a40032020-05-07 21:02:32 +020035$data = query("SELECT data, regiosanitariadescripcio AS regio, sum(numcasos) AS sum_numcasos
36WHERE
avm999634b07f162020-06-04 13:35:57 +020037 resultatcoviddescripcio = 'Positiu PCR' AND
avm9996300a40032020-05-07 21:02:32 +020038 regiosanitariadescripcio <> 'No classificat'
39GROUP BY regiosanitariadescripcio, data
avm999637e562d42020-07-15 23:27:38 +020040ORDER BY data ASC, regiosanitariadescripcio
41LIMIT 50000");
avm9996300a40032020-05-07 21:02:32 +020042
avm99963227cbb02020-06-09 13:51:25 +020043// Fem un array que tindrà com a elements un array per cada regió amb el
44// contingut de totes les files d'aquella regió
avm9996300a40032020-05-07 21:02:32 +020045$dataPerRegio = [];
46foreach ($data as $row) {
47 if (!isset($dataPerRegio[$row["regio"]])) $dataPerRegio[$row["regio"]] = [];
48 $dataPerRegio[$row["regio"]][] = $row;
49}
50
51$summary = [];
avm99963227cbb02020-06-09 13:51:25 +020052foreach ($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
avm99963c3b457a2020-07-21 14:23:15 +020056 // Generem les dades
57 $summary[$regio] = generateSummary($dataRegio, $HABITANTS[$regio]);
avm9996300a40032020-05-07 21:02:32 +020058}
59
avm99963227cbb02020-06-09 13:51:25 +020060// Posem les dades a diversos fitxers per tal que les pugui llegir el gnuplot
avm9996300a40032020-05-07 21:02:32 +020061foreach ($summary as $regio => $summaryRegio) {
62 $file = fopen("/tmp/covid19graphgenerator-".$CODENAME[$regio].".dat", "w");
63
avm9996373e13142020-08-31 01:59:30 +020064 $i = 0;
65 foreach ($summaryRegio as $row) {
66 fwrite($file, $row["data"]." ".$row["ia14"]." ".$row["rho7"]." ".$i."\n");
67 ++$i;
68 }
avm9996300a40032020-05-07 21:02:32 +020069
70 fclose($file);
71}