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

Replace time formatting function with equivalent dependency #169

Merged
merged 2 commits into from
Dec 13, 2024
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
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]
Loading