-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 304d76f
Showing
144 changed files
with
1,330 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
// required headers | ||
header("Access-Control-Allow-Origin: *"); | ||
header("Content-Type: application/json; charset=UTF-8"); | ||
$pagesize=30; | ||
// include database and object files | ||
include_once 'database.php'; | ||
include_once 'flight.php'; | ||
|
||
try{ | ||
$database = new Database(); | ||
$db = $database->getConnection(); | ||
$start=0; | ||
$page=1; | ||
$total_distance = 0; | ||
$count = 0; | ||
$id = -1; | ||
if (isset($_GET['page'])) { | ||
//echo $_GET['link']; | ||
if(is_numeric($_GET['page']) &&$_GET['page']>0){ | ||
$page=(int)$_GET['page']; | ||
$start=(($page-1)*$pagesize); | ||
} | ||
} | ||
if (isset($_GET['id']) && is_numeric($_GET['id'])) { | ||
$id=(int)$_GET['id']; | ||
} | ||
$query = "SELECT SUM(distance) as total_distance, COUNT(id) as count FROM EXPLORERTRAJECTORIES"; | ||
$stmt = $db->prepare($query); | ||
$stmt->execute(); | ||
$num = $stmt->rowCount(); | ||
if($num == 1){ | ||
if($row = $stmt->fetch(PDO::FETCH_ASSOC)){ | ||
$total_distance = $row['total_distance']; | ||
$count = $row['count']; | ||
} | ||
} | ||
$products_arr=array(); | ||
$query = ""; | ||
if($id > 0){ | ||
$query = "SELECT EXPLORERTRAJECTORIES.* FROM EXPLORERTRAJECTORIES WHERE id = ".$id; | ||
} else { | ||
$query = "SELECT EXPLORERTRAJECTORIES.* FROM EXPLORERTRAJECTORIES ORDER BY id DESC LIMIT ".$pagesize." OFFSET ".$start; | ||
$products_arr["total_distance"] = floatval($total_distance); | ||
$products_arr["count"] = intval($count); | ||
// $products_arr["page"] = intval($page); | ||
} | ||
$products_arr["flights"]=array(); | ||
$stmt = $db->prepare($query); | ||
$stmt->execute(); | ||
$num = $stmt->rowCount(); | ||
|
||
if($num>0){ | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ | ||
extract($row); | ||
$product_item=array( | ||
"id" => $id, | ||
"departure_date" => $departure_date, | ||
"created" => $created, | ||
"min_dist" => floatval ($min_dist), | ||
"min_time" => floatval ($min_time), | ||
"avg_speed" => floatval ($speed), | ||
"altitude" => floatval ($altitude), | ||
"distance" => floatval ($distance), | ||
"path" => json_decode($path), | ||
"departure" => array( | ||
"city" => $departure_city, | ||
"country" => $departure_country, | ||
"coordinates" =>array( | ||
"latitude" => floatval ($departure_latitude), | ||
"longitude" => floatval ($departure_longitude) | ||
) | ||
), | ||
// "email" => $email, | ||
// "username" => $username, | ||
|
||
); | ||
if($destination_city != NULL) { | ||
$product_item["destination"] = array( | ||
"city" => $destination_city, | ||
"country" => $destination_country, | ||
"coordinates" =>array( | ||
"latitude" => floatval ($destination_latitude), | ||
"longitude" => floatval ($destination_longitude) | ||
) | ||
); | ||
} | ||
if($username != NULL) { | ||
$product_item["username"] = $username; | ||
} | ||
array_push($products_arr["flights"], $product_item); | ||
} | ||
} | ||
echo json_encode($products_arr); | ||
|
||
}catch(Exception $exception){ | ||
echo json_encode(array("Exception error: " => $exception->getMessage())); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
// required headers | ||
header("Access-Control-Allow-Origin: *"); | ||
header("Content-Type: application/json; charset=UTF-8"); | ||
|
||
// include database and object files | ||
include_once 'database.php'; | ||
include_once 'flight.php'; | ||
|
||
$database = new Database(); | ||
$db = $database->getConnection(); | ||
$database->createTable(); | ||
|
||
$q = $db->prepare("DESCRIBE EXPLORERTRAJECTORIES"); | ||
$q->execute(); | ||
// echo(); | ||
$table_fields = $q->fetchAll(PDO::FETCH_COLUMN); | ||
echo json_encode($table_fields); | ||
//$table_fields = $q->fetchAll(); | ||
//print_r($table_fields); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
class Database{ | ||
/* | ||
private $host = "mysqlinstance.c1ls9liw8pr7.us-west-2.rds.amazonaws.com"; | ||
private $db_name = "dbname"; | ||
private $username = "mydbusername"; | ||
private $password = "mydbpassword"; | ||
*/ | ||
private $host = "floatpredictorinstance.clkirumppz4x.eu-central-1.rds.amazonaws.com"; | ||
private $db_name = "floatpredictor"; | ||
private $username = "floatpredictor"; | ||
private $password = 'U8$LhsZkz1EmgGjH'; | ||
public $conn; | ||
|
||
public $table_name = "EXPLORERTRAJECTORIES"; | ||
|
||
public function getConnection(){ | ||
$this->conn = null; | ||
try{ | ||
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password); | ||
$this->conn->exec("set names utf8"); | ||
//echo ("Connected"); | ||
}catch(PDOException $exception){ | ||
echo '{ "Connection error" : "'. $exception->getMessage() .'" }'; | ||
} | ||
return $this->conn; | ||
} | ||
|
||
public function listTables(){ | ||
$sql = 'SHOW TABLES'; | ||
if($this->getConnection()) | ||
{ | ||
$query = $this->conn->query($sql); | ||
return $query->fetchAll(PDO::FETCH_COLUMN); | ||
} | ||
return FALSE; | ||
} | ||
public function dropTable(){ | ||
$db = $this->getConnection(); | ||
$ret=$db->exec("DROP TABLE EXPLORERTRAJECTORIES"); | ||
} | ||
public function createTable(){ | ||
try{ | ||
$db = $this->getConnection(); | ||
$sql = | ||
<<<EOF | ||
CREATE TABLE IF NOT EXISTS EXPLORERTRAJECTORIES( | ||
id INT(11) AUTO_INCREMENT NOT NULL, | ||
min_dist REAL NOT NULL, | ||
min_time REAL NOT NULL, | ||
speed REAL NOT NULL, | ||
distance REAL NOT NULL, | ||
altitude REAL NOT NULL, | ||
departure_date DATETIME NOT NULL, | ||
path TEXT NOT NULL, | ||
departure_city VARCHAR(50) NOT NULL, | ||
departure_country VARCHAR(50) NOT NULL, | ||
departure_longitude REAL NOT NULL, | ||
departure_latitude REAL NOT NULL, | ||
destination_city VARCHAR(50), | ||
destination_country VARCHAR(50), | ||
destination_longitude REAL, | ||
destination_latitude REAL, | ||
created TIMESTAMP, | ||
email VARCHAR(50), | ||
username VARCHAR(50), | ||
PRIMARY KEY (id)) | ||
ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; | ||
EOF; | ||
|
||
$ret=$db->exec($sql); | ||
/*if(!$ret) { | ||
echo ("error"); | ||
} else { | ||
echo "Table created successfully\n"; | ||
}*/ | ||
|
||
} | ||
|
||
catch(PDOException $e){ | ||
echo $e->getMessage(); | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
// required headers | ||
header("Access-Control-Allow-Origin: *"); | ||
header("Content-Type: application/json; charset=UTF-8"); | ||
|
||
// include database and object files | ||
include_once 'database.php'; | ||
include_once 'flight.php'; | ||
try{ | ||
$database = new Database(); | ||
$database->dropTable(); | ||
echo '{"result":"ok"}'; | ||
}catch(PDOException $exception){ | ||
echo "Connection error: " . $exception->getMessage(); | ||
} | ||
?> |
Oops, something went wrong.