Commit 35a2e01d authored by Constantin Pohl's avatar Constantin Pohl
Browse files

Added port file & output

parent e6867dcb
......@@ -3,16 +3,18 @@
#include "pfabric.hpp"
using namespace pfabric;
//raw input tuple from file
typedef TuplePtr<
std::string, //vessel_ID
short, //speed
int, //longitude
int, //latitude
short, //course
short, //heading
double, //longitude
double, //latitude
int, //course
int, //heading
std::string, //timestamp
std::string, //departure port name
std::string //reported draught
......@@ -26,40 +28,64 @@ typedef TuplePtr<
//preprocessed tuple
typedef TuplePtr<
size_t, //vessel_ID
short, //speed
int, //longitude
int, //latitude
short, //course
short, //heading
//Timestamp, //timestamp
std::string, //timestamp
std::string, //departure port name
int //reported draught
std::string, //vessel_ID
short, //speed
double, //longitude
double, //latitude
int, //course
int, //heading
std::string, //timestamp
std::string, //departure port name
int //reported draught
> preprocInput;
//port vector
typedef std::vector<std::tuple<
std::string, //port name
double, //port longitude
double> //port latitude
> portVector;
/*
* The following is done in preprocessing:
* - ID is a hex value, initially stored in String because of intense size, hash to size_t for later partitioning
* - Timestamp is initially a String, convert to Timestamp (TODO)
* - Some test data does not have a draught value, replace attribute with 0 and convert to int
* - Read ports from file
*/
inline preprocInput preprocessing(rawInput tp) {
size_t hx = std::hash<std::string>{}(get<0>(tp));
//TODO Parse String to Timestamp
//Timestamp tm = ...
std::string tm = get<6>(tp);
if(get<8>(tp).length() == 1) {
return makeTuplePtr(hx, get<1>(tp), get<2>(tp),
return makeTuplePtr(get<0>(tp), get<1>(tp), get<2>(tp),
get<3>(tp), get<4>(tp), get<5>(tp),
tm, get<7>(tp), 0);
get<6>(tp), get<7>(tp), 0);
} else {
return makeTuplePtr(hx, get<1>(tp), get<2>(tp),
return makeTuplePtr(get<0>(tp), get<1>(tp), get<2>(tp),
get<3>(tp), get<4>(tp), get<5>(tp),
tm, get<7>(tp), stoi(get<8>(tp)));
get<6>(tp), get<7>(tp), stoi(get<8>(tp)));
}
}
inline void readPorts(portVector& portVec) {
std::string portLine;
std::string portName;
size_t pos = 0;
double lon;
double lat;
std::ifstream portFile("../src/DEBS2018/data/ports.csv");
if (portFile.is_open()) {
while(std::getline(portFile, portLine)) {
pos = portLine.find(",");
portName = portLine.substr(0, pos);
portLine.erase(0, pos+1);
pos = portLine.find(",");
lon = stod(portLine.substr(0, pos));
portLine.erase(0, pos+1);
pos = portLine.find(",");
lat = stod(portLine.substr(0, pos));
portVec.push_back(std::make_tuple(portName, lon, lat));
}
portFile.close();
} else {
std::cout<<"Port file not found."<<std::endl;
}
}
......@@ -71,6 +97,18 @@ inline preprocInput preprocessing(rawInput tp) {
int main(int argc, char **argv) {
//port: circle of 12km around (longitude, latitude) is the bounding box (TODO)
std::vector<std::tuple<
std::string, //port name
double, //port longitude
double> //port latitude
> ports(0);
readPorts(ports);
for(size_t i=0; i<ports.size(); i++) {
std::cout<<"Port: "<<std::get<0>(ports[i])<<", lon: "<<std::get<1>(ports[i])<<", lat: "<<std::get<2>(ports[i])<<std::endl;
}
PFabricContext ctx;
auto t = ctx.createTopology();
......@@ -82,7 +120,7 @@ int main(int argc, char **argv) {
//.partitionBy([](auto tp) { return get<0>(tp) % 5; }, 5)
//TODO: Do something with the data
//.merge()
.print()
//.print()
;
//Read test file 2
......@@ -93,7 +131,7 @@ int main(int argc, char **argv) {
//.partitionBy([](auto tp) { return get<0>(tp) % 5; }, 5)
//TODO: Do something with the data
//.merge()
.print()
//.print()
;
t->start(false);
......
ALEXANDRIA,29.87560,31.18424
AUGUSTA,15.21417,37.19920
BARCELONA,2.15844,41.35238
CARTAGENA,-0.96793,37.58017
CEUTA,-5.31317,35.89361
DAMIETTA,31.76100,31.46800
DILISKELESI,29.53376,40.76661
FOS SUR MER,4.86513,43.42291
GEMLIK,29.11552,40.42740
GENOVA,8.90911,44.40355
GIBRALTAR,-5.36475,36.14380
HAIFA,35.00391,32.83316
ISKENDERUN,36.17972,36.68401
LIVORNO,10.30616,43.56281
MARSAXLOKK,14.54345,35.82770
MONACO,7.42689,43.73548
NEMRUT,26.90016,38.76553
PALMA DE MALLORCA,2.63237,39.55724
PIRAEUS,23.61056,37.94606
PORT SAID,32.32300,31.24478
TARRAGONA,1.22472,41.10103
TUZLA,29.29471,40.83438
VALENCIA,-0.31647,39.44231
VALLETTA,14.51505,35.89301
YALOVA,29.47632,40.71889
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment