Skip to content

Commit

Permalink
Update gtfs_structures
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-de committed Apr 8, 2024
1 parent 1728f07 commit d700eb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/metadatas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ pub fn compute_stats(gtfs: &gtfs_structures::RawGtfs) -> Stats {
}; // white
r.text_color != text_default_color || r.color != route_default_color
}),
routes_with_long_name_count: counts_objects(&gtfs.routes, |r| !r.long_name.is_empty()),
routes_with_short_name_count: counts_objects(&gtfs.routes, |r| !r.short_name.is_empty()),
routes_with_long_name_count: counts_objects(&gtfs.routes, |r| {
!r.long_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
}),
routes_with_short_name_count: counts_objects(&gtfs.routes, |r| {
!r.short_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
}),

trips_count: gtfs.trips.as_ref().map(|t| t.len()).unwrap_or(0),
trips_with_bike_info_count: counts_objects(&gtfs.trips, |t| {
Expand Down
8 changes: 7 additions & 1 deletion src/validators/check_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub fn validate(gtfs: &gtfs_structures::Gtfs) -> Vec<Issue> {
let route_issues = gtfs
.routes
.values()
.filter(empty_name)
.filter(|r| empty_route_name(r))
.map(make_missing_name_issue);
let stop_issues = gtfs
.stops
Expand Down Expand Up @@ -32,6 +32,12 @@ fn empty_name<T: std::fmt::Display>(o: &T) -> bool {
format!("{}", o).is_empty()
}

// a route has a name if it has either a short or a long name
fn empty_route_name(r: &gtfs_structures::Route) -> bool {
r.short_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
|| r.long_name.as_ref().map(|n| n.is_empty()).unwrap_or(true)
}

fn make_missing_name_issue<T: gtfs_structures::Id + gtfs_structures::Type + std::fmt::Display>(
o: &T,
) -> Issue {
Expand Down

0 comments on commit d700eb6

Please sign in to comment.