From c2a3115a7a38136f7fe3af70ff5fccb1480f6b17 Mon Sep 17 00:00:00 2001 From: "asz33@cornell.edu" Date: Fri, 28 Aug 2020 10:29:31 -0700 Subject: [PATCH 1/2] Strip date of milliseconds to fix 4:07 error --- docker-compose.yml | 4 ++-- docker-compose/ghopper/Dockerfile | 2 +- src/utils/ParseRouteUtils.js | 29 ++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 67f825b4..a8806add 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: - /usr/src/app/node_modules ghopper: - image: cornellappdev/transit-ghopper:v1.2.1 + image: cornellappdev/transit-ghopper:v1.2.6 ports: - "8988:8988" @@ -28,7 +28,7 @@ services: - "8987:8987" live-tracking: - image: cornellappdev/transit-python:v1.2.2 + image: cornellappdev/transit-python:v1.2.6 env_file: python.envrc ports: - "5000:5000" diff --git a/docker-compose/ghopper/Dockerfile b/docker-compose/ghopper/Dockerfile index 1ca620a9..315acf50 100644 --- a/docker-compose/ghopper/Dockerfile +++ b/docker-compose/ghopper/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update RUN apt-get -y install maven wget RUN git clone --single-branch -b 0.13 https://github.com/graphhopper/graphhopper.git -RUN wget https://s3.amazonaws.com/tcat-gtfs/tcat-ny-us.zip +COPY tcat-ny-us.zip /usr/src/app/tcat-ny-us.zip WORKDIR /usr/src/app/graphhopper RUN ./graphhopper.sh build diff --git a/src/utils/ParseRouteUtils.js b/src/utils/ParseRouteUtils.js index 39a55eab..21e96e78 100644 --- a/src/utils/ParseRouteUtils.js +++ b/src/utils/ParseRouteUtils.js @@ -429,6 +429,28 @@ function parseWalkingRoute( } } +/** + * Ensure that the route times are in this format: "2020-08-27T23:11:58Z". + * Sometimes, we will get dates in the format of "2020-08-27T23:11:58.741+0000" + * and if this is the case, strip the milliseconds off. Otherwise, return the + * date we were given. + * @param date + * @returns formatted date string + */ +function formatDate( + date: string, +): string { + if (date) { + const dateBeforeMs = date.split('.')[0]; + if (date === dateBeforeMs) { + // date already does not have milliseconds + return date; + } + return `${date.split('.')[0]}Z`; + } + return date; +} + /** * Transform route object from graphhopper into one readable by the client, an array of * five routes. Includes delay calculations, asynchronous. @@ -469,7 +491,8 @@ function parseRoutes( // string 2018-02-21T17:27:00Z let { departureTime } = legs[0]; - let arriveTime = legs[numberOfLegs - 1].arrivalTime; + departureTime = formatDate(departureTime); + let arriveTime = formatDate(legs[numberOfLegs - 1].arrivalTime); // Readjust the walking start and end times by accounting for the buffer // times that were initially passed into Graphhopper to get routes @@ -497,8 +520,8 @@ function parseRoutes( const directions = await Promise.all(legs.map(async (currLeg, j, legsArray) => { let { type } = currLeg; - let startTime = currLeg.departureTime; - let endTime = currLeg.arrivalTime; + let startTime = formatDate(currLeg.departureTime); + let endTime = formatDate(currLeg.arrivalTime); if (busRoute.transfers === -1) { startTime = departureTime; From 4ca6ae1782f2fa531fb78bc01ee56762c00c87b1 Mon Sep 17 00:00:00 2001 From: "asz33@cornell.edu" Date: Fri, 28 Aug 2020 11:59:11 -0700 Subject: [PATCH 2/2] Refactor --- src/utils/ParseRouteUtils.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/ParseRouteUtils.js b/src/utils/ParseRouteUtils.js index 21e96e78..c45b2f50 100644 --- a/src/utils/ParseRouteUtils.js +++ b/src/utils/ParseRouteUtils.js @@ -437,16 +437,14 @@ function parseWalkingRoute( * @param date * @returns formatted date string */ -function formatDate( - date: string, -): string { +function formatDate(date: string): string { if (date) { const dateBeforeMs = date.split('.')[0]; if (date === dateBeforeMs) { // date already does not have milliseconds return date; } - return `${date.split('.')[0]}Z`; + return `${dateBeforeMs}Z`; } return date; }