Skip to content

Commit

Permalink
Replace time formatting function with equivalent dependency (#169)
Browse files Browse the repository at this point in the history
* replace time formatting funcion with equivalent dependency

* bump installed version, update function name, specify precision
  • Loading branch information
Nate-Wessel authored Dec 13, 2024
1 parent 4603fd2 commit 3610a4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
17 changes: 5 additions & 12 deletions backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from app.db import getConnection
from app.get_here_links import get_here_links
from app.selectMapVersion import selectMapVersion
from traveltimetools.utils import timeFormats
import numpy
import math
import pandas
Expand All @@ -19,14 +20,6 @@ def mean_daily_mean(obs):
# average the days together
return numpy.mean(daily_means)

def timeFormat(seconds):
return {
'seconds': round(seconds,3),
'minutes': round(seconds/60,3),
# format travel times in seconds like a clock for humans to read
'clock': f'{math.floor(seconds/3600):02d}:{math.floor((seconds/60)%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):
"""Function for returning data from the aggregate-travel-times/ endpoint"""

Expand Down Expand Up @@ -145,19 +138,19 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
p95lower, p95upper = numpy.percentile(sample_distribution, [2.5, 97.5])
reported_intervals = {
'p=0.95': {
'lower': timeFormat(p95lower),
'upper': timeFormat(p95upper)
'lower': timeFormats(p95lower,1),
'upper': timeFormats(p95upper,1)
}
}

return {
'results': {
'travel_time': timeFormat(tt_seconds),
'travel_time': timeFormats(tt_seconds,1),
'confidence': {
'sample': len(sample),
'intervals': reported_intervals
},
'observations': [timeFormat(tt) for (dt,tt) in sample]
'observations': [timeFormats(tt,1) for (dt,tt) in sample]
},
'query': {
'corridor': {'links': links, 'map_version': map_version},
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ packaging==20.7
pandas==2.2.2
psycopg==3.1.18
python-dotenv==0.15.0
numpy==1.26.0
numpy==1.26.0
git+ssh://[email protected]/Toronto-Big-Data-Innovation-Team/[email protected]

0 comments on commit 3610a4e

Please sign in to comment.