Implemented 'skip_waypoints' for the 'Nearest' service.

It actually makes no sence, as the only output on the 'Nearest' service
is a list of wypoints. On the other hand it can be used now as a simple
health check.
This commit is contained in:
Denis Chaplygin 2019-09-16 11:44:08 +03:00
parent 10c1b38139
commit 1b47242a58

View File

@ -6,6 +6,7 @@
#include "engine/api/json_factory.hpp" #include "engine/api/json_factory.hpp"
#include "engine/phantom_node.hpp" #include "engine/phantom_node.hpp"
#include "base_result.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -54,25 +55,30 @@ class NearestAPI final : public BaseAPI
data_version_string = fb_result.CreateString(data_timestamp); data_version_string = fb_result.CreateString(data_timestamp);
} }
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> waypoints_vector;
waypoints.resize(phantom_nodes.front().size()); if (!parameters.skip_waypoints) {
std::transform(phantom_nodes.front().begin(), std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
phantom_nodes.front().end(), waypoints.resize(phantom_nodes.front().size());
waypoints.begin(), std::transform(phantom_nodes.front().begin(),
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) { phantom_nodes.front().end(),
auto &phantom_node = phantom_with_distance.phantom_node; waypoints.begin(),
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) {
auto &phantom_node = phantom_with_distance.phantom_node;
auto node_values = MakeNodes(phantom_node); auto node_values = MakeNodes(phantom_node);
fbresult::Uint64Pair nodes{node_values.first, node_values.second}; fbresult::Uint64Pair nodes{node_values.first, node_values.second};
auto waypoint = MakeWaypoint(fb_result, phantom_node); auto waypoint = MakeWaypoint(fb_result, phantom_node);
waypoint.add_nodes(&nodes); waypoint.add_nodes(&nodes);
return waypoint.Finish(); return waypoint.Finish();
}); });
waypoints_vector = fb_result.CreateVector(waypoints);
}
auto waypoints_vector = fb_result.CreateVector(waypoints);
fbresult::FBResultBuilder response(fb_result); fbresult::FBResultBuilder response(fb_result);
response.add_waypoints(waypoints_vector); response.add_waypoints(waypoints_vector);
if (data_version_string) if (data_version_string)
{ {
@ -83,28 +89,30 @@ class NearestAPI final : public BaseAPI
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes, void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
util::json::Object &response) const util::json::Object &response) const
{ {
util::json::Array waypoints; if (!parameters.skip_waypoints) {
waypoints.values.resize(phantom_nodes.front().size()); util::json::Array waypoints;
std::transform(phantom_nodes.front().begin(), waypoints.values.resize(phantom_nodes.front().size());
phantom_nodes.front().end(), std::transform(phantom_nodes.front().begin(),
waypoints.values.begin(), phantom_nodes.front().end(),
[this](const PhantomNodeWithDistance &phantom_with_distance) { waypoints.values.begin(),
auto &phantom_node = phantom_with_distance.phantom_node; [this](const PhantomNodeWithDistance &phantom_with_distance) {
auto waypoint = MakeWaypoint(phantom_node); auto &phantom_node = phantom_with_distance.phantom_node;
auto waypoint = MakeWaypoint(phantom_node);
util::json::Array nodes; util::json::Array nodes;
auto node_values = MakeNodes(phantom_node); auto node_values = MakeNodes(phantom_node);
nodes.values.push_back(node_values.first); nodes.values.push_back(node_values.first);
nodes.values.push_back(node_values.second); nodes.values.push_back(node_values.second);
waypoint.values["nodes"] = std::move(nodes); waypoint.values["nodes"] = std::move(nodes);
return waypoint; return waypoint;
}); });
response.values["waypoints"] = std::move(waypoints);
}
response.values["code"] = "Ok"; response.values["code"] = "Ok";
response.values["waypoints"] = std::move(waypoints);
} }
const NearestParameters &parameters; const NearestParameters &parameters;