Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MohamedM216
Copy link
Contributor

@MohamedM216 MohamedM216 commented Aug 25, 2025

Issue

This PR extends AttributesController to enable control over matrix serializer 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

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog
  • If you made changes to the lua files, update the taginfo too
  • If you made changes to a translation file, update transifex too

Requirements / Relations

#5063

@kevinkreiser
Copy link
Member

dont forget to make a similar docs segment in the matrix docs to explain the different fields

@MohamedM216
Copy link
Contributor Author

Ah, right. I completely forgot about that. I’ll make sure to add it.

@MohamedM216
Copy link
Contributor Author

@kevinkreiser I have updated the docs. Addressed here a43e76d

@MohamedM216
Copy link
Contributor Author

Hi @kevinkreiser , just following up on this PR. Whenever you have time to review would be great. Thanks!

{kMatrixConnectionDateTime, true},
{kMatrixConnectionTimeZoneOffset, true},
{kMatrixConnectionTimeZoneName, true},
{kMatrixConnectionShape, true},
Copy link
Member

Choose a reason for hiding this comment

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

the default for shape should probably be false


writer.set_precision(tyr::kDefaultPrecision);
if (matrix.shapes().size() && shape_format != no_shape) {
if (controller(kMatrixConnectionShape) && matrix.shapes().size() && shape_format != no_shape) {
Copy link
Member

Choose a reason for hiding this comment

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

...and then this should be

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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?

writer.end_array();

if (!(options.shape_format() == no_shape ||
if (controller(kMatrixConnectionShape) &&
Copy link
Member

Choose a reason for hiding this comment

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

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);
Copy link
Member

Choose a reason for hiding this comment

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

can you add some tests either here or the gurka matrix one that checks the JSON response?

Copy link
Member

@chrstnbwnkl chrstnbwnkl left a comment

Choose a reason for hiding this comment

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

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.

@kinkard
Copy link
Member

kinkard commented Oct 1, 2025

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) {
Copy link
Contributor Author

@MohamedM216 MohamedM216 Oct 5, 2025

Choose a reason for hiding this comment

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

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.

Comment on lines +284 to +285
if ((controller(kMatrixConnectionShape) || options.shape_format() != no_shape) &&
request.matrix().algorithm() == Matrix::CostMatrix) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This condition.

@MohamedM216
Copy link
Contributor Author

Hi @chrstnbwnkl , just following up. Whenever you have time to review would be great.

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.

4 participants