Remove DB field geofile
This commit is contained in:
1
files/db/update_v7_to_v8.sql
Normal file
1
files/db/update_v7_to_v8.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE projects DROP COLUMN geofile;
|
||||
@@ -5,11 +5,11 @@
|
||||
*
|
||||
* To convert a gpx file:
|
||||
* 1. Add file <file_name>.gpx to geo/ folder
|
||||
* 2. Assign file to project: UPDATE projects SET geofile = '<file_name>' WHERE id_project = <id_project>;
|
||||
* 2. Assign file to project: UPDATE projects SET codename = '<file_name>' WHERE id_project = <id_project>;
|
||||
* 3. Load any page
|
||||
*
|
||||
* To force gpx rebuild:
|
||||
* ?a=build_geojson&name=<gpx_file_name>
|
||||
* ?a=build_geojson&name=<file_name>
|
||||
*/
|
||||
class Converter extends PhpObject {
|
||||
|
||||
@@ -17,11 +17,9 @@ class Converter extends PhpObject {
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
}
|
||||
|
||||
public static function convertToGeoJson($sFileName) {
|
||||
$sFileName = basename($sFileName, Gpx::EXT);
|
||||
|
||||
$oGpx = new Gpx($sFileName);
|
||||
$oGeoJson = new GeoJson($sFileName);
|
||||
public static function convertToGeoJson($sCodeName) {
|
||||
$oGpx = new Gpx($sCodeName);
|
||||
$oGeoJson = new GeoJson($sCodeName);
|
||||
|
||||
$oGeoJson->buildTracks($oGpx->getTracks());
|
||||
if($oGeoJson->isSimplicationRequired()) $oGeoJson->buildTracks($oGpx->getTracks(), true);
|
||||
@@ -30,10 +28,10 @@ class Converter extends PhpObject {
|
||||
return $oGpx->getLog().'<br />'.$oGeoJson->getLog();
|
||||
}
|
||||
|
||||
public static function isGeoJsonValid($sFileName) {
|
||||
public static function isGeoJsonValid($sCodeName) {
|
||||
$bResult = false;
|
||||
$sGeoJsonFilePath = Geo::getFilePath($sFileName, GeoJson::EXT);
|
||||
if(file_exists($sGeoJsonFilePath) && filemtime($sGeoJsonFilePath) > filemtime(Geo::getFilePath($sFileName, Gpx::EXT))) $bResult = true;
|
||||
$sGeoJsonFilePath = Geo::getFilePath($sCodeName, GeoJson::EXT);
|
||||
if(file_exists($sGeoJsonFilePath) && filemtime($sGeoJsonFilePath) > filemtime(Geo::getFilePath($sCodeName, Gpx::EXT))) $bResult = true;
|
||||
return $bResult;
|
||||
}
|
||||
}
|
||||
@@ -46,14 +44,14 @@ class Geo extends PhpObject {
|
||||
protected $asTracks;
|
||||
protected $sFilePath;
|
||||
|
||||
public function __construct($sFileName) {
|
||||
public function __construct($sCodeName) {
|
||||
parent::__construct(get_class($this), Settings::DEBUG, PhpObject::MODE_HTML);
|
||||
$this->sFilePath = self::getFilePath($sFileName, static::EXT);
|
||||
$this->sFilePath = self::getFilePath($sCodeName, static::EXT);
|
||||
$this->asTracks = array();
|
||||
}
|
||||
|
||||
public static function getFilePath($sFileName, $sExt) {
|
||||
return self::GEO_FOLDER.$sFileName.$sExt;
|
||||
public static function getFilePath($sCodeName, $sExt) {
|
||||
return self::GEO_FOLDER.$sCodeName.$sExt;
|
||||
}
|
||||
|
||||
public function getLog() {
|
||||
@@ -65,8 +63,8 @@ class Gpx extends Geo {
|
||||
|
||||
const EXT = '.gpx';
|
||||
|
||||
public function __construct($sFileName) {
|
||||
parent::__construct($sFileName);
|
||||
public function __construct($sCodeName) {
|
||||
parent::__construct($sCodeName);
|
||||
$this->parseFile();
|
||||
}
|
||||
|
||||
@@ -113,8 +111,8 @@ class GeoJson extends Geo {
|
||||
const MAX_DEVIATION_FLAT = 0.1; //10%
|
||||
const MAX_DEVIATION_ELEV = 0.1; //20%
|
||||
|
||||
public function __construct($sFileName) {
|
||||
parent::__construct($sFileName);
|
||||
public function __construct($sCodeName) {
|
||||
parent::__construct($sCodeName);
|
||||
}
|
||||
|
||||
public function saveFile() {
|
||||
@@ -217,7 +215,7 @@ class GeoJson extends Geo {
|
||||
|
||||
private function isPointValid($asPointA, $asPointO, $asPointB) {
|
||||
/* A----O Calculate angle AO^OB
|
||||
* \ If angle is within [Pi - 10%; Pi + 10%], O can be discarded
|
||||
* \ If angle is within [90% Pi ; 110% Pi], O can be discarded
|
||||
* \ O is valid otherwise
|
||||
* B
|
||||
*/
|
||||
|
||||
@@ -116,7 +116,6 @@ class Project extends PhpObject {
|
||||
'active_from',
|
||||
'active_to',
|
||||
"IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode",
|
||||
'geofile',
|
||||
'timezone'
|
||||
),
|
||||
'from' => self::PROJ_TABLE
|
||||
@@ -131,11 +130,10 @@ class Project extends PhpObject {
|
||||
case 2: $asProject['mode'] = self::MODE_HISTO; break;
|
||||
}
|
||||
|
||||
if(!Converter::isGeoJsonValid($asProject['geofile'])) Converter::convertToGeoJson($asProject['geofile']);
|
||||
if(!Converter::isGeoJsonValid($sCodeName)) Converter::convertToGeoJson($sCodeName);
|
||||
|
||||
$asProject['geofilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($asProject['geofile'], GeoJson::EXT));
|
||||
$asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($asProject['geofile'], Gpx::EXT));
|
||||
unset($asProject['geofile']);
|
||||
$asProject['geofilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($sCodeName, GeoJson::EXT));
|
||||
$asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($sCodeName, Gpx::EXT));
|
||||
$asProject['codename'] = $sCodeName;
|
||||
}
|
||||
return $bSpecificProj?$asProject:$asProjects;
|
||||
|
||||
@@ -65,7 +65,7 @@ class Spot extends Main
|
||||
Feed::MSG_TABLE => array('ref_msg_id', Db::getId(Feed::FEED_TABLE), 'type', 'latitude', 'longitude', 'iso_time', 'site_time', 'unix_time', 'content', 'battery_state'),
|
||||
Feed::FEED_TABLE => array('ref_feed_id', Db::getId(Feed::SPOT_TABLE), Db::getId(Project::PROJ_TABLE), 'name', 'description', 'status', 'last_update'),
|
||||
Feed::SPOT_TABLE => array('ref_spot_id', 'name', 'model'),
|
||||
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to', 'geofile', 'timezone'),
|
||||
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to', 'timezone'),
|
||||
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), 'name', 'content', 'site_time'),
|
||||
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'rotate', 'comment')
|
||||
),
|
||||
@@ -89,7 +89,6 @@ class Spot extends Main
|
||||
'status' => "VARCHAR(10)",
|
||||
'active_from' => "TIMESTAMP DEFAULT 0",
|
||||
'active_to' => "TIMESTAMP DEFAULT 0",
|
||||
'geofile' => "VARCHAR(50)",
|
||||
'timezone' => "VARCHAR(100)",
|
||||
'last_update' => "TIMESTAMP DEFAULT 0",
|
||||
'filename' => "VARCHAR(100) NOT NULL",
|
||||
|
||||
Reference in New Issue
Block a user