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

Route Alerts Refinement #506

Merged
merged 15 commits into from
Dec 10, 2020
Merged

Route Alerts Refinement #506

merged 15 commits into from
Dec 10, 2020

Conversation

Udumft
Copy link
Contributor

@Udumft Udumft commented Dec 2, 2020

Prepares Route Alerts related types for public usage.

This PR refines Docs for number of entities and properties, modifies Incident struct. For the latter I used info provided by Directions team in slack convo and existing Valhalla schema.

Fixes #482.

@Udumft Udumft added the op-ex Refactoring, Tech Debt or any other operational excellence work. label Dec 2, 2020
@Udumft Udumft self-assigned this Dec 2, 2020
@Udumft Udumft marked this pull request as ready for review December 2, 2020 16:36
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

If you have time, it would be great to include a basic encoding/decoding unit test to ensure that the Incident type and its dependent types all round-trip in the usual case. I realize the tests were missing from #466, but any (justified) departure from the JSON format increases the risk of a roundtripping issue.

Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Comment on lines 67 to 68
/// A list of lane indices, affected by the incident
public var lanesBlocked: [Int]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these indices consistent with the indices in Intersection.approachLanes? If so, let’s mention it in this documentation comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the schema, these are not consistent with approach lanes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end I decided to introduce an enum to ease handling these. It is unlikely that humanity invents new types of lanes, but I still left a place to avoid crashing once naming is updated. Even NN does not trust this list to be static.
Unfortunately this is not compatible with LaneIndication we use in Intersections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or am I overthinking it introducing rawLanesBlocked?

Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/RestStop.swift Show resolved Hide resolved
@Udumft Udumft requested a review from 1ec5 December 4, 2020 13:35
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Comment on lines 57 to 66
case Lane1 = "1"
case Lane2 = "2"
case Lane3 = "3"
case Lane4 = "4"
case Lane5 = "5"
case Lane6 = "6"
case Lane7 = "7"
case Lane8 = "8"
case Lane9 = "9"
case Lane10 = "10"
Copy link
Contributor

Choose a reason for hiding this comment

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

For the documentation comments for these cases, let’s say e.g. “Second lane from the left”, assuming that’s what lane2 means even in a region that drives on the left.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't "Lane1" means the leftmost lane for Left Driving Side regions and the rightmost lane for Right Driving Side regions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was assuming the numbering follows the California standard, but other regions may number the lanes differently, so maybe we need to be ambiguous for now.

Copy link
Contributor

@1ec5 1ec5 Dec 7, 2020

Choose a reason for hiding this comment

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

The National Traffic Information Management Coalition, which is affiliated with AASHTO in the U.S., has been recommending the California lane numbering scheme for use nationwide. Michigan and Ohio have both officially adopted it for TIMs.

let formatter = ISO8601DateFormatter()

try container.encode(identifier, forKey: .identifier)
try container.encode(rawKind, forKey: .type)
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 need a separate rawKind property? I think we can make Kind conform to Codable and it’ll automatically be possible to replace rawKind with kind here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rawKind is introduced to preserve JSON encoding/decoding roundtrip for cases when current SDK version does not support new types of Incidents. Thus, we just store the raw value for coding purposes, and at the same time user is enabled to work only with known defined Kinds.

Same approach applied to BlockedLane, but IMHO it is less likely that new types of lanes could be introduced then new types of incidents. So I would rather agree that we should get rid of rawLanesBlocked instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid parallel properties, we should store only the raw value and make the enumeration-typed property a computed property.

Sources/MapboxDirections/Incident.swift Show resolved Hide resolved
@1ec5 1ec5 added this to the v1.2.0 milestone Dec 4, 2020
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Comment on lines 48 to 49
/// Left and center lanes
case leftCenter = "LEFT CENTER"
Copy link
Contributor

Choose a reason for hiding this comment

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

According to this presentation (slide 11), traffic information management (TIM) systems in the U.S. use “left center lane” to refer to the second lane from left on a four-lane highway:

Note that this slide isn’t globally applicable: for example, inside and outside would be reversed in everyday speech in Taiwan. But I don’t know if that would affect the incident data we get.

Comment on lines 57 to 66
case Lane1 = "1"
case Lane2 = "2"
case Lane3 = "3"
case Lane4 = "4"
case Lane5 = "5"
case Lane6 = "6"
case Lane7 = "7"
case Lane8 = "8"
case Lane9 = "9"
case Lane10 = "10"
Copy link
Contributor

@1ec5 1ec5 Dec 7, 2020

Choose a reason for hiding this comment

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

The National Traffic Information Management Coalition, which is affiliated with AASHTO in the U.S., has been recommending the California lane numbering scheme for use nationwide. Michigan and Ohio have both officially adopted it for TIMs.

@Udumft Udumft requested a review from 1ec5 December 8, 2020 15:47
import Foundation

/// Defines a lane affected by the `Incident`
public struct BlockedLanes: OptionSet, CustomStringConvertible {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh cool, thanks for taking care of turning this type into an option set.

Sources/MapboxDirections/Incident.swift Outdated Show resolved Hide resolved
Sources/MapboxDirections/RouteLeg.swift Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@Udumft Udumft requested a review from 1ec5 December 9, 2020 10:44
Comment on lines +59 to +62
public var kind: Kind? {
return Kind(rawValue: rawKind)
}
var rawKind: String
Copy link
Contributor

@1ec5 1ec5 Dec 10, 2020

Choose a reason for hiding this comment

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

Something for consideration before the final release: now that we’re writing in pure Swift, we could consolidate these two properties into a single kind property of type Kind, but one of the Kind cases could have an associated value with the raw type. This would in fact be an option for any enumeration that the Directions API reserves the right to extend, other than option sets. But until we go down that road, the separate rawKind property is appropriate.

@Udumft Udumft merged commit 9c1cc5a into main Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
op-ex Refactoring, Tech Debt or any other operational excellence work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine route alert types and properties for public consumption
2 participants