Fix table response format to return null + double in seconds
This commit is contained in:
parent
00d75ece64
commit
bcfbc0cf6c
@ -36,21 +36,31 @@ class TableAPI final : public BaseAPI
|
||||
const std::vector<PhantomNode> &phantoms,
|
||||
util::json::Object &response) const
|
||||
{
|
||||
auto number_of_sources = parameters.sources.size();
|
||||
auto number_of_destinations = parameters.destinations.size();;
|
||||
|
||||
// symmetric case
|
||||
if (parameters.sources.empty())
|
||||
{
|
||||
BOOST_ASSERT(parameters.destinations.empty());
|
||||
response.values["sources"] = MakeWaypoints(phantoms);
|
||||
response.values["destinations"] = MakeWaypoints(phantoms);
|
||||
response.values["durations"] = MakeTable(durations, phantoms.size(), phantoms.size());
|
||||
number_of_sources = phantoms.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
response.values["sources"] = MakeWaypoints(phantoms, parameters.sources);
|
||||
response.values["destinations"] = MakeWaypoints(phantoms, parameters.destinations);
|
||||
response.values["durations"] =
|
||||
MakeTable(durations, parameters.sources.size(), parameters.destinations.size());
|
||||
}
|
||||
|
||||
if (parameters.destinations.empty())
|
||||
{
|
||||
response.values["destinations"] = MakeWaypoints(phantoms);
|
||||
number_of_destinations = phantoms.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
response.values["destinations"] = MakeWaypoints(phantoms, parameters.destinations);
|
||||
}
|
||||
|
||||
response.values["durations"] = MakeTable(durations, number_of_sources, number_of_destinations);
|
||||
response.values["code"] = "ok";
|
||||
}
|
||||
|
||||
@ -94,7 +104,15 @@ class TableAPI final : public BaseAPI
|
||||
util::json::Array json_row;
|
||||
auto row_begin_iterator = values.begin() + (row * number_of_columns);
|
||||
auto row_end_iterator = values.begin() + ((row + 1) * number_of_columns);
|
||||
json_row.values.insert(json_row.values.end(), row_begin_iterator, row_end_iterator);
|
||||
json_row.values.resize(number_of_columns);
|
||||
std::transform(row_begin_iterator, row_end_iterator, json_row.values.begin(), [](const EdgeWeight duration)
|
||||
{
|
||||
if (duration == INVALID_EDGE_WEIGHT)
|
||||
{
|
||||
return util::json::Value(util::json::Null());
|
||||
}
|
||||
return util::json::Value(util::json::Number(duration / 10.));
|
||||
});
|
||||
json_table.values.push_back(std::move(json_row));
|
||||
}
|
||||
return json_table;
|
||||
|
Loading…
Reference in New Issue
Block a user