feat: add attribute controller support for matrix responses#5471
feat: add attribute controller support for matrix responses#5471MohamedM216 wants to merge 12 commits intovalhalla:masterfrom
Conversation
…troller to functions signatures
|
dont forget to make a similar docs segment in the matrix docs to explain the different fields |
|
Ah, right. I completely forgot about that. I’ll make sure to add it. |
|
@kevinkreiser I have updated the docs. Addressed here a43e76d |
|
Hi @kevinkreiser , just following up on this PR. Whenever you have time to review would be great. Thanks! |
src/baldr/attributes_controller.cc
Outdated
| {kMatrixConnectionDateTime, true}, | ||
| {kMatrixConnectionTimeZoneOffset, true}, | ||
| {kMatrixConnectionTimeZoneName, true}, | ||
| {kMatrixConnectionShape, true}, |
There was a problem hiding this comment.
the default for shape should probably be false
src/tyr/matrix_serializer.cc
Outdated
|
|
||
| writer.set_precision(tyr::kDefaultPrecision); | ||
| if (matrix.shapes().size() && shape_format != no_shape) { | ||
| if (controller(kMatrixConnectionShape) && matrix.shapes().size() && shape_format != no_shape) { |
There was a problem hiding this comment.
...and then this should be
| if (controller(kMatrixConnectionShape) && matrix.shapes().size() && shape_format != no_shape) { | |
| if (matrix.shapes().size() && (controller(kMatrixConnectionShape) || shape_format != no_shape)) { |
...and you need to add a similar check in the part that decides whether to reserve space for shapes in the proto response.
There was a problem hiding this comment.
OK! From the changes you made, I understand that the idea is: if the user specifies any shape format other than no_shape, they probably want shapes in the response, even if they didn't explicitly enable the shape attribute in the controller. Right?
src/tyr/matrix_serializer.cc
Outdated
| writer.end_array(); | ||
|
|
||
| if (!(options.shape_format() == no_shape || | ||
| if (controller(kMatrixConnectionShape) && |
There was a problem hiding this comment.
adjust the check here as well to accommodate the fact that kMatrixConnectionShape is false by default
| TimeDistanceMatrix timedist_matrix; | ||
| timedist_matrix.SourceToTarget(request, reader, mode_costing, sif::TravelMode::kDrive, 400000.0); | ||
| json_res = tyr::serializeMatrix(request); | ||
| json_res = tyr::serializeMatrix(request, controller); |
There was a problem hiding this comment.
can you add some tests either here or the gurka matrix one that checks the JSON response?
chrstnbwnkl
left a comment
There was a problem hiding this comment.
Actually, I just realized that this just filters the JSON response, but we should probably apply this filter on the proto level already? Right now for example, the shapes may be needlessly added to the proto response and then discarded by the filter when converting to JSON.
Then this feature will work for PBF response format as well and I'm just not sure that it is something worth effort and contract (all PBF object fields are filled) change. Especially taken that PBF is already size efficient enough. |
| << response << "\n\n"; | ||
| } | ||
|
|
||
| TEST(Matrix, shape_controller_explicit_include) { |
There was a problem hiding this comment.
This one fails. I think the reason behind this is this condition [see below]
The json response:
{"sources_to_targets":[[{"from_index":0,"to_index":0,"time":473,"distance":5.88,"begin_heading":168.6,"end_heading":216.5,"begin_lat":52.103943,"begin_lon":5.068089,"end_lat":52.106118,"end_lon":5.101512},{"from_index":0,"to_index":1,"time":393,"distance":4.309,"begin_heading":168.6,"end_heading":276.0,"begin_lat":52.103943,"begin_lon":5.068089,"end_lat":52.100476,"end_lon":5.087027}]],"sources":[{"lat":52.103943,"lon":5.068089}],"targets":[{"lat":52.106118,"lon":5.101512},{"lat":52.100476,"lon":5.087027}],"units":"kilometers","algorithm":"costmatrix"}I would appreciate your guidance on this.
| if ((controller(kMatrixConnectionShape) || options.shape_format() != no_shape) && | ||
| request.matrix().algorithm() == Matrix::CostMatrix) { |
|
Hi @chrstnbwnkl , just following up. Whenever you have time to review would be great. |
Issue
This PR extends
AttributesControllerto enable control overmatrixserializer attributes to avoid parameter cluttering in case new pieces of information for a matrix connection are added in the future as described here #5063.Tasklist
Requirements / Relations
#5063