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

Improve trip display name #174

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
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
26 changes: 5 additions & 21 deletions src/loader/gtfs/trip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,28 +242,12 @@ std::string trip::display_name(timetable const& tt) const {
utl::parse<int>(short_name_));
}

// take the first thing that starts with a letter and ends with a number
auto const starts_with_letter_and_ends_with_number =
[=](std::string_view line_id) {
return !is_digit(line_id.front()) && is_digit(line_id.back());
};
auto precedence = std::array{std::string_view{route_->short_name_},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for all feeds that use semantic naming instead of the google maps convention.
That is as far as I know most of the data for Germany and Austria

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly doesn't work, not prefering trip short name?
Do you have any specific example in mind?

std::string_view{route_->long_name_},
std::string_view{short_name_}};

auto precedence = std::array{std::string_view{short_name_},
std::string_view{route_->short_name_},
std::string_view{route_->long_name_}};

for (auto const candidate : precedence) {
if (candidate.empty()) {
continue;
}

if (starts_with_letter_and_ends_with_number(candidate)) {
return std::string(candidate);
}
}

// prefer trip name over route short name,
// prefer route short name over route long name
// prefer route short name over route long name,
// prefer route long name over trip short name
for (auto const candidate : precedence) {
if (!candidate.empty()) {
return std::string(candidate);
Expand Down