Removes summary from legs property
This commit is contained in:
parent
470d7600b8
commit
eaf9993dd9
@ -22,78 +22,6 @@ namespace engine
|
|||||||
{
|
{
|
||||||
namespace guidance
|
namespace guidance
|
||||||
{
|
{
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
const constexpr std::size_t MAX_USED_SEGMENTS = 2;
|
|
||||||
struct NamedSegment
|
|
||||||
{
|
|
||||||
double duration;
|
|
||||||
std::uint32_t position;
|
|
||||||
std::uint32_t name_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <std::size_t SegmentNumber>
|
|
||||||
std::array<std::uint32_t, SegmentNumber> summarizeRoute(const std::vector<PathData> &route_data)
|
|
||||||
{
|
|
||||||
// merges segments with same name id
|
|
||||||
const auto collapse_segments = [](std::vector<NamedSegment> &segments)
|
|
||||||
{
|
|
||||||
auto out = segments.begin();
|
|
||||||
auto end = segments.end();
|
|
||||||
for (auto in = segments.begin(); in != end; ++in)
|
|
||||||
{
|
|
||||||
if (in->name_id == out->name_id)
|
|
||||||
{
|
|
||||||
out->duration += in->duration;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
++out;
|
|
||||||
BOOST_ASSERT(out != end);
|
|
||||||
*out = *in;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<NamedSegment> segments(route_data.size());
|
|
||||||
std::uint32_t index = 0;
|
|
||||||
std::transform(
|
|
||||||
route_data.begin(), route_data.end(), segments.begin(), [&index](const PathData &point)
|
|
||||||
{
|
|
||||||
return NamedSegment{point.duration_until_turn / 10.0, index++, point.name_id};
|
|
||||||
});
|
|
||||||
// this makes sure that the segment with the lowest position comes first
|
|
||||||
std::sort(segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs)
|
|
||||||
{
|
|
||||||
return lhs.name_id < rhs.name_id ||
|
|
||||||
(lhs.name_id == rhs.name_id && lhs.position < rhs.position);
|
|
||||||
});
|
|
||||||
auto new_end = collapse_segments(segments);
|
|
||||||
segments.resize(new_end - segments.begin());
|
|
||||||
// sort descending
|
|
||||||
std::sort(segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs)
|
|
||||||
{
|
|
||||||
return lhs.duration > rhs.duration;
|
|
||||||
});
|
|
||||||
|
|
||||||
// make sure the segments are sorted by position
|
|
||||||
segments.resize(std::min(segments.size(), SegmentNumber));
|
|
||||||
std::sort(segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs)
|
|
||||||
{
|
|
||||||
return lhs.position < rhs.position;
|
|
||||||
});
|
|
||||||
|
|
||||||
std::array<std::uint32_t, SegmentNumber> summary;
|
|
||||||
std::fill(summary.begin(), summary.end(), 0);
|
|
||||||
std::transform(segments.begin(), segments.end(), summary.begin(),
|
|
||||||
[](const NamedSegment &segment)
|
|
||||||
{
|
|
||||||
return segment.name_id;
|
|
||||||
});
|
|
||||||
return summary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename DataFacadeT>
|
template <typename DataFacadeT>
|
||||||
RouteLeg assembleLeg(const DataFacadeT &facade,
|
RouteLeg assembleLeg(const DataFacadeT &facade,
|
||||||
@ -140,26 +68,12 @@ RouteLeg assembleLeg(const DataFacadeT &facade,
|
|||||||
duration = duration + target_duration;
|
duration = duration + target_duration;
|
||||||
if (route_data.empty())
|
if (route_data.empty())
|
||||||
{
|
{
|
||||||
duration -=
|
duration -= (target_traversed_in_reverse ? source_node.reverse_weight
|
||||||
(target_traversed_in_reverse ? source_node.reverse_weight : source_node.forward_weight) / 10;
|
: source_node.forward_weight) /
|
||||||
|
10;
|
||||||
}
|
}
|
||||||
auto summary_array = detail::summarizeRoute<detail::MAX_USED_SEGMENTS>(route_data);
|
|
||||||
|
|
||||||
BOOST_ASSERT(detail::MAX_USED_SEGMENTS > 0);
|
return RouteLeg{duration, distance, {}};
|
||||||
BOOST_ASSERT(summary_array.begin() != summary_array.end());
|
|
||||||
std::string summary =
|
|
||||||
std::accumulate(std::next(summary_array.begin()), summary_array.end(),
|
|
||||||
facade.GetNameForID(summary_array.front()),
|
|
||||||
[&facade](std::string previous, const std::uint32_t name_id)
|
|
||||||
{
|
|
||||||
if (name_id != 0)
|
|
||||||
{
|
|
||||||
previous += ", " + facade.GetNameForID(name_id);
|
|
||||||
}
|
|
||||||
return previous;
|
|
||||||
});
|
|
||||||
|
|
||||||
return RouteLeg{duration, distance, summary, {}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace guidance
|
} // namespace guidance
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include "engine/guidance/route_step.hpp"
|
#include "engine/guidance/route_step.hpp"
|
||||||
|
|
||||||
#include <boost/optional.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
@ -19,7 +16,6 @@ struct RouteLeg
|
|||||||
{
|
{
|
||||||
double duration;
|
double duration;
|
||||||
double distance;
|
double distance;
|
||||||
std::string summary;
|
|
||||||
std::vector<RouteStep> steps;
|
std::vector<RouteStep> steps;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,6 @@ util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps)
|
|||||||
util::json::Object route_leg;
|
util::json::Object route_leg;
|
||||||
route_leg.values["distance"] = std::round(leg.distance * 10) / 10.;
|
route_leg.values["distance"] = std::round(leg.distance * 10) / 10.;
|
||||||
route_leg.values["duration"] = std::round(leg.duration * 10) / 10.;
|
route_leg.values["duration"] = std::round(leg.duration * 10) / 10.;
|
||||||
route_leg.values["summary"] = std::move(leg.summary);
|
|
||||||
route_leg.values["steps"] = std::move(steps);
|
route_leg.values["steps"] = std::move(steps);
|
||||||
return route_leg;
|
return route_leg;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
|
|||||||
{"legs", json::Array{{json::Object{
|
{"legs", json::Array{{json::Object{
|
||||||
{{"distance", 0.},
|
{{"distance", 0.},
|
||||||
{"duration", 0.},
|
{"duration", 0.},
|
||||||
{"summary", ""},
|
|
||||||
{"steps", json::Array{{json::Object{
|
{"steps", json::Array{{json::Object{
|
||||||
{{"duration", 0.},
|
{{"duration", 0.},
|
||||||
{"distance", 0.},
|
{"distance", 0.},
|
||||||
@ -134,10 +133,6 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
|
|||||||
const auto duration = leg_object.values.at("duration").get<json::Number>().value;
|
const auto duration = leg_object.values.at("duration").get<json::Number>().value;
|
||||||
BOOST_CHECK_EQUAL(duration, 0);
|
BOOST_CHECK_EQUAL(duration, 0);
|
||||||
|
|
||||||
// nothing can be said about summary, empty or contains human readable summary
|
|
||||||
const auto summary = leg_object.values.at("summary").get<json::String>().value;
|
|
||||||
BOOST_CHECK(((void)summary, true));
|
|
||||||
|
|
||||||
const auto &steps = leg_object.values.at("steps").get<json::Array>().values;
|
const auto &steps = leg_object.values.at("steps").get<json::Array>().values;
|
||||||
BOOST_CHECK(!steps.empty());
|
BOOST_CHECK(!steps.empty());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user