diff --git a/api/bounds.php b/api/bounds.php index 5253abc..d038953 100755 --- a/api/bounds.php +++ b/api/bounds.php @@ -1,76 +1,76 @@ . */ require '../load.php'; $results = []; if( isset( $_GET['lat_n'], $_GET['lat_s'], $_GET['lng_e'], $_GET['lng_w'] ) ) { $lat_n = & $_GET['lat_n']; $lat_s = & $_GET['lat_s']; $lng_e = & $_GET['lng_e']; $lng_w = & $_GET['lng_w']; $results = query_results( sprintf( "SELECT station.station_ID, station.station_lat, station.station_lon, " . "stationowner.stationowner_uid, stationowner.stationowner_name " . - "FROM {$GLOBALS[JOIN]('station', 'stationowner')} " . + "FROM {$JOIN('station', 'stationowner')} " . "WHERE station.station_lat BETWEEN %f AND %f " . "AND station.station_lon BETWEEN %f AND %f " . "AND station.stationowner_ID = stationowner.stationowner_ID", $lat_s, $lat_n, $lng_w, $lng_e ), 'Station' ); $n_results = count( $results ); $results->error = $n_results > 90; if(! $results->error) { // Get prices for($i=0; $i<$n_results; $i++) { $results[$i]->prices = query_results( sprintf( "SELECT DISTINCT price.price_value, price.price_self, " . "fuel.fuel_uid, fuel.fuel_name " . - "FROM {$GLOBALS[JOIN]('price', 'fuel')} " . + "FROM {$JOIN('price', 'fuel')} " . "WHERE price.station_ID = %d " . "AND price.fuel_ID = fuel.fuel_ID " . "ORDER BY price.price_value", $results[$i]->station_ID ), 'Price' ); } } } http_json_header(); echo json_encode( $results, isset( $_GET['pretty'] ) ? JSON_PRETTY_PRINT : 0 ); diff --git a/cli/import-mise.php b/cli/import-mise.php index 5632b61..f458f1b 100755 --- a/cli/import-mise.php +++ b/cli/import-mise.php @@ -1,146 +1,146 @@ . */ /* * Manually download data from Ministero dello Sviluppo Economico * http://www.sviluppoeconomico.gov.it/index.php/it/open-data/elenco-dataset/2032336-carburanti-prezzi-praticati-e-anagrafica-degli-impianti * * Files: * http://www.sviluppoeconomico.gov.it/images/exportCSV/prezzo_alle_8.csv * http://www.sviluppoeconomico.gov.it/images/exportCSV/anagrafica_impianti_attivi.csv * * The files are licensed under the terms of the Italian Open Data License v2.0 * http://www.dati.gov.it/iodl/2.0/ */ require __DIR__ . '/../load.php'; require __DIR__ . '/import-mise-functions.php'; -//query("TRUNCATE {$GLOBALS[T]('rel_provincia_comune')}"); -//query("TRUNCATE {$GLOBALS[T]('provincia')}"); -//query("TRUNCATE {$GLOBALS[T]('comune')}"); -//query("TRUNCATE {$GLOBALS[T]('station')}"); -//query("TRUNCATE {$GLOBALS[T]('stationowner')}"); -//query("TRUNCATE {$GLOBALS[T]('fuelprovider')}"); -//query("TRUNCATE {$GLOBALS[T]('fuel')}"); -query("TRUNCATE {$GLOBALS[T]('price')}"); +//query("TRUNCATE {$T('rel_provincia_comune')}"); +//query("TRUNCATE {$T('provincia')}"); +//query("TRUNCATE {$T('comune')}"); +//query("TRUNCATE {$T('station')}"); +//query("TRUNCATE {$T('stationowner')}"); +//query("TRUNCATE {$T('fuelprovider')}"); +//query("TRUNCATE {$T('fuel')}"); +query("TRUNCATE {$T('price')}"); -$comuni = query_results("SELECT comune_ID, comune_uid FROM {$GLOBALS[T]('comune')}", 'Comune'); +$comuni = query_results("SELECT comune_ID, comune_uid FROM {$T('comune')}", 'Comune'); $comuni = indexed_array($comuni, 'comune_uid', 'comune_ID'); -$provincie = query_results("SELECT provincia_ID, provincia_uid FROM {$GLOBALS[T]('provincia')}", 'Provincia'); +$provincie = query_results("SELECT provincia_ID, provincia_uid FROM {$T('provincia')}", 'Provincia'); $provincie = indexed_array($provincie, 'provincia_uid', 'provincia_ID'); -$fuels = query_results("SELECT fuel_ID, fuel_uid FROM {$GLOBALS[T]('fuel')}", 'Fuel'); +$fuels = query_results("SELECT fuel_ID, fuel_uid FROM {$T('fuel')}", 'Fuel'); $fuels = indexed_array($fuels, 'fuel_uid', 'fuel_ID'); -$stations = query_results("SELECT station_ID, station_miseID FROM {$GLOBALS[T]('station')}", 'Station'); +$stations = query_results("SELECT station_ID, station_miseID FROM {$T('station')}", 'Station'); $stations = indexed_array($stations, 'station_miseID', 'station_ID'); -$stationowners = query_results("SELECT stationowner_ID, stationowner_uid FROM {$GLOBALS[T]('stationowner')}", 'Stationowner'); +$stationowners = query_results("SELECT stationowner_ID, stationowner_uid FROM {$T('stationowner')}", 'Stationowner'); $stationowners = indexed_array($stationowners, 'stationowner_uid', 'stationowner_ID'); -$fuelproviders = query_results("SELECT fuelprovider_ID, fuelprovider_uid FROM {$GLOBALS[T]('fuelprovider')}", 'Fuelprovider'); +$fuelproviders = query_results("SELECT fuelprovider_ID, fuelprovider_uid FROM {$T('fuelprovider')}", 'Fuelprovider'); $fuelproviders = indexed_array($fuelproviders, 'fuelprovider_uid', 'fuelprovider_ID'); try { if( ! isset( $argv[1], $argv[2] ) ) { throw new Exception( sprintf( _("Utilizzo: %s FILE_STAZIONI.csv PREZZI_ALLE_8.csv"), esc_html( $argv[0] ) ), 1 ); } define('FILENAME_STATIONS', $argv[1]); define('FILENAME_PRICES', $argv[2]); if( ! file_exists(FILENAME_STATIONS) ) { throw new Exception( _("File delle stazioni non trovato"), 2 ); } if( ! $handle = fopen(FILENAME_STATIONS, 'r') ) { throw new Exception( _("Impossibile aprire il file delle stazioni"), 3 ); } // Waste first 2 lines fgetcsv($handle); fgetcsv($handle); while( $data = fgetcsv($handle, 512, ';') ) { get_station_ID( (int) $data[0] /*$station_miseID*/, $data[4] /*$station_name*/, $data[3] /*$station_type*/, $data[5] /*$station_address*/, (float) $data[8] /*$station_lat*/, (float) $data[9] /*$station_lon*/, get_comune_ID( generate_slug( $data[6] ) /*$comune_uid*/, $data[6] /*$comune_name*/, $data[7] /*$provincia_name*/ ), get_stationowner_ID( generate_slug( $data[1] ) /*$stationowner_uid*/, $data[1] /*$stationowner_name*/ ), get_fuelprovider_ID( generate_slug( $data[2] ) /*$fuelprovider_uid*/, $data[2] /*$fuelprovider_name*/ ) ); } fclose($handle); // Prices if( ! file_exists(FILENAME_PRICES) ) { throw new Exception( _("File dei prezzi non trovato"), 4 ); } if( ! $handle = fopen(FILENAME_PRICES, 'r') ) { throw new Exception( _("Impossibile aprire il file dei prezzi"), 5 ); } // Waste first 2 lines fgetcsv($handle); fgetcsv($handle); while( $data = fgetcsv($handle, 255, ';') ) { insert_row('price', [ new DBCol('price_value', (float) $data[2], 'f'), new DBCol('price_self', (int) $data[3], 'd'), new DBCol('price_date', itdate2datetime($data[4]), 's'), new DBCol( 'fuel_ID', get_fuel_ID( generate_slug($data[1]) /*$fuel_uid*/, $data[1] /*$fuel_name*/ ), 'd' ), new DBCol('station_ID', get_station_ID( (int) $data[0] ), 'd') ] ); } fclose($handle); } catch(Exception $e) { printf( _("Errore: %s."), $e->getMessage() ); echo "\n"; exit( $e->getCode() ); } diff --git a/index.php b/index.php index ccf6b61..5e17d21 100755 --- a/index.php +++ b/index.php @@ -1,98 +1,98 @@ . */ /* * The map */ require 'load.php'; enqueue_css('leaflet'); enqueue_css('my-fuel-map'); enqueue_js('jquery.ui'); enqueue_js('leaflet'); enqueue_js('leaflet.bouncemarker'); enqueue_js('my-fuel-map'); get_header('map'); $last_price_rfc3339 = last_price_date(DateTime::RFC3339); $last_price_text = last_price_date(); ?>
$last_price_text" ) ?>