Skip to content

Commit

Permalink
Removed voice & banner instructions from last step and added ssmlAnno…
Browse files Browse the repository at this point in the history
…uncements (#4644)

Co-authored-by: Christian <58629404+chrstnbwnkl@users.noreply.github.com>
  • Loading branch information
Trietes and chrstnbwnkl committed Jun 4, 2024
1 parent c14d3ac commit 78c1701
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
* ADDED: elapsed_cost field to map matching json response [#4709](https://github.com/valhalla/valhalla/pull/4709)
* ADDED: error if we fail to find any matrix connection [#4718](https://github.com/valhalla/valhalla/pull/4718)
* ADDED: Fail early in valhalla_ingest_transit if there's no valid GTFS feeds [#4710](https://github.com/valhalla/valhalla/pull/4710/)
* ADDED: Added ssmlAnnouncements for voice instructions and removed voice and banner instructions from last step. [#4644](https://github.com/valhalla/valhalla/pull/4644)

## Release Date: 2023-05-11 Valhalla 3.4.0
* **Removed**
Expand Down
23 changes: 18 additions & 5 deletions src/tyr/route_serializer_osrm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,10 @@ json::ArrayPtr voice_instructions(const valhalla::DirectionsLeg::Maneuver* prev_
voice_instruction_start->emplace("distanceAlongGeometry", json::fixed_t{distance, 1});
voice_instruction_start->emplace("announcement",
prev_maneuver->verbal_pre_transition_instruction());
voice_instruction_start->emplace("ssmlAnnouncement",
"<speak>" +
prev_maneuver->verbal_pre_transition_instruction() +
"</speak>");
voice_instructions_array->emplace_back(std::move(voice_instruction_start));
} else if (distance > distance_before_verbal_transition_alert_instruction +
APPROXIMATE_VERBAL_POSTRANSITION_LENGTH &&
Expand All @@ -1527,6 +1531,10 @@ json::ArrayPtr voice_instructions(const valhalla::DirectionsLeg::Maneuver* prev_
voice_instruction_beginning->emplace("distanceAlongGeometry", json::fixed_t{distance - 10, 1});
voice_instruction_beginning->emplace("announcement",
prev_maneuver->verbal_post_transition_instruction());
voice_instruction_beginning->emplace("ssmlAnnouncement",
"<speak>" +
prev_maneuver->verbal_post_transition_instruction() +
"</speak>");
voice_instructions_array->emplace_back(std::move(voice_instruction_beginning));
}
}
Expand All @@ -1545,6 +1553,9 @@ json::ArrayPtr voice_instructions(const valhalla::DirectionsLeg::Maneuver* prev_
json::fixed_t{distance_before_verbal_transition_alert_instruction, 1});
}
voice_instruction_end->emplace("announcement", maneuver.verbal_transition_alert_instruction());
voice_instruction_end->emplace("ssmlAnnouncement",
"<speak>" + maneuver.verbal_transition_alert_instruction() +
"</speak>");
voice_instructions_array->emplace_back(std::move(voice_instruction_end));
}

Expand All @@ -1563,6 +1574,9 @@ json::ArrayPtr voice_instructions(const valhalla::DirectionsLeg::Maneuver* prev_
1});
}
voice_instruction_end->emplace("announcement", maneuver.verbal_pre_transition_instruction());
voice_instruction_end->emplace("ssmlAnnouncement",
"<speak>" + maneuver.verbal_pre_transition_instruction() +
"</speak>");
voice_instructions_array->emplace_back(std::move(voice_instruction_end));
}

Expand Down Expand Up @@ -1839,9 +1853,8 @@ json::ArrayPtr serialize_legs(const google::protobuf::RepeatedPtrField<valhalla:
prev_distance, drive_side));
}
if (arrive_maneuver) {
step->emplace("bannerInstructions",
banner_instructions(name, dest, ref, prev_maneuver, maneuver, arrive_maneuver,
&etp, mnvr_type, modifier, ex, distance, drive_side));
// just add empty array for arrival maneuver
step->emplace("bannerInstructions", json::array({}));
}
}

Expand All @@ -1853,8 +1866,8 @@ json::ArrayPtr serialize_legs(const google::protobuf::RepeatedPtrField<valhalla:
maneuver_index, &etp));
}
if (arrive_maneuver) {
step->emplace("voiceInstructions",
voice_instructions(prev_maneuver, maneuver, distance, maneuver_index, &etp));
// just add empty array for arrival maneuver
step->emplace("voiceInstructions", json::array({}));
}
}

