Skip to content

Commit

Permalink
Ensure JSON returns correct data types, correctly escaped (#81)
Browse files Browse the repository at this point in the history
* return numeric travel time (not string)

* double quote strings for CSV, not for JSON
  • Loading branch information
Nate-Wessel committed Oct 5, 2023
1 parent ecde318 commit 3d9c5a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def aggregate_travel_times(start_node, end_node, start_time, end_time, start_dat

connection.close()
return jsonify({
'travel_time': travel_time, # may be null if insufficient data
'travel_time': float(travel_time), # may be null if insufficient data
'route_text': stname,
'links': links
})
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/travelTimeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,25 @@ export class TravelTimeQuery {
resultsRecord(type='json'){
const record = {
URI: this.URI,
corridor: `"${this.corridor.name}"`,
timeRange: `"${this.timeRange.name}"`,
dateRange: `"${this.dateRange.name}"`,
daysOfWeek: `"${this.days.name}"`,
corridor: this.corridor.name,
timeRange: this.timeRange.name,
dateRange: this.dateRange.name,
daysOfWeek: this.days.name,
hoursInRange: this.hoursInRange,
mean_travel_time_minutes: this.#travelTime
}
if(type=='json'){
return record
}else if(type=='csv'){
return Object.values(record).join(',')
return Object.values(record)
.map( value => {

if(typeof value == 'string'){
return `"${value}"`
}
return value
} )
.join(',')
}
return 'invalid type requested'
}
Expand Down

0 comments on commit 3d9c5a7

Please sign in to comment.