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

Calculate travel time standard deviations #161

Draft
wants to merge 5 commits into
base: min-bins
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions frontend/src/corridor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class Corridor extends Factor {
}
get segments(){ return this.#segments }
get links(){ return this.segments.flatMap( seg => seg.links ) }
get length_in_meters(){
return this.links.reduce((cs,link)=>cs+link.length_m, 0)
}
get viaStreets(){
return new Set( this.links.map( link => link.name ) )
}
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/travelTimeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,21 @@ export class TravelTimeQuery {
this.holidaysAreRelevant ? this.#holidayOption.holidaysIncluded : 'NA'
)
record.set('hoursInRange', this.hoursInRange)
record.set('mean_travel_time_minutes', this.#results?.travel_time?.minutes)
record.set('mean_travel_time_seconds', this.#results?.travel_time?.seconds)
// get the standard deviation of the travel time observations
// start by calculating the mean again, separately
// this is because the tt means we use aren't straight averages, for historical reasons
let sum_obs = this.#results.observations.reduce((cumsum, tt) => {
return cumsum + tt.seconds
}, 0)
let mean_obs = sum_obs / this.#results.observations.length
record.set('mean_travel_time_seconds', mean_obs)
// sum of the squared deviations from the mean
let sum_sq_dev = this.#results.observations.reduce((cumsum, tt) => {
return cumsum + (mean_obs - tt.seconds)**2
}, 0)
let sample_variance = sum_sq_dev / (this.#results.observations.length - 1)
record.set('tt_sd_seconds', Math.sqrt(sample_variance))
record.set('length_in_meters', this.corridor.length_in_meters)
// turning these off in the frontend until they're ready for production
//record.set('moe_lower_p95', this.#results?.confidence?.intervals?.['p=0.95']?.lower?.seconds)
//record.set('moe_upper_p95', this.#results?.confidence?.intervals?.['p=0.95']?.upper?.seconds)
Expand Down