From 13efba0aaa760b17eae93e371e39edaeafe6a16e Mon Sep 17 00:00:00 2001 From: Nate-Wessel Date: Thu, 12 Dec 2024 21:50:58 +0000 Subject: [PATCH 1/2] replace time formatting funcion with equivalent dependency --- backend/app/get_travel_time.py | 9 +-------- backend/requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/backend/app/get_travel_time.py b/backend/app/get_travel_time.py index c5982de..9ae2eb2 100644 --- a/backend/app/get_travel_time.py +++ b/backend/app/get_travel_time.py @@ -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 timeFormat import numpy import math import pandas @@ -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""" diff --git a/backend/requirements.txt b/backend/requirements.txt index bd39afc..f68426d 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -6,4 +6,5 @@ packaging==20.7 pandas==2.2.2 psycopg==3.1.18 python-dotenv==0.15.0 -numpy==1.26.0 \ No newline at end of file +numpy==1.26.0 +git+ssh://git@github.com/Toronto-Big-Data-Innovation-Team/traveltimetools.git@7e4fc23 \ No newline at end of file From 285cb6fea4692cea4f64506202b4f4123d819227 Mon Sep 17 00:00:00 2001 From: Nate-Wessel Date: Fri, 13 Dec 2024 17:18:52 +0000 Subject: [PATCH 2/2] bump installed version, update function name, specify precision --- backend/app/get_travel_time.py | 10 +++++----- backend/requirements.txt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/app/get_travel_time.py b/backend/app/get_travel_time.py index 9ae2eb2..47c2072 100644 --- a/backend/app/get_travel_time.py +++ b/backend/app/get_travel_time.py @@ -3,7 +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 timeFormat +from traveltimetools.utils import timeFormats import numpy import math import pandas @@ -138,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}, diff --git a/backend/requirements.txt b/backend/requirements.txt index f68426d..2177ad6 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -7,4 +7,4 @@ pandas==2.2.2 psycopg==3.1.18 python-dotenv==0.15.0 numpy==1.26.0 -git+ssh://git@github.com/Toronto-Big-Data-Innovation-Team/traveltimetools.git@7e4fc23 \ No newline at end of file +git+ssh://git@github.com/Toronto-Big-Data-Innovation-Team/traveltimetools.git@v1.0.0 \ No newline at end of file