104 lines
3.8 KiB
PHP
104 lines
3.8 KiB
PHP
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Suivi du baromètre</title>
|
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<?php
|
|
|
|
$villes_ALM = array(49007, 49015, 49020, 49028, 49035, 49048, 49055, 4129, 49130, 49135, 49307, 49200, 49214, 49223, 49241, 49246, 49377, 49267, 49271, 49294, 49298, 49306, 49278, 49326, 49329, 49338, 49339, 49353, 49434);
|
|
$json_address = "https://www.barometre-velo.fr/stats/progress.geojson";
|
|
|
|
$base = new SQlite3('barometre.sqlite');
|
|
|
|
// Mise à jour des données
|
|
$last_check = $base->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."\";");
|
|
?>
|
|
<p>Heure du relevé : <b><?=date_format(date_create($last_check),"d/m/Y H:i:s")?></b></p>
|
|
<p>Total des réponses pour ALM : <b><?=$compte?></b></p>
|
|
<hr/>
|
|
<table>
|
|
<?php
|
|
$compte = $base->query("SELECT * FROM chiffres c natural join villes v WHERE c.date = \"".$last_check."\" ORDER BY c.nombre DESC");
|
|
while( $line = $compte->fetchArray()) {
|
|
echo "<tr><td>{$line['nom']}</td><td>{$line['nombre']}</td></tr>\n";
|
|
}
|
|
?></table>
|
|
<hr/>
|
|
<div style="width: 75%; margin:0 auto;"><canvas id="graphe"></canvas></div>
|
|
<?php
|
|
$data = $base->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);
|
|
?>
|
|
<script type="text/javascript">
|
|
const data = <?=$json?>;
|
|
(async function() {
|
|
const myChart = new Chart(document.getElementById('graphe'), {
|
|
type: 'line',
|
|
data: {
|
|
datasets : data
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
<hr/>
|
|
<div style="width: 75%; margin:0 auto;"><canvas id="graphe_angers"></canvas></div>
|
|
<?php
|
|
$data = $base->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);
|
|
?>
|
|
<script type="text/javascript">
|
|
const data_angers = <?=$json_angers?>;
|
|
(async function() {
|
|
const myChart = new Chart(document.getElementById('graphe_angers'), { type:'line', data: {datasets: [{
|
|
type: 'line',
|
|
label:"Angers",
|
|
data: data_angers,
|
|
tension: 0.1
|
|
}]}});
|
|
})();
|
|
</script>
|
|
<hr/>
|
|
<div style="position: fixed; bottom:0; width:100%;">
|
|
<a href="https://git.fedaya.net/Fedaya/progression_barometre">Le code correspondant au script</a>
|
|
</div>
|
|
</body>
|
|
</html>
|