Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iacopolea committed May 17, 2018
0 parents commit 304d76f
Show file tree
Hide file tree
Showing 144 changed files with 1,330 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .idea/aerocene-data.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions api/api.php
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()));
}

?>
22 changes: 22 additions & 0 deletions api/createtable.php
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);

?>
86 changes: 86 additions & 0 deletions api/database.php
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();
}
}
}

?>
16 changes: 16 additions & 0 deletions api/drop.php
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();
}
?>
Loading

0 comments on commit 304d76f

Please sign in to comment.