querySingle("SELECT last FROM last_check"); if ($last_check ===null || date_add(new DateTime($last_check), DateInterval::createFromDateString('1 hour')) < new DateTime()) { $json = file_get_contents($json_address); if ($json !== false) { $decoded = json_decode($json, true); foreach($decoded['features'] as $value) { if(in_array($value['properties']['insee'], $villes_ALM)) { $ville = $base->querySingle("SELECT * FROM Villes WHERE code_INSEE=".$value['properties']['insee'].";", true); if ($ville == array()) { $base->query("INSERT INTO Villes VALUES (".$value['properties']['insee'].", \"".$value['properties']['name']."\");"); } $base->query("INSERT INTO chiffres VALUES(\"".$decoded['date']."\", ".$value['properties']['insee'].", ".$value['properties']['contributions'].");"); } } $base->query("DELETE FROM last_check;"); $base->query("INSERT INTO last_check VALUES ('".$decoded['date']."');"); $last_check = $decoded['date']; } } // Comptage et affichage $compte = $base->querySingle("SELECT SUM(nombre) FROM chiffres WHERE date = \"".$last_check."\";"); ?>

Heure du relevé :

Total des réponses pour ALM :


query("SELECT * FROM chiffres c natural join villes v WHERE c.date = \"".$last_check."\" ORDER BY c.nombre DESC"); while( $line = $compte->fetchArray()) { echo "\n"; } ?>
{$line['nom']}{$line['nombre']}

query("SELECT * FROM chiffres c natural join villes v WHERE v.nom != 'Angers'"); $dataset = []; while($line = $data->fetchArray()) { if (!key_exists($line['code_INSEE'], $dataset)) { $dataset[$line['code_INSEE']]['type'] = 'line'; $dataset[$line['code_INSEE']]['label'] = $line['nom']; $dataset[$line['code_INSEE']]['tension'] = 0.1; } $dataset[$line['code_INSEE']]['data'][] = array('x' => date_format(date_create($line['date']), 'Y/m/d H:i'), 'y'=>$line['nombre']); } $decoded = []; foreach($dataset as $value) { $decoded[] = $value; } $json = json_encode($decoded); ?>
query("SELECT * FROM chiffres c natural join villes v WHERE v.nom == 'Angers'"); $dataset_angers = []; while($line = $data->fetchArray()) { $dataset_angers[] = array('x' => date_format(date_create($line['date']), 'Y/m/d H:i'), 'y'=>$line['nombre']); } $json_angers = json_encode($dataset_angers); $data = $base->query("SELECT date, SUM(nombre) as nombre FROM chiffres GROUP BY date"); $dataset_tout = []; while($line = $data->fetchArray()) { $dataset_tout[] = array('x' => date_format(date_create($line['date']), 'Y/m/d H:i'), 'y'=>$line['nombre']); } $json_tout = json_encode($dataset_tout); ?>
Le code correspondant au script