Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge ddbb #9

Merged
merged 11 commits into from
Apr 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mergeFunc
  • Loading branch information
haitaoo1 committed Apr 27, 2024
commit 6c4cdd440537bf732ba17904df0e52cc27520007
20 changes: 10 additions & 10 deletions migration/init.sql
Original file line number Diff line number Diff line change
@@ -55,20 +55,20 @@ INSERT INTO registrants (id, name, country) VALUES

-- Insert drones with references to the registrants
INSERT INTO drones (dic, auth_code, registrants, owner_name, owner_identify, owner_email, registered_at) VALUES
('ESP00001-123-0033', 'edd22adf56e73d5ffe8490a513129923', 'ZLL', 'Zheng Lin Lei', 'Unknown', 'llzheng@oroneta.com', CURRENT_TIMESTAMP),
('FRA00001-001-0033', '45ac9f1020665490f8372ee5ef1107fd', 'EC', 'Elena Clofent', 'Unknown', 'eclemuo@oroneta.com', CURRENT_TIMESTAMP),
('ESP00002-123-0033', '699736a280a612c68ae7e5fb5690505d', 'ZL', 'Zhi Lin Lo', 'Unknown', 'zli@oroneta.com', CURRENT_TIMESTAMP),
('AUS78825-778-0001', '808122cbca3396b1977bfdd0166faa95', 'MZ', 'Maria Zapata', 'Unknown', 'mzapale@oroneta.com', CURRENT_TIMESTAMP),
('ESP88712-998-0871', 'cdb0581cae7b0aa6a415800f9d94bbf2', 'HW', 'Haitao Wu', 'Unknown', 'hwu@oroneta.com', CURRENT_TIMESTAMP);
('ESP00001-123-0033', '0', 'ZLL', 'Zheng Lin Lei', 'Unknown', 'llzheng@oroneta.com', CURRENT_TIMESTAMP),
('ESP00002-123-0033', '1', 'ZL', 'Zhi Lin Lo', 'Unknown', 'zli@oroneta.com', CURRENT_TIMESTAMP),
('ESP00003-123-0033', '2', 'EC', 'Elena Clofent', 'Unknown', 'eclemuo@oroneta.com', CURRENT_TIMESTAMP),
('AUS78825-778-0001', '3', 'MZ', 'Maria Zapata', 'Unknown', 'mzapale@oroneta.com', CURRENT_TIMESTAMP),
('ESP88712-998-0871', '4', 'HW', 'Haitao Wu', 'Unknown', 'hwu@oroneta.com', CURRENT_TIMESTAMP);


-- INSERT to routes

INSERT INTO routes (dic, auth_code, flight) VALUES
('ESP00001-123-0033', 'edd22adf56e73d5ffe8490a513129923', '[[21,32], [4,-117], [40,-74], [36,-122], [30,-97]]'),
('FRA00001-001-0033', '45ac9f1020665490f8372ee5ef1107fd', '[[48,2], [50,14], [45,9], [52,13], [60,24]]'),
('ESP00002-123-0033', '699736a280a612c68ae7e5fb5690505d', '[[52,-0.13], [40,-3.68], [41,29], [38,-9], [55,-3]]'),
('AUS78825-778-0001', '808122cbca3396b1977bfdd0166faa95', '[[33.86,151.21], [-37.81,144.96], [-31.95,115.86], [-27.47,153.03], [-42.88,147.33]]'),
('ESP88712-998-0871', 'cdb0581cae7b0aa6a415800f9d94bbf2', '[[35.68,139.69], [22.32,114.17], [1.35,103.82], [13.75,100.51], [37.57,126.98]]');
('ESP00001-123-0033', '0', '[[21,32], [4,-117], [40,-74], [36,-122], [30,-97]]'),
('ESP00002-123-0033', '1', '[[52,-0.13], [40,-3.68], [41,29], [38,-9], [55,-3]]'),
('ESP00003-123-0033', '2', '[[48,2], [50,14], [45,9], [52,13], [60,24]]');
-- ('AUS78825-778-0001', '3', '[[33.86,151.21], [-37.81,144.96], [-31.95,115.86], [-27.47,153.03], [-42.88,147.33]]'),
-- ('ESP88712-998-0871', '4', '[[35.68,139.69], [22.32,114.17], [1.35,103.82], [13.75,100.51], [37.57,126.98]]');


44 changes: 26 additions & 18 deletions src/c/main_RouteServer.cpp
Original file line number Diff line number Diff line change
@@ -62,30 +62,38 @@ int main(){
}

int collisionsCount = 0;
//Iterate over Coordinates

auto coordsArray = CoordData["coord"];

//manual conversion json to string
std::ostringstream os;
os << "[";
for (size_t i = 0; i < coordsArray.size(); ++i) {
os << "[" << coordsArray[i][0].d() << "," << coordsArray[i][1].d() << "]";
if (i < coordsArray.size() - 1) {
os << ",";
}
}
os << "]";

// Convertir rvalue a wvalue
crow::json::wvalue coordsWvalue(CoordData["coord"]);
std::string coordsString = os.str();

// Serializar wvalue a string (si dump está disponible en wvalue)
// std::string coordsString = crow::json::dump(coordsWvalue);

// // //check collisions
// if(checkColissions(conn, dic.c_str(), coordsString.c_str())){
// collisionsCount++;

// if(collisionsCount > MAX_COLLISION) {
// crow::json::wvalue responseJson;
// responseJson["status"] = 0;
// responseJson["message"] = "Route is very dangerous to be used";
// return crow::response(200, responseJson);
// }
// }
//check collisions
if(checkColissions(conn, dic.c_str(), coordsString.c_str())){
collisionsCount++;

if(collisionsCount > MAX_COLLISION) {
crow::json::wvalue responseJson;
responseJson["status"] = 0;
responseJson["message"] = "Route is very dangerous to be used";
return crow::response(200, responseJson);
}
}


//Insert drone data and coordinates
// insertRoute(conn, dic.c_str(),authCode.c_str(), coordsString);
//Collisions<MAX_COLLISION=route safe
insertRoute(conn, dic.c_str(),authCode.c_str(), coordsString.c_str());
crow::json::wvalue responseJson;
responseJson["status"] = 1;
//responseJson["dangerous_level"] = 1;