Skip to content

Commit

Permalink
standardise time output
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed May 2, 2024
1 parent 82f57b4 commit 0e3b474
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ def mean_daily_mean(obs):
def mean_hourly(obs):
return numpy.mean([tt for (dt,tt) in obs])

# format travel times in seconds like a clock for humans to read
def secs2clock(seconds):
return f'{math.floor(seconds/3600):02d}:{math.floor(seconds/60):02d}:{round(seconds%60):02d}'
def timeFormat(seconds):
return {
'seconds': seconds,
'minutes': seconds / 60,
# format travel times in seconds like a clock for humans to read
'clock': f'{math.floor(seconds/3600):02d}:{math.floor(seconds/60):02d}:{round(seconds%60):02d}'
}

def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_date, include_holidays, dow_list):

Expand Down Expand Up @@ -84,36 +88,24 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
)

return {
'travel_time': {
'seconds': tt_seconds,
'minutes': tt_seconds / 60,
'clock': secs2clock(tt_seconds),
'results': {
'travel_time': timeFormat(tt_seconds),
'confidence': {
'sample': len(sample),
'intervals': {
'p=0.9': {
'lower': {
'seconds': p90lower,
'clock': secs2clock(p90lower)
},
'upper': {
'seconds': p90upper,
'clock': secs2clock(p90upper)
}
'lower': timeFormat(p90lower),
'upper': timeFormat(p90upper)
},
'p=0.95': {
'lower': {
'seconds': p95lower,
'clock': secs2clock(p95lower)
},
'upper': {
'seconds': p95upper,
'clock': secs2clock(p95upper)
}
'lower': timeFormat(p95lower),
'upper': timeFormat(p95upper)
}
}
}
},
'links': links,
'query_params': query_params,
'corridor':{
'links': links
},
'query_params': query_params
}

0 comments on commit 0e3b474

Please sign in to comment.