From 053f2c5a180ce662e73c93d1c41e681d18bfc362 Mon Sep 17 00:00:00 2001 From: Devin Matte Date: Wed, 5 Jun 2024 17:48:57 -0400 Subject: [PATCH] Remove initial data --- server/chalicelib/initial_data.py | 64 ------------------------------- src/hooks/useMbtaApi.ts | 1 - src/initialData.js | 7 ---- 3 files changed, 72 deletions(-) delete mode 100644 server/chalicelib/initial_data.py delete mode 100644 src/initialData.js diff --git a/server/chalicelib/initial_data.py b/server/chalicelib/initial_data.py deleted file mode 100644 index 0573def..0000000 --- a/server/chalicelib/initial_data.py +++ /dev/null @@ -1,64 +0,0 @@ -import asyncio -import subprocess -from chalicelib.mbta_api import routes_info, vehicle_data_for_routes, stops_for_route -from chalicelib.last_seen import get_recent_sightings_for_lines -from chalicelib.util import filter_new, filter_old, filter_route - - -def get_git_tag(): - return str(subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]))[2:-3] - - -def calc_stats(vehicle_array): - totalGreen = filter_route("Green", vehicle_array) - totalOrange = filter_route("Orange", vehicle_array) - totalRed = filter_route("Red", vehicle_array) - totalBlue = filter_route("Blue", vehicle_array) - - # intialize dictionary of stats - vehicle_stats = { - "Green": { - "totalActive": len(totalGreen), - "totalNew": len(filter_new(totalGreen)), - "totalOld": len(filter_old(totalGreen)), - }, - "Orange": { - "totalActive": len(totalOrange), - "totalNew": len(filter_new(totalOrange)), - "totalOld": len(filter_old(totalOrange)), - }, - "Red": { - "totalActive": len(totalRed), - "totalNew": len(filter_new(totalRed)), - "totalOld": len(filter_old(totalRed)), - }, - "Blue": { - "totalActive": len(totalBlue), - "totalNew": len(filter_new(totalBlue)), - "totalOld": len(filter_old(totalBlue)), - }, - } - - return vehicle_stats - - -# captures initial request data from MBTA API as well as server-side data such as git tags and static train data -# returns JSON of all data -async def initial_request_data(route_ids): - routes, vehicle_data, *stops = await asyncio.gather( - *[ - routes_info(route_ids), - vehicle_data_for_routes(route_ids), - *[stops_for_route(route_id) for route_id in route_ids], - ] - ) - sightings = get_recent_sightings_for_lines() - git_tag = get_git_tag() - return { - "version": git_tag, - "sightings": sightings, - "routes": routes, - "vehicles": vehicle_data, - "vehicle_stats": calc_stats(vehicle_data), - "stops": dict(zip(route_ids, stops)), - } diff --git a/src/hooks/useMbtaApi.ts b/src/hooks/useMbtaApi.ts index 81ed05c..a055d0d 100644 --- a/src/hooks/useMbtaApi.ts +++ b/src/hooks/useMbtaApi.ts @@ -1,6 +1,5 @@ /* File that contains a React hook that provides data from the MBTA API -Provides the __NTT_INITIAL_DATA__ JSON blob that is embedded in the initial server response */ import { useEffect, useState, useCallback } from 'react'; diff --git a/src/initialData.js b/src/initialData.js deleted file mode 100644 index 6ce1f17..0000000 --- a/src/initialData.js +++ /dev/null @@ -1,7 +0,0 @@ -export const getInitialDataByKey = (key) => { - const { __NTT_INITIAL_DATA__ } = window; - if (__NTT_INITIAL_DATA__ && __NTT_INITIAL_DATA__[key]) { - return __NTT_INITIAL_DATA__[key]; - } - return null; -};