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

[feature] Improve line names #747

Merged
merged 1 commit into from
Feb 23, 2021
Merged

[feature] Improve line names #747

merged 1 commit into from
Feb 23, 2021

Conversation

ArnaudOggy
Copy link
Contributor

@ArnaudOggy ArnaudOggy commented Feb 22, 2021

If a line name is empty, it's set with the name of its first "forward" route (in alphabetical order)

Ref. ND-1229

Note: apparently no fixtures to update for its little brother tartare-tools 😉

src/model.rs Outdated
@@ -1153,6 +1153,31 @@ impl Collections {
}
}

/// If a line name is empty, it's set with the name of its first "forward" route (in alphabetical order)
Copy link
Contributor

Choose a reason for hiding this comment

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

hum maybe it would be better to put this in a separate enhancers module like what has been done in #738 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s prettier. Done 👍

src/model.rs Outdated
@@ -1153,6 +1153,31 @@ impl Collections {
}
}

/// If a line name is empty, it's set with the name of its first "forward" route (in alphabetical order)
pub fn enhance_line_names(&mut self, lines_to_routes: &impl Relation<From = Line, To = Route>) {
let mut line_names: HashMap<Idx<Line>, String> = HashMap::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

very minor and quite picky but if I understand this correctly, this could be a Vec<(Idx<Line>, String)> no?

Copy link
Contributor Author

@ArnaudOggy ArnaudOggy Feb 23, 2021

Choose a reason for hiding this comment

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

Lighter indeed ! Done

src/model.rs Outdated

#[test]
fn non_empty_line_with_non_empty_route() {
let mut collections = Collections::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

If the line were handled by the ModelBuilder you can use it here and I think it would be nice to.
This could be written as

let model = transit_model_builder::ModelBuilder::default()
        .line("line_id1", |l| {l.name = "my line id".to_owned();})
        .route("route_id1", |r| {
            r.line_id = "line_id1".to_owned();
            r.direction_type = Some("forward".to_owned());
            r.name = "my route id1".to_owned();
        })
        .build();

Copy link
Contributor

Choose a reason for hiding this comment

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

I can add it to your PR if you want writing rust would be a nice Jenkins/kube break 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we keep it in mind for later 😄

Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

I'm wondering why enhance_route_name was not used for that. A function like the following one could have been extracted

fn generate_name(trips: impl Iterator<Item = VehicleJourney>) -> String;

and then used for both enhance_route_name and enhance_line_name. This would make it homogeneous in the way we generate these names.

Note however that what I'm proposing has a substantial performance impact compared to your solution since calculating frequencies is more work and is obviously different in term of requirement.

@ArnaudOggy ArnaudOggy marked this pull request as draft February 23, 2021 09:17
@ArnaudOggy
Copy link
Contributor Author

I'm wondering why enhance_route_name was not used for that. A function like the following one could have been extracted

fn generate_name(trips: impl Iterator<Item = VehicleJourney>) -> String;

and then used for both enhance_route_name and enhance_line_name. This would make it homogeneous in the way we generate these names.

Note however that what I'm proposing has a substantial performance impact compared to your solution since calculating frequencies is more work and is obviously different in term of requirement.

as seen together we will keep it simple for the moment, but indicate this possibility in code comment, and in the associated request ticket

@ArnaudOggy ArnaudOggy marked this pull request as ready for review February 23, 2021 14:58
Copy link
Contributor

@antoine-de antoine-de left a comment

Choose a reason for hiding this comment

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

👍

}
}
for (line_idx, line_name) in line_names {
// note: choice is made to keep 'forward_line_name' and 'backward_line_name' as its are
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// note: choice is made to keep 'forward_line_name' and 'backward_line_name' as its are
// note: choice is made to keep 'forward_line_name' and 'backward_line_name' as it is

@ArnaudOggy ArnaudOggy merged commit a6db573 into master Feb 23, 2021
@ArnaudOggy ArnaudOggy deleted the improve_line_names branch February 23, 2021 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants