Compare commits

...

2 Commits

Author SHA1 Message Date
loviuz cfc2fdc441 Aggiunta info grafiche sui marcatori 2022-12-11 16:17:36 +01:00
loviuz 71ae3cb217 Aggiunto indicatore per anzianità ultimo aggiornamento 2022-12-11 13:12:19 +01:00
4 changed files with 34 additions and 13 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ composer.phar
composer.lock
*.csv
vendor
data.umap
data.umap
.vscode

View File

@ -1,5 +1,6 @@
{
"require": {
"guzzlehttp/guzzle": "^7.4"
"guzzlehttp/guzzle": "^7.4",
"nesbot/carbon": "^2.64"
}
}

View File

@ -5,13 +5,13 @@ include 'vendor/autoload.php';
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'http://www.mise.gov.it/images/exportCSV/anagrafica_impianti_attivi.csv');
file_put_contents('anagrafica_impianti_attivi.csv', $response->getBody() );
file_put_contents('anagrafica_impianti_attivi.csv', $response->getBody());
$response = $client->request('GET', 'http://www.mise.gov.it/images/exportCSV/prezzo_alle_8.csv');
file_put_contents('prezzo_alle_8.csv', $response->getBody());
// Lettura template file umap
$umap = json_decode( file_get_contents('template.umap'), 1 );
$umap = json_decode(file_get_contents('template.umap'), 1);
// Lettura 2 CSV
$csvDistributori = fopen('anagrafica_impianti_attivi.csv', 'r');
@ -65,7 +65,8 @@ $raggruppamenti_iniziali = [
'GASOLIO ENERGY D' => 'GASOLIO',
'BENZINA ENERGY 98 OTTANI' => 'BENZINA',
'BENZINA SHELL V POWER' => 'BENZINA',
'SSP98' => 'BENZINA'
'SSP98' => 'BENZINA',
'GASOLIO PLUS' => 'GASOLIO'
];
$raggruppamenti = [];
@ -96,7 +97,7 @@ while (($line = fgetcsv($csvPrezzi, 0, ';')) !== false) {
$prezzo = (float)$line[2];
$isSelf = (int)$line[3];
$ultimo_aggiornamento = $line[4];
$prezzi[ $idimpianto ][] = [
'tipo' => strtoupper($tipo),
'prezzo' => $prezzo,
@ -113,7 +114,7 @@ fgetcsv($csvDistributori);
fgetcsv($csvDistributori);
// Costruzione dati umap
while(($line = fgetcsv($csvDistributori, 0, ';')) !== FALSE){
while (($line = fgetcsv($csvDistributori, 0, ';')) !== false) {
$idimpianto = $line[0];
$name = $line[2];
$lat = $line[8] !== 'NULL' ? $line[8] : null;
@ -129,11 +130,22 @@ while(($line = fgetcsv($csvDistributori, 0, ';')) !== FALSE){
foreach ($prezzi[$idimpianto] as $idx => $prezzo) {
$tipo = $prezzo['tipo'].($prezzo['isSelf'] ? ' (self)' : ' (servito)');
$tipo_raggruppato = $raggruppamenti[ $tipo ];
$giorni_ritardo_aggiornamento = (Carbon\Carbon::rawCreateFromFormat('d/m/Y H:i:s', $prezzo['ultimo_aggiornamento']))->diffInDays(new Carbon\Carbon(), false);
// Emoji per indicare la data di ultimo aggiornamento
$icon = '🔴';
if ($giorni_ritardo_aggiornamento <= 3) {
$icon = '🟢';
} elseif ($giorni_ritardo_aggiornamento > 3 && $giorni_ritardo_aggiornamento <= 7) {
$icon = '🟠';
}
$prezzi_per_tipo[$tipo_raggruppato][$idimpianto][$tipo] = [
'idimpianto' => $idimpianto,
'ultimo_aggiornamento' => $prezzo['ultimo_aggiornamento'],
'nome' => $name,
'button' => '[[geo:'.$lat.','.$lon.'|🏁 Guidami qui »]]',
'icon' => $icon,
'prezzo' => (float)$prezzo['prezzo'],
'lat' => $lat,
'lon' => $lon
@ -158,15 +170,15 @@ foreach ($prezzi_per_tipo as $tipo_raggruppato => $idimpianti) {
foreach ($tipi as $tipo => $impianto) {
$prezzi[] = $impianto['prezzo'];
$descriptions[] = $tipo.': '.$impianto['prezzo']."\n";
$descriptions[] = '**'.$tipo.':** '.$impianto['prezzo'].' €';
}
$markers[] = [
"type" => "Feature",
"properties" => [
"idImpianto" => $idimpianto,
'description' => "**".$impianto['nome']."**\n".implode("\n", $descriptions)."\n*Ultimo agg.: ".$impianto['ultimo_aggiornamento'].'*',
'name' => min($prezzi).' - '.max($prezzi).' €'
'description' => "# ".$impianto['nome']."\n*🗓️ ".$impianto['ultimo_aggiornamento']."*\n".implode("\n", $descriptions)."\n\n".$impianto['button'],
'name' => $impianto['icon'].' '.min($prezzi).' - '.max($prezzi).' €'
],
"geometry" => [
"type" => "Point",
@ -203,7 +215,7 @@ $json_response = json_encode($umap, JSON_PRETTY_PRINT);
// Salvataggio file umap
if (isset($_GET['response'])) {
echo $json_response;
echo $json_response;
} else {
file_put_contents( 'data.umap', $json_response );
file_put_contents('data.umap', $json_response);
}

View File

@ -23,7 +23,14 @@
"iconClass": "Drop",
"color": "Blue",
"limitBounds": [],
"tilelayer": [],
"tilelayer": {
"minZoom": 0,
"maxZoom": 18,
"attribution": "Tiles courtesy of [[https://www.jawg.io/|jawgmaps]] - Map data [[http://osm.org/copyright/|&copy; OpenStreetMap contributors]], under ODbL.",
"url_template": "https://tile.jawg.io/dark/{z}/{x}/{y}.png?api-key=community",
"name": "OSM Dark (jawgmaps)",
"tms": false
},
"licence": "",
"description": "# ISTRUZIONI\n1. Diminuisci l'area di visualizzazione centrando la mappa nella tua posizione\n2. Clicca sull'icona simile a dei dischi sovrapposti per scegliere il tipo di carburante\n3. Trova il distributore più vantaggioso 😉\nATTENZIONE: la mappa contiene tutti i distributori d'Italia per cui alla selezione del tipo di carburante potrebbe essere un po' lento a caricare i dati.\n",
"name": "Distributori prezzi Italia",