Expand Down
34 changes: 25 additions & 9 deletions test/gurka/test_osrm_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -571,17 +571,24 @@ gurka::map VoiceInstructions::map = {};
TEST_F(VoiceInstructions, VoiceInstructionsPresent) {
auto json = json_request("A", "F");
auto steps = json["routes"][0]["legs"][0]["steps"].GetArray();
// Validate that each step has voiceInstructions with announcement and distanceAlongGeometry
for (int step = 0; step < steps.Size(); ++step) {
// Validate that each step (except the last one) has voiceInstructions with announcement,
// ssmlAnnouncement and distanceAlongGeometry
for (int step = 0; step < steps.Size() - 1; ++step) {
ASSERT_TRUE(steps[step].HasMember("voiceInstructions"));
ASSERT_TRUE(steps[step]["voiceInstructions"].IsArray());

EXPECT_GT(steps[step]["voiceInstructions"].Size(), 0);
for (int instr = 0; instr < steps[step]["voiceInstructions"].GetArray().Size(); ++instr) {
ASSERT_TRUE(steps[step]["voiceInstructions"][instr].HasMember("announcement"));
ASSERT_TRUE(steps[step]["voiceInstructions"][instr].HasMember("ssmlAnnouncement"));
ASSERT_TRUE(steps[step]["voiceInstructions"][instr].HasMember("distanceAlongGeometry"));
}
}

// Validate the last step as empty voiceInstructions
ASSERT_TRUE(steps[steps.Size() - 1].HasMember("voiceInstructions"));
ASSERT_TRUE(steps[steps.Size() - 1]["voiceInstructions"].IsArray());
EXPECT_EQ(steps[steps.Size() - 1]["voiceInstructions"].Size(), 0);
}

// depart_instruction
Expand Down Expand Up @@ -695,9 +702,8 @@ TEST_F(VoiceInstructions, AllVoiceInstructions) {
EXPECT_GT(final_arrive_instruction["distanceAlongGeometry"].GetFloat(), 41);
EXPECT_LT(final_arrive_instruction["distanceAlongGeometry"].GetFloat(), 43);

auto last_instruction = steps[2]["voiceInstructions"][0].GetObject();
EXPECT_STREQ(last_instruction["announcement"].GetString(), "You will arrive at your destination.");
EXPECT_EQ(last_instruction["distanceAlongGeometry"].GetFloat(), 0.0);
auto last_instruction = steps[2]["voiceInstructions"].GetArray();
EXPECT_EQ(last_instruction.Size(), 0);
}

TEST(Standalone, BannerInstructions) {
Expand Down Expand Up @@ -749,8 +755,8 @@ TEST(Standalone, BannerInstructions) {

auto steps = json["routes"][0]["legs"][0]["steps"].GetArray();

// Validate that each step has bannerInstructions with primary
for (int step = 0; step < steps.Size(); ++step) {
// Validate that each step (except the last one) has bannerInstructions with primary
for (int step = 0; step < steps.Size() - 1; ++step) {
ASSERT_TRUE(steps[step].HasMember("bannerInstructions"));
ASSERT_TRUE(steps[step]["bannerInstructions"].IsArray());
EXPECT_GT(steps[step]["bannerInstructions"].GetArray().Size(), 0);
Expand All @@ -762,6 +768,11 @@ TEST(Standalone, BannerInstructions) {
ASSERT_TRUE(steps[step]["bannerInstructions"][instr]["primary"].HasMember("components"));
ASSERT_TRUE(steps[step]["bannerInstructions"][instr]["primary"]["components"].IsArray());
}

// Validate the last step has empty bannerInstructions
ASSERT_TRUE(steps[steps.Size() - 1].HasMember("bannerInstructions"));
ASSERT_TRUE(steps[steps.Size() - 1]["bannerInstructions"].IsArray());
EXPECT_EQ(steps[steps.Size() - 1]["bannerInstructions"].GetArray().Size(), 0);
}

// validate first step has two bannerInstruction
Expand Down Expand Up @@ -957,8 +968,8 @@ TEST(Standalone, BannerInstructionsRoundabout) {

auto steps = json["routes"][0]["legs"][0]["steps"].GetArray();

// Validate that each step has bannerInstructions with primary
for (int step = 0; step < steps.Size(); ++step) {
// Validate that each step (except the last one) has bannerInstructions with primary
for (int step = 0; step < steps.Size() - 1; ++step) {
ASSERT_TRUE(steps[step].HasMember("bannerInstructions"));
ASSERT_TRUE(steps[step]["bannerInstructions"].IsArray());
EXPECT_GT(steps[step]["bannerInstructions"].GetArray().Size(), 0);
Expand All @@ -972,6 +983,11 @@ TEST(Standalone, BannerInstructionsRoundabout) {
}
}

// Validate the last step has empty bannerInstructions
ASSERT_TRUE(steps[steps.Size() - 1].HasMember("bannerInstructions"));
ASSERT_TRUE(steps[steps.Size() - 1]["bannerInstructions"].IsArray());
EXPECT_EQ(steps[steps.Size() - 1]["bannerInstructions"].GetArray().Size(), 0);

// validate first step's primary instructions
auto primary_0 = steps[0]["bannerInstructions"][0]["primary"].GetObject();
EXPECT_STREQ(primary_0["type"].GetString(), "rotary");
Expand Down

0 comments on commit 78c1701

Please sign in to comment.