Compare commits
2 Commits
196052b7e2
...
cfc2fdc441
Author | SHA1 | Date |
---|---|---|
|
cfc2fdc441 | |
|
71ae3cb217 |
|
@ -2,4 +2,5 @@ composer.phar
|
||||||
composer.lock
|
composer.lock
|
||||||
*.csv
|
*.csv
|
||||||
vendor
|
vendor
|
||||||
data.umap
|
data.umap
|
||||||
|
.vscode
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^7.4"
|
"guzzlehttp/guzzle": "^7.4",
|
||||||
|
"nesbot/carbon": "^2.64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
generate.php
32
generate.php
|
@ -5,13 +5,13 @@ include 'vendor/autoload.php';
|
||||||
$client = new \GuzzleHttp\Client();
|
$client = new \GuzzleHttp\Client();
|
||||||
|
|
||||||
$response = $client->request('GET', 'http://www.mise.gov.it/images/exportCSV/anagrafica_impianti_attivi.csv');
|
$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');
|
$response = $client->request('GET', 'http://www.mise.gov.it/images/exportCSV/prezzo_alle_8.csv');
|
||||||
file_put_contents('prezzo_alle_8.csv', $response->getBody());
|
file_put_contents('prezzo_alle_8.csv', $response->getBody());
|
||||||
|
|
||||||
// Lettura template file umap
|
// 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
|
// Lettura 2 CSV
|
||||||
$csvDistributori = fopen('anagrafica_impianti_attivi.csv', 'r');
|
$csvDistributori = fopen('anagrafica_impianti_attivi.csv', 'r');
|
||||||
|
@ -65,7 +65,8 @@ $raggruppamenti_iniziali = [
|
||||||
'GASOLIO ENERGY D' => 'GASOLIO',
|
'GASOLIO ENERGY D' => 'GASOLIO',
|
||||||
'BENZINA ENERGY 98 OTTANI' => 'BENZINA',
|
'BENZINA ENERGY 98 OTTANI' => 'BENZINA',
|
||||||
'BENZINA SHELL V POWER' => 'BENZINA',
|
'BENZINA SHELL V POWER' => 'BENZINA',
|
||||||
'SSP98' => 'BENZINA'
|
'SSP98' => 'BENZINA',
|
||||||
|
'GASOLIO PLUS' => 'GASOLIO'
|
||||||
];
|
];
|
||||||
|
|
||||||
$raggruppamenti = [];
|
$raggruppamenti = [];
|
||||||
|
@ -96,7 +97,7 @@ while (($line = fgetcsv($csvPrezzi, 0, ';')) !== false) {
|
||||||
$prezzo = (float)$line[2];
|
$prezzo = (float)$line[2];
|
||||||
$isSelf = (int)$line[3];
|
$isSelf = (int)$line[3];
|
||||||
$ultimo_aggiornamento = $line[4];
|
$ultimo_aggiornamento = $line[4];
|
||||||
|
|
||||||
$prezzi[ $idimpianto ][] = [
|
$prezzi[ $idimpianto ][] = [
|
||||||
'tipo' => strtoupper($tipo),
|
'tipo' => strtoupper($tipo),
|
||||||
'prezzo' => $prezzo,
|
'prezzo' => $prezzo,
|
||||||
|
@ -113,7 +114,7 @@ fgetcsv($csvDistributori);
|
||||||
fgetcsv($csvDistributori);
|
fgetcsv($csvDistributori);
|
||||||
|
|
||||||
// Costruzione dati umap
|
// Costruzione dati umap
|
||||||
while(($line = fgetcsv($csvDistributori, 0, ';')) !== FALSE){
|
while (($line = fgetcsv($csvDistributori, 0, ';')) !== false) {
|
||||||
$idimpianto = $line[0];
|
$idimpianto = $line[0];
|
||||||
$name = $line[2];
|
$name = $line[2];
|
||||||
$lat = $line[8] !== 'NULL' ? $line[8] : null;
|
$lat = $line[8] !== 'NULL' ? $line[8] : null;
|
||||||
|
@ -129,11 +130,22 @@ while(($line = fgetcsv($csvDistributori, 0, ';')) !== FALSE){
|
||||||
foreach ($prezzi[$idimpianto] as $idx => $prezzo) {
|
foreach ($prezzi[$idimpianto] as $idx => $prezzo) {
|
||||||
$tipo = $prezzo['tipo'].($prezzo['isSelf'] ? ' (self)' : ' (servito)');
|
$tipo = $prezzo['tipo'].($prezzo['isSelf'] ? ' (self)' : ' (servito)');
|
||||||
$tipo_raggruppato = $raggruppamenti[ $tipo ];
|
$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] = [
|
$prezzi_per_tipo[$tipo_raggruppato][$idimpianto][$tipo] = [
|
||||||
'idimpianto' => $idimpianto,
|
'idimpianto' => $idimpianto,
|
||||||
'ultimo_aggiornamento' => $prezzo['ultimo_aggiornamento'],
|
'ultimo_aggiornamento' => $prezzo['ultimo_aggiornamento'],
|
||||||
'nome' => $name,
|
'nome' => $name,
|
||||||
|
'button' => '[[geo:'.$lat.','.$lon.'|🏁 Guidami qui »]]',
|
||||||
|
'icon' => $icon,
|
||||||
'prezzo' => (float)$prezzo['prezzo'],
|
'prezzo' => (float)$prezzo['prezzo'],
|
||||||
'lat' => $lat,
|
'lat' => $lat,
|
||||||
'lon' => $lon
|
'lon' => $lon
|
||||||
|
@ -158,15 +170,15 @@ foreach ($prezzi_per_tipo as $tipo_raggruppato => $idimpianti) {
|
||||||
|
|
||||||
foreach ($tipi as $tipo => $impianto) {
|
foreach ($tipi as $tipo => $impianto) {
|
||||||
$prezzi[] = $impianto['prezzo'];
|
$prezzi[] = $impianto['prezzo'];
|
||||||
$descriptions[] = $tipo.': '.$impianto['prezzo']."\n";
|
$descriptions[] = '**'.$tipo.':** '.$impianto['prezzo'].' €';
|
||||||
}
|
}
|
||||||
|
|
||||||
$markers[] = [
|
$markers[] = [
|
||||||
"type" => "Feature",
|
"type" => "Feature",
|
||||||
"properties" => [
|
"properties" => [
|
||||||
"idImpianto" => $idimpianto,
|
"idImpianto" => $idimpianto,
|
||||||
'description' => "**".$impianto['nome']."**\n".implode("\n", $descriptions)."\n*Ultimo agg.: ".$impianto['ultimo_aggiornamento'].'*',
|
'description' => "# ".$impianto['nome']."\n*🗓️ ".$impianto['ultimo_aggiornamento']."*\n".implode("\n", $descriptions)."\n\n".$impianto['button'],
|
||||||
'name' => min($prezzi).' - '.max($prezzi).' €'
|
'name' => $impianto['icon'].' '.min($prezzi).' - '.max($prezzi).' €'
|
||||||
],
|
],
|
||||||
"geometry" => [
|
"geometry" => [
|
||||||
"type" => "Point",
|
"type" => "Point",
|
||||||
|
@ -203,7 +215,7 @@ $json_response = json_encode($umap, JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
// Salvataggio file umap
|
// Salvataggio file umap
|
||||||
if (isset($_GET['response'])) {
|
if (isset($_GET['response'])) {
|
||||||
echo $json_response;
|
echo $json_response;
|
||||||
} else {
|
} else {
|
||||||
file_put_contents( 'data.umap', $json_response );
|
file_put_contents('data.umap', $json_response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,14 @@
|
||||||
"iconClass": "Drop",
|
"iconClass": "Drop",
|
||||||
"color": "Blue",
|
"color": "Blue",
|
||||||
"limitBounds": [],
|
"limitBounds": [],
|
||||||
"tilelayer": [],
|
"tilelayer": {
|
||||||
|
"minZoom": 0,
|
||||||
|
"maxZoom": 18,
|
||||||
|
"attribution": "Tiles courtesy of [[https://www.jawg.io/|jawgmaps]] - Map data [[http://osm.org/copyright/|© 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": "",
|
"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",
|
"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",
|
"name": "Distributori prezzi Italia",
|
||||||
|
|
Loading…
Reference in New Issue