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

handling time dependent restrictions #3029

Merged

Conversation

CuriOusQuOkka
Copy link
Contributor

@CuriOusQuOkka CuriOusQuOkka commented Apr 23, 2021

Issue

Valhalla missed conditional TR mapped according to previous tagging schema #441

Tasklist

@CuriOusQuOkka CuriOusQuOkka changed the title handling old-style time dependent restrictions handling time dependent restrictions Apr 23, 2021
TEST_F(TimeDependentRestrictions, ActiveHourRestriction) {
auto result =
gurka::do_action(valhalla::Options::route, map, {"A", "F"}, "auto",
{{"/date_time/type", "1"}, {"/date_time/value", "2021-04-02T14:00"}});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test it for other date_time types (0,2 & 3)? These types invoke different routing algorithms so it'll be good to test the timed TRs here in case it breaks in one algo and not another.

You can use parametrized tests to pass each of the date_time types.

Copy link
Member

Choose a reason for hiding this comment

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

If any of them are failing, they can be flagged with a DISABLED_ prefix - at least then we'll get notice that they're not fixed yet, and we could add a CI step to try non-fatally running disabled tests :

https://google.github.io/googletest/advanced.html#temporarily-disabling-tests

@@ -401,6 +401,29 @@ TEST(TimeParsing, TestConditionalRestrictions) {
TryConditionalRestrictions(conditions.at(x), 0, 1, 64, 3, 3, 0, 15, 0, 12, 1, 5, 17, 0);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to test wrongly formatted restriction...eg: end day is set without a corresponding start day (-Friday or some such)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for me it sounds as incorrect input. In case only day_on is specified, '-' is not added, day_on can be a sequence of days separated by a comma or a range with '-' inside. When only day_off is specified it is harder to understand what it means: working hours are from Monday/Sunday to X, or each day except X....?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, in that the input is incorrect. My point was that we should test that such inputs are ignored (looking at the code, we only set the condition when day_start is set, so just having a day_end should not enable the TR). So adding a test with incorrect input and showing that it does not take effect would be sufficient. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, added regular and gurka tests.

Copy link
Member

Choose a reason for hiding this comment

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

@CuriOusQuOkka @mandeepsandhu if we have only the start day set then these restrictions should be tossed as the user entered the info incorrectly

CHANGELOG.md Outdated
@@ -52,6 +52,7 @@
* FIXED: Removed unexpected maneuvers at sharp bends [#2968](https://github.com/valhalla/valhalla/pull/2968)
* FIXED: Remove large number formatting for non-US countries [#3015](https://github.com/valhalla/valhalla/pull/3015)
* FIXED: Odin undefined behaviour: handle case when xedgeuse is not initialized [#3020](https://github.com/valhalla/valhalla/pull/3020)
* FIXED: Fix time-dependent restrictions handling [#3029](https://github.com/valhalla/valhalla/pull/3029)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is too general description, I'd recommend to make it more specific

if (!day_start.empty() && !day_end.empty()) {
condition = day_start + '-' + day_end;
} else if (!day_start.empty()) {
condition = day_start;
Copy link
Contributor

Choose a reason for hiding this comment

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

so, just to clarify: if we have only day_start it means that restriction applies only on this day ? or to the end of the week ?

Copy link
Member

Choose a reason for hiding this comment

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

@genadz we can't only have just a day_start. if the restriction is only one day the day_start would be equal to the day_end.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gknisely from the code above it looks like just having day_start is also a valid option. If both start & end are mandatory, then maybe we should just have if (!day_start.empty() && !day_end.empty()) { ...} ?

Copy link
Member

Choose a reason for hiding this comment

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

@mandeepsandhu correct.

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 support start date that stays alone. It can be a sequence (like Monday,Wednesday,Thursday), a range (Monday-Friday), or just one day.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

read the comment form @gknisely. Ignore this case.

};
gurka::map TimeDependentRestrictions::map = {};

// TODO: Does not work for date_time_type=2, returns additional AB edge.
Copy link
Contributor

Choose a reason for hiding this comment

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

it's because of this #2940 ; try to put start and end locations on the edges

          D----B---1-A
          |    |
          |    |
          E----C---2-F

Copy link
Contributor

Choose a reason for hiding this comment

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

@genadz since date_time: 2 uses timedep-reverse, I wonder if the extra edge is being returned due to the bug @danpat found here.

@CuriOusQuOkka #2987 fixed a bug in timedep-reverse, which might fix the problem you're seeing. If so, you can re-enable date_time: 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @mandeepsandhu, it fixed the bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

@genadz since date_time: 2 uses timedep-reverse, I wonder if the extra edge is being returned due to the bug @danpat found here.

cool! so, I should close this issue #2940

@CuriOusQuOkka CuriOusQuOkka force-pushed the time_dependent_restrictions branch 2 times, most recently from 85c6ad1 to cc3af61 Compare April 26, 2021 17:48
@mandeepsandhu
Copy link
Contributor

@CuriOusQuOkka do you want to remove the "Draft" tag from this PR (thats a signal to reviewers to start looking at the changes more closely)?

@CuriOusQuOkka CuriOusQuOkka force-pushed the time_dependent_restrictions branch 3 times, most recently from 0b9c86d to 7a95f68 Compare April 26, 2021 21:09
@CuriOusQuOkka CuriOusQuOkka marked this pull request as ready for review April 26, 2021 21:14
}

TEST_F(TimeDependentTags, IgnoreDayOffOnlyRestriction) {
tags day_off = {
Copy link
Contributor

Choose a reason for hiding this comment

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

if I understood correctly having only day_on or hour_off/hour_on also should be ignored. could you add all these cases ?

@CuriOusQuOkka CuriOusQuOkka force-pushed the time_dependent_restrictions branch 2 times, most recently from dd6690d to e0aec94 Compare April 27, 2021 10:54
@gknisely
Copy link
Member

{"/date_time/value", "2021-04-02T23:00"}});
gurka::assert::raw::expect_path(result, {"AB", "BC", "CF"});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness, should we also add a testcase with date_time before start of restriction?

@CuriOusQuOkka CuriOusQuOkka force-pushed the time_dependent_restrictions branch 2 times, most recently from 5862a44 to 6a95605 Compare April 29, 2021 11:08
@CuriOusQuOkka
Copy link
Contributor Author

@CuriOusQuOkka CuriOusQuOkka merged commit 01ca643 into valhalla:master Apr 29, 2021
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

5 participants