Remove DB field geofile

This commit is contained in:
2020-02-05 21:04:08 +01:00
parent 76ee2f9ada
commit 68bdbb4014
4 changed files with 22 additions and 26 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE projects DROP COLUMN geofile;

View File

@@ -5,11 +5,11 @@
* *
* To convert a gpx file: * To convert a gpx file:
* 1. Add file <file_name>.gpx to geo/ folder * 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 * 3. Load any page
* *
* To force gpx rebuild: * To force gpx rebuild:
* ?a=build_geojson&name=<gpx_file_name> * ?a=build_geojson&name=<file_name>
*/ */
class Converter extends PhpObject { class Converter extends PhpObject {
@@ -17,11 +17,9 @@ class Converter extends PhpObject {
parent::__construct(__CLASS__, Settings::DEBUG); parent::__construct(__CLASS__, Settings::DEBUG);
} }
public static function convertToGeoJson($sFileName) { public static function convertToGeoJson($sCodeName) {
$sFileName = basename($sFileName, Gpx::EXT); $oGpx = new Gpx($sCodeName);
$oGeoJson = new GeoJson($sCodeName);
$oGpx = new Gpx($sFileName);
$oGeoJson = new GeoJson($sFileName);
$oGeoJson->buildTracks($oGpx->getTracks()); $oGeoJson->buildTracks($oGpx->getTracks());
if($oGeoJson->isSimplicationRequired()) $oGeoJson->buildTracks($oGpx->getTracks(), true); if($oGeoJson->isSimplicationRequired()) $oGeoJson->buildTracks($oGpx->getTracks(), true);
@@ -30,10 +28,10 @@ class Converter extends PhpObject {
return $oGpx->getLog().'<br />'.$oGeoJson->getLog(); return $oGpx->getLog().'<br />'.$oGeoJson->getLog();
} }
public static function isGeoJsonValid($sFileName) { public static function isGeoJsonValid($sCodeName) {
$bResult = false; $bResult = false;
$sGeoJsonFilePath = Geo::getFilePath($sFileName, GeoJson::EXT); $sGeoJsonFilePath = Geo::getFilePath($sCodeName, GeoJson::EXT);
if(file_exists($sGeoJsonFilePath) && filemtime($sGeoJsonFilePath) > filemtime(Geo::getFilePath($sFileName, Gpx::EXT))) $bResult = true; if(file_exists($sGeoJsonFilePath) && filemtime($sGeoJsonFilePath) > filemtime(Geo::getFilePath($sCodeName, Gpx::EXT))) $bResult = true;
return $bResult; return $bResult;
} }
} }
@@ -46,14 +44,14 @@ class Geo extends PhpObject {
protected $asTracks; protected $asTracks;
protected $sFilePath; protected $sFilePath;
public function __construct($sFileName) { public function __construct($sCodeName) {
parent::__construct(get_class($this), Settings::DEBUG, PhpObject::MODE_HTML); 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(); $this->asTracks = array();
} }
public static function getFilePath($sFileName, $sExt) { public static function getFilePath($sCodeName, $sExt) {
return self::GEO_FOLDER.$sFileName.$sExt; return self::GEO_FOLDER.$sCodeName.$sExt;
} }
public function getLog() { public function getLog() {
@@ -65,8 +63,8 @@ class Gpx extends Geo {
const EXT = '.gpx'; const EXT = '.gpx';
public function __construct($sFileName) { public function __construct($sCodeName) {
parent::__construct($sFileName); parent::__construct($sCodeName);
$this->parseFile(); $this->parseFile();
} }
@@ -113,8 +111,8 @@ class GeoJson extends Geo {
const MAX_DEVIATION_FLAT = 0.1; //10% const MAX_DEVIATION_FLAT = 0.1; //10%
const MAX_DEVIATION_ELEV = 0.1; //20% const MAX_DEVIATION_ELEV = 0.1; //20%
public function __construct($sFileName) { public function __construct($sCodeName) {
parent::__construct($sFileName); parent::__construct($sCodeName);
} }
public function saveFile() { public function saveFile() {
@@ -217,7 +215,7 @@ class GeoJson extends Geo {
private function isPointValid($asPointA, $asPointO, $asPointB) { private function isPointValid($asPointA, $asPointO, $asPointB) {
/* A----O Calculate angle AO^OB /* 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 * \ O is valid otherwise
* B * B
*/ */

View File

@@ -116,7 +116,6 @@ class Project extends PhpObject {
'active_from', 'active_from',
'active_to', 'active_to',
"IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode", "IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode",
'geofile',
'timezone' 'timezone'
), ),
'from' => self::PROJ_TABLE 'from' => self::PROJ_TABLE
@@ -131,11 +130,10 @@ class Project extends PhpObject {
case 2: $asProject['mode'] = self::MODE_HISTO; break; 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['geofilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($sCodeName, GeoJson::EXT));
$asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($asProject['geofile'], Gpx::EXT)); $asProject['gpxfilepath'] = Spot::addTimestampToFilePath(Geo::getFilePath($sCodeName, Gpx::EXT));
unset($asProject['geofile']);
$asProject['codename'] = $sCodeName; $asProject['codename'] = $sCodeName;
} }
return $bSpecificProj?$asProject:$asProjects; return $bSpecificProj?$asProject:$asProjects;

View File

@@ -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::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::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'), 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'), 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') 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)", 'status' => "VARCHAR(10)",
'active_from' => "TIMESTAMP DEFAULT 0", 'active_from' => "TIMESTAMP DEFAULT 0",
'active_to' => "TIMESTAMP DEFAULT 0", 'active_to' => "TIMESTAMP DEFAULT 0",
'geofile' => "VARCHAR(50)",
'timezone' => "VARCHAR(100)", 'timezone' => "VARCHAR(100)",
'last_update' => "TIMESTAMP DEFAULT 0", 'last_update' => "TIMESTAMP DEFAULT 0",
'filename' => "VARCHAR(100) NOT NULL", 'filename' => "VARCHAR(100) NOT NULL",