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

Fixed neighborhood name commas breaking csv formatting #3392

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

davphan
Copy link
Collaborator

@davphan davphan commented Sep 27, 2023

Resolves #3390

Neighborhood names containing commas would break the CSV file formatting, acting as an unintended delimiter. This PR adds double quotes around each instance of neighborhood names being referenced in CSV files, namely in these API calls:

  • /v2/access/attributes
  • /v2/access/attributesWithLabels
  • /v2/access/score/neighborhoods
Before/After screenshots (if applicable)

Before:
image

After:
image

Testing instructions
  1. Check the Label Map to find the coordinates of an area populated with labels. Choose a min/max lat and min/max long.
  2. Use this URL to fetch the csv file from the API:
  1. View the downloaded CSV. Make sure the Neighborhood Name column is correct and that subsequent columns are in the right spot
     
Things to check before submitting the PR
  • I've written a descriptive PR title.
  • I've added/updated comments for large or confusing blocks of code.
  • I've included before/after screenshots above.

@@ -147,7 +147,9 @@ class ProjectSidewalkAPIController @Inject()(implicit val env: Environment[User,
writer.println(header)
// Write each row in the CSV.
for (current <- GlobalAttributeTable.getGlobalAttributesWithLabelsInBoundingBox(minLat, minLng, maxLat, maxLng, severity)) {
writer.println(current.attributesToArray.mkString(","))
val rowArr: Array[String] = current.attributesToArray
rowArr(6) = "\"" + rowArr(6) + "\""
Copy link
Member

Choose a reason for hiding this comment

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

Let's try our best not to rely on knowing which index in the array to use for the neighborhood name. Is there a more programmatic way that we can do it, like adding the quotes in the attributesToArray method?

@davphan
Copy link
Collaborator Author

davphan commented Oct 1, 2023

@misaugstad Adjusted the commit to add quotes through the attributesToArray methods, everything's been tested again the same way!

Copy link
Member

@misaugstad misaugstad left a comment

Choose a reason for hiding this comment

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

Perfect, thank you!

@misaugstad misaugstad merged commit 08dcc06 into develop Oct 4, 2023
@misaugstad misaugstad deleted the 3390-neighborhood-csv-error branch October 4, 2023 20:46
@misaugstad misaugstad mentioned this pull request Nov 1, 2023
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.

APIs not dealing with neighborhoods with commas in CSV format
2 participants