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

ND-163 - Enrich NTFS with HelloGo fares #267

Merged
merged 4 commits into from
Jun 24, 2019

Conversation

woshilapin
Copy link
Contributor

No description provided.

}

let line_ref = get_line_ref(fare_frame)?;
let line_id = get_line_id_from_line_ref(service_frame, line_ref)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

As a reminder, do not forget to check if the line exists in collections.lines.

Copy link
Contributor Author

@woshilapin woshilapin Jun 19, 2019

Choose a reason for hiding this comment

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

Thanks for the reminder. It is now done in the commit that introduce modifications to handle prefixes (see 09154d7).

@woshilapin woshilapin force-pushed the ND-163 branch 2 times, most recently from 09154d7 to 04bd8c8 Compare June 20, 2019 08:53

fn load_fare_file(collections: &mut Collections, root: &Element) -> Result<()> {
let prefix = get_prefix(&collections)?;
let prefix_column = prefix.clone() + ":";
Copy link
Contributor

Choose a reason for hiding this comment

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

Only concatenate if a prefix exists, otherwise the result of the variable does not make sense (and objects in the collection will not be found).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean something like this.

Suggested change
let prefix_column = prefix.clone() + ":";
let prefix_column = if prefix.is_empty() {
"".to_string()
} else {
prefix.clone() + ":"
};

Copy link
Contributor Author

@woshilapin woshilapin Jun 21, 2019

Choose a reason for hiding this comment

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

Oh, I actually made the get_prefix() function used just above return a Result, meaning, it would fail if no prefix is found. Maybe I need to convert to an Option. Let me try to rework all of that.

Another question that came up is, what if the contributor_id is equal to NTM: (very edgy case, I agree). Should I detect the prefix NTM (but that would essentially mean the ID is empty), or should I consider that it is not prefixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I discussed the edge cases with @prhod and:

  • If contributor_id is NTM: (so without a suffix), just act as normal and extract the prefix
  • If contributor_id is something like 123 (no prefix), process the NTFS as a non-prefixed NTFS

I also realized that the name prefix_column didn't make much sense because... what I meant was prefix_with_colon. I also did the change accordingly. Look commit 599ab46 for the changes.

@woshilapin woshilapin force-pushed the ND-163 branch 4 times, most recently from 9a96037 to a5c56c7 Compare June 21, 2019 11:51
Copy link
Member

@datanel datanel left a comment

Choose a reason for hiding this comment

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

nice work 👍

Ok(origin_destinations)
}

fn load_fare_file(collections: &mut Collections, root: &Element) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like load_fare_file as I don't see files but I don't have a better name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, it's not a file. I changed it to load_netex_fares which might not be perfect either but maybe a little bit better (see ee4c4b8).

/// For HelloGo fares connector, we need the prefix of the input NTFS.
/// The prefix will be extracted from the 'contributor_id'
fn get_prefix(collections: &Collections) -> Option<String> {
if let Some((_, contributor)) = collections.contributors.iter().next() {
Copy link
Member

Choose a reason for hiding this comment

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

collections
        .contributors
        .values()
        .next()
        .and_then(|c| c.id.find(':').map(|index| c.id[..index].to_string()))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice rustic improvement, done in 0c57c90.

}

fn load_fare_file(collections: &mut Collections, root: &Element) -> Result<()> {
let prefix_with_colon = if let Some(prefix) = get_prefix(&collections) {
Copy link
Member

Choose a reason for hiding this comment

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

let prefix_with_colon = get_prefix(&collections)
        .map(|prefix| prefix + ":")
        .unwrap_or_else(|| "".to_string());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice rustic improvement, done in 5a3d82b.

key,
element.name()
)
} else {
Copy link
Member

Choose a reason for hiding this comment

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

you can remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 812eec1.

.try_only_child("FrameDefaults")?
.try_only_child("DefaultCurrency")?
.text();
if iso4217::alpha3(currency.as_str()).is_some() {
Copy link
Member

Choose a reason for hiding this comment

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

or early return, as you want

if iso4217::alpha3(currency.as_str()).is_none() {
    bail!("Failed to validate '{}' as a currency", currency);
}

Ok(currency)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 3ccab53.


impl From<String> for TicketUse {
fn from(ticket_id: String) -> Self {
let ticket_use_id = format!("TU:{}", ticket_id.clone()).to_string();
Copy link
Member

Choose a reason for hiding this comment

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

let ticket_use_id = format!("TU:{}", &ticket_id);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I choose to do it without the format!() macro. See 0c7b22f.

@woshilapin
Copy link
Contributor Author

I also added some more integration tests for NTFS without prefixes. See 22d130d.

@woshilapin woshilapin force-pushed the ND-163 branch 2 times, most recently from 88e0612 to df1cc03 Compare June 24, 2019 12:14
@ArnaudOggy ArnaudOggy merged commit b9c5857 into hove-io:fare-v2 Jun 24, 2019
@woshilapin woshilapin deleted the ND-163 branch June 24, 2019 15:29
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.

None yet

3 participants