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

Ensure JSON returns correct data types, correctly escaped #81

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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