Skip to content

Commit 1f8c3e0

Browse files
remove special logic to assemble trip name
1 parent 9f509de commit 1f8c3e0

File tree

3 files changed

+8
-66
lines changed

3 files changed

+8
-66
lines changed

include/nigiri/loader/gtfs/trip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct trip {
8383
timetable const&,
8484
unsigned indent = 0) const;
8585

86-
std::string display_name(timetable const&) const;
86+
std::string display_name() const;
8787

8888
clasz get_clasz(timetable const&) const;
8989

src/loader/gtfs/load_timetable.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void load_timetable(loader_config const& config,
265265
}
266266
encode_seq_numbers(trp.seq_numbers_, stop_seq_numbers);
267267
trp.trip_idx_ = tt.register_trip_id(
268-
trp.id_, trp.route_->route_id_idx_, src, trp.display_name(tt),
268+
trp.id_, trp.route_->route_id_idx_, src, trp.display_name(),
269269
{source_file_idx, trp.from_line_, trp.to_line_}, train_nr,
270270
stop_seq_numbers);
271271
}

src/loader/gtfs/trip.cc

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -188,72 +188,14 @@ void trip::interpolate() {
188188
}
189189
}
190190

191-
std::string trip::display_name(timetable const& tt) const {
192-
auto const is_digit = [](char const x) { return x >= '0' && x <= '9'; };
193-
194-
// Depending on the class, there are different expectations from users
195-
// if the special case doesn't work based on available data, fall back to
196-
// generic code afterwards
197-
switch (route_->clasz_) {
198-
// For subway / metro, only the line matters since it's frequent enough.
199-
case clasz::kSubway:
200-
case clasz::kMetro:
201-
if (!route_->short_name_.empty()) {
202-
return route_->short_name_;
203-
}
204-
break;
205-
// Deutsche Bahn heuristics to classify ICEs and ICs
206-
case clasz::kHighSpeed:
207-
case clasz::kLongDistance: {
208-
auto const trip_name_is_number =
209-
!short_name_.empty() && utl::all_of(short_name_, is_digit);
210-
if (!route_->short_name_.starts_with("IC") &&
211-
route_->agency_ != provider_idx_t::invalid() &&
212-
tt.providers_[route_->agency_].long_name_ == "DB Fernverkehr AG") {
213-
if (route_->clasz_ == clasz::kHighSpeed) {
214-
return trip_name_is_number
215-
? fmt::format("ICE {}", utl::parse<int>(short_name_))
216-
: fmt::format("ICE {}", route_->short_name_);
217-
} else if (route_->clasz_ == clasz::kLongDistance) {
218-
return trip_name_is_number
219-
? fmt::format("IC {}", utl::parse<int>(short_name_))
220-
: fmt::format("IC {}", route_->short_name_);
221-
}
222-
}
223-
224-
break;
225-
}
226-
default: {
227-
}
228-
}
229-
230-
// route name looks like product name, trip name is number
231-
auto const is_product_name = [=](std::string_view route) {
232-
return utl::all_of(route, [=](char const c) { return !is_digit(c); });
233-
};
234-
235-
auto const is_trip_number = [=](std::string_view trip_name) {
236-
return utl::all_of(trip_name, is_digit);
237-
};
238-
239-
if (!route_->short_name_.empty() && is_product_name(route_->short_name_) &&
240-
!short_name_.empty() && is_trip_number(short_name_)) {
241-
return fmt::format("{} {}", route_->short_name_,
242-
utl::parse<int>(short_name_));
243-
}
244-
245-
auto precedence = std::array{std::string_view{route_->short_name_},
246-
std::string_view{route_->long_name_},
247-
std::string_view{short_name_}};
248-
249-
// prefer route short name over route long name,
250-
// prefer route long name over trip short name
251-
for (auto const candidate : precedence) {
252-
if (!candidate.empty()) {
253-
return std::string(candidate);
191+
std::string trip::display_name() const {
192+
for (auto const str :
193+
{std::string_view{route_->short_name_},
194+
std::string_view{route_->long_name_}, std::string_view{short_name_}}) {
195+
if (!str.empty()) {
196+
return std::string{str};
254197
}
255198
}
256-
257199
return {};
258200
}
259201

0 commit comments

Comments
 (0)