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

Commuter rail in Data Dashboard #898

Draft
wants to merge 68 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7acd7c5
Using Gobble data
devinmatte Dec 17, 2023
06fda87
Adding commuter rail data to data dashboard
devinmatte Dec 18, 2023
de039bd
Merge remote-tracking branch 'origin/main' into gobble-data
devinmatte Dec 18, 2023
a378dc4
Merge branch 'main' into gobble-data
devinmatte Dec 20, 2023
f361981
Merge branch 'main' into gobble-data
devinmatte Dec 20, 2023
74ce70a
Treat bus the same as rapid for dates
devinmatte Dec 20, 2023
02cb728
Merge branch 'main' into commuter-rail-in-dd
devinmatte Dec 21, 2023
75c60ab
Better if statement
devinmatte Dec 22, 2023
aa40939
Handle date formats with timezones
devinmatte Dec 22, 2023
30ddd1f
Renaming date_utils
devinmatte Dec 22, 2023
a122a88
Cleanup imports
devinmatte Dec 22, 2023
6751998
Merge branch 'main' into gobble-data
devinmatte Dec 22, 2023
9532a70
Inject timezone into non-timezone datestamps
devinmatte Dec 22, 2023
5bb67e6
Merge branch 'gobble-data' into commuter-rail-in-dd
devinmatte Dec 22, 2023
ee77537
Set minimum commuter rail date
devinmatte Dec 22, 2023
4577978
Adding some initial platform ids
devinmatte Dec 22, 2023
d137236
Adding lowell line platform ids
devinmatte Dec 22, 2023
20c5eec
Properly fetching CR stations
devinmatte Dec 22, 2023
3a89a12
Acutally fetching CR data
devinmatte Dec 23, 2023
a8ed493
Adding franklin line ids
devinmatte Dec 23, 2023
94b1f5a
Populating stations
devinmatte Dec 23, 2023
b23874e
Adding more lines
devinmatte Dec 26, 2023
90443ff
Adding Haverhill stops
devinmatte Dec 26, 2023
43db5e0
Updating min dates
devinmatte Dec 26, 2023
772d10e
Adding more lines and better stop population
devinmatte Dec 26, 2023
8552827
Clean up scripts
devinmatte Dec 26, 2023
5917d97
Allowing commuter rail ridership fetching
devinmatte Dec 27, 2023
abb331c
Merge branch 'main' into commuter-rail-in-dd
devinmatte Dec 27, 2023
e17b392
Updating line files
devinmatte Dec 27, 2023
4f3f337
Adding more stop ids
devinmatte Dec 27, 2023
d223d02
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jan 1, 2024
8de71df
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jan 8, 2024
6a42b6d
Fixing bus typing
devinmatte Jan 8, 2024
078206f
Merge remote-tracking branch 'origin/main' into commuter-rail-in-dd
devinmatte Jan 9, 2024
7e4505f
Remove foxboro for now
devinmatte Jan 9, 2024
b69f386
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jan 11, 2024
b169555
Merge remote-tracking branch 'origin/main' into commuter-rail-in-dd
devinmatte Jan 11, 2024
8db9c46
Fix widget title import
devinmatte Jan 11, 2024
a094889
Merge remote-tracking branch 'origin/main' into commuter-rail-in-dd
devinmatte Jan 17, 2024
3b102e1
Updating CR line files
devinmatte Jan 17, 2024
d5913dd
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jan 20, 2024
35c5410
Hide stations we don't have stops for
devinmatte Jan 21, 2024
3101977
Nevermind
devinmatte Jan 21, 2024
c27a83e
Populate with newer stops
devinmatte Jan 21, 2024
93b5197
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jan 23, 2024
8b40dc5
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jan 30, 2024
631a5f0
Fixing CR data calls
devinmatte Feb 4, 2024
144a6f2
Merge branch 'main' into commuter-rail-in-dd
devinmatte Feb 10, 2024
6d6da82
Merge branch 'main' into commuter-rail-in-dd
devinmatte Feb 14, 2024
f722dde
Merge branch 'main' into commuter-rail-in-dd
devinmatte Feb 25, 2024
ef4c548
Merge branch 'main' into commuter-rail-in-dd
devinmatte Mar 9, 2024
8fb44d1
Fixing 120+ minute headways for CR
devinmatte Mar 10, 2024
634b983
Updating commuter rail stations and notices
devinmatte Mar 11, 2024
4810c36
Merge remote-tracking branch 'origin/main' into commuter-rail-in-dd
devinmatte May 17, 2024
7ce77b4
Fixing data fetching issues for cr
devinmatte May 17, 2024
d837b4c
Remove unused
devinmatte May 17, 2024
3b34d1b
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jun 18, 2024
e281387
Merge branch 'main' into commuter-rail-in-dd
devinmatte Jul 18, 2024
5ed4575
Adding commuter rail ridership to dashboard
devinmatte Jul 19, 2024
0272985
Fixing props
devinmatte Jul 19, 2024
6af58db
Adding commuter rail landing button
devinmatte Jul 19, 2024
0285525
Merge branch 'commuter-rail-ridership' into commuter-rail-in-dd
devinmatte Jul 19, 2024
c23d10f
Fixing commuter rail links
devinmatte Jul 19, 2024
cabcc80
Fix linting issues
devinmatte Jul 19, 2024
8389487
Merge remote-tracking branch 'origin/main' into commuter-rail-in-dd
devinmatte Jul 29, 2024
8b17144
Adding log retention policy
devinmatte Aug 1, 2024
3742ac3
Oops we'd need to delete the stack
devinmatte Aug 1, 2024
385f905
Okay nevermind
devinmatte Aug 1, 2024
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
8 changes: 8 additions & 0 deletions common/api/datadashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
parameters: SingleDayAPIOptions | AggregateAPIOptions,
aggregate: boolean,
enabled = true
): any => {

Check warning on line 105 in common/api/datadashboard.ts

View workflow job for this annotation

GitHub Actions / frontend (20, 3.11)

Unexpected any. Specify a different type
const queryTypes = QUERIES[busOrSubway];
const dependencies = aggregate ? aggregateQueryDependencies : singleDayQueryDependencies;
// Create objects with keys of query names which contains keys and parameters.
Expand Down Expand Up @@ -141,6 +141,14 @@
[QueryNameKeys.headways]: requests[1],
};
}

if (busOrSubway === 'cr') {
return {
[QueryNameKeys.traveltimes]: requests[0],
[QueryNameKeys.headways]: requests[1],
};
}

return {
[QueryNameKeys.traveltimes]: requests[0],
[QueryNameKeys.headways]: requests[1],
Expand Down
12 changes: 9 additions & 3 deletions common/components/controls/ControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import React from 'react';
import classNames from 'classnames';
import { lineColorBorder } from '../../styles/general';
import type { BusRoute, Line } from '../../types/lines';
import type { BusRoute, CommuterRailRoute, Line } from '../../types/lines';
import type { DateStoreSection } from '../../constants/pages';
import { StationSelectorWidget } from '../widgets/StationSelectorWidget';
import { DateControl } from './DateControl';

interface ControlPanelProps {
dateStoreSection: DateStoreSection;
busRoute: BusRoute | undefined;
crRoute: CommuterRailRoute | undefined;
line: Line | undefined;
}

export const ControlPanel: React.FC<ControlPanelProps> = ({ dateStoreSection, line, busRoute }) => {
export const ControlPanel: React.FC<ControlPanelProps> = ({
dateStoreSection,
line,
busRoute,
crRoute,
}) => {
const getControls = () => {
if ((dateStoreSection === 'singleTrips' || dateStoreSection === 'multiTrips') && line) {
return (
Expand All @@ -21,7 +27,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({ dateStoreSection, li
dateStoreSection={dateStoreSection}
queryType={dateStoreSection === 'singleTrips' ? 'single' : 'range'}
/>
<StationSelectorWidget line={line} busRoute={busRoute} />
<StationSelectorWidget line={line} busRoute={busRoute} crRoute={crRoute} />
</>
);
}
Expand Down
6 changes: 4 additions & 2 deletions common/components/controls/MobileControlPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import classNames from 'classnames';
import type { BusRoute, Line } from '../../types/lines';
import type { BusRoute, CommuterRailRoute, Line } from '../../types/lines';
import type { DateStoreSection } from '../../constants/pages';
import { lineColorBackground } from '../../styles/general';
import { StationSelectorWidget } from '../widgets/StationSelectorWidget';
Expand All @@ -9,13 +9,15 @@ import { DateControl } from './DateControl';
interface MobileControlPanelProps {
dateStoreSection: DateStoreSection;
busRoute: BusRoute | undefined;
crRoute: CommuterRailRoute | undefined;
line: Line | undefined;
}

export const MobileControlPanel: React.FC<MobileControlPanelProps> = ({
dateStoreSection,
line,
busRoute,
crRoute,
}) => {
const singleDate = dateStoreSection === 'singleTrips';
const getControls = () => {
Expand All @@ -34,7 +36,7 @@ export const MobileControlPanel: React.FC<MobileControlPanelProps> = ({
lineColorBackground[line ?? 'DEFAULT']
)}
>
<StationSelectorWidget line={line} busRoute={busRoute} />
<StationSelectorWidget line={line} busRoute={busRoute} crRoute={crRoute} />
</div>
</>
);
Expand Down
5 changes: 3 additions & 2 deletions common/components/inputs/StationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ export const StationSelector: React.FC<StationSelector> = ({
const {
line,
lineShort,
query: { busRoute },
query: { busRoute, crRoute },
} = useDelimitatedRoute();
const mdBreakpoint = useBreakpoint('md');
const station = type === 'from' ? fromStation : toStation;
const stationOptions = optionsForField(type, lineShort, fromStation, busRoute);
const stationOptions = optionsForField(type, lineShort, fromStation, busRoute, crRoute);
const branchLabelWidth = {
'line-red': 'w-8',
'line-green': 'w-12',
DEFAULT: 'w-0',
};

return (
<Listbox value={station} onChange={setStation}>
{({ open }) => (
Expand Down
22 changes: 12 additions & 10 deletions common/components/nav/CommuterRailRouteSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ import { ChevronUpDownIcon } from '@heroicons/react/20/solid';
import { useRouter } from 'next/navigation';
import React, { Fragment } from 'react';
import { getCommuterRailRoutes } from '../../constants/stations';
import { getBusRouteSelectionItemHref, useDelimitatedRoute } from '../../utils/router';
import { getCommuterRailRouteSelectionItemHref, useDelimitatedRoute } from '../../utils/router';
import { COMMUTER_RAIL_LINE_NAMES } from '../../types/lines';

// TODO: This is a duplicate of common/components/nav/BusRouteSelection.tsx
export const CommuterRailRouteSelection: React.FC = () => {
const route = useDelimitatedRoute();
const router = useRouter();
const crRoutes = getCommuterRailRoutes();
const selected = route.query.busRoute;
const selected = route.query.crRoute;

return (
<div className="bg-mbta-lightBus">
<div className="bg-mbta-lightCommuterRail">
<Listbox
value={selected}
onChange={(key) => router.push(getBusRouteSelectionItemHref(key, route))}
onChange={(key) => router.push(getCommuterRailRouteSelectionItemHref(key, route))}
>
<div className="relative text-white text-opacity-95">
<Listbox.Button className="relative w-full cursor-pointer border border-mbta-bus bg-tm-lightGrey py-2 pl-3 pr-10 text-left focus:outline-none focus-visible:border-indigo-500 focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2 focus-visible:ring-offset-orange-300 sm:text-sm">
<span className="block truncate ">{selected}</span>
<Listbox.Button className="relative w-full cursor-pointer border border-mbta-commuterRail bg-tm-lightGrey py-2 pl-3 pr-10 text-left focus:outline-none focus-visible:border-indigo-500 focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2 focus-visible:ring-offset-orange-300 sm:text-sm">
<span className="block truncate ">
{selected && COMMUTER_RAIL_LINE_NAMES[selected]}
</span>
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
<ChevronUpDownIcon className="h-5 w-5 " aria-hidden="true" />
</span>
Expand All @@ -39,7 +41,7 @@ export const CommuterRailRouteSelection: React.FC = () => {
key={personIdx}
className={({ active }) =>
`relative cursor-pointer select-none py-2 pl-10 pr-4 ${
active ? 'bg-amber-100 text-amber-900' : 'text-gray-900'
active ? 'bg-fuchsia-100 text-fuchsia-900' : 'text-gray-900'
}`
}
value={crRoute}
Expand All @@ -49,10 +51,10 @@ export const CommuterRailRouteSelection: React.FC = () => {
<span
className={`block truncate ${selected ? 'font-medium' : 'font-normal'}`}
>
{crRoute}
{COMMUTER_RAIL_LINE_NAMES[crRoute]}
</span>
{selected ? (
<span className="absolute inset-y-0 left-0 flex items-center pl-3 text-mbta-bus">
<span className="absolute inset-y-0 left-0 flex items-center pl-3 text-mbta-commuterRail">
<FontAwesomeIcon
icon={faCheckCircle}
className="h-5 w-5"
Expand Down
21 changes: 13 additions & 8 deletions common/components/nav/MenuDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'classnames';
import Link from 'next/link';
import React, { useEffect, useState } from 'react';
import { LINE_OBJECTS } from '../../constants/lines';
import { BUS_DEFAULTS } from '../../state/defaults/dateDefaults';
import { BUS_DEFAULTS, COMMUTER_RAIL_DEFAULTS } from '../../state/defaults/dateDefaults';
import { lineColorBackground } from '../../styles/general';
import type { Line } from '../../types/lines';
import type { Route } from '../../types/router';
Expand Down Expand Up @@ -38,15 +38,20 @@ export const MenuDropdown: React.FC<MenuDropdownProps> = ({ line, route, childre
}
}, [line]);

const href = React.useMemo(() => {
switch (line) {
case 'line-bus':
return `/bus/trips/single?busRoute=1&date=${BUS_DEFAULTS.singleTripConfig.date}`;
case 'line-commuter-rail':
return `/commuter-rail/trips/single?crRoute=CR-Lowell&date=${COMMUTER_RAIL_DEFAULTS.singleTripConfig.date}`;
default:
return getLineSelectionItemHref(line, route);
}
}, [line, route]);

return (
<div className={classNames('w-full')}>
<Link
href={
line === 'line-bus'
? `/bus/trips/single?busRoute=1&date=${BUS_DEFAULTS.singleTripConfig.date}`
: getLineSelectionItemHref(line, route)
}
>
<Link href={href}>
<div
className={classNames(
'flex w-full flex-row items-center gap-2 rounded-t-md py-1 pl-1 text-sm ',
Expand Down
10 changes: 0 additions & 10 deletions common/components/nav/NavSection.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions common/components/nav/NavSectionHeader.tsx

This file was deleted.

11 changes: 8 additions & 3 deletions common/components/widgets/StationSelectorWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ import {
optionsStation,
stopIdsForStations,
} from '../../utils/stations';
import type { BusRoute, Line } from '../../types/lines';
import type { BusRoute, CommuterRailRoute, Line } from '../../types/lines';
import { LINE_OBJECTS } from '../../constants/lines';
import type { Station } from '../../types/stations';

interface StationSelectorWidgetProps {
line: Line;
busRoute: BusRoute | undefined;
crRoute: CommuterRailRoute | undefined;
}

export const StationSelectorWidget: React.FC<StationSelectorWidgetProps> = ({ line, busRoute }) => {
export const StationSelectorWidget: React.FC<StationSelectorWidgetProps> = ({
line,
busRoute,
crRoute,
}) => {
const updateQueryParams = useUpdateQuery();
const lineShort = LINE_OBJECTS[line].short;
const {
query: { from, to },
} = useDelimitatedRoute();

const stations = optionsStation(lineShort, busRoute);
const stations = optionsStation(lineShort, busRoute, crRoute);
const toStation = to ? getParentStationForStopId(to) : stations?.[stations.length - 2];
const fromStation = from ? getParentStationForStopId(from) : stations?.[1];
React.useEffect(() => {
Expand Down
24 changes: 23 additions & 1 deletion common/constants/baselines.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { BusRoute, CommuterRailRoute, Line } from '../types/lines';

// These are manually chosen based off the peak *monthly* scheduled service. Selecting highest value "
export const PEAK_SCHEDULED_SERVICE = {
'line-red': 223,
Expand All @@ -17,7 +19,14 @@ export const PEAK_SPEED = {
};

// These are manually chosen based off the peak value. Need to be updated when all data is generated.
export const PEAK_RIDERSHIP = {
export const PEAK_RIDERSHIP: {
[key in
| Exclude<Line, 'line-bus' | 'line-commuter-rail'>
| Exclude<BusRoute, '114/116/117'>
| CommuterRailRoute
| '114116117'
| 'DEFAULT']: number;
} = {
'line-red': 213703,
'line-orange': 169578,
'line-blue': 60129,
Expand All @@ -36,6 +45,19 @@ export const PEAK_RIDERSHIP = {
'77': 8015,
'111': 11258,
'114116117': 12867,
'CR-Fitchburg': 0,
'CR-Franklin': 0,
'CR-Greenbush': 0,
'CR-Haverhill': 0,
'CR-Lowell': 0,
'CR-Foxboro': 0,
'CR-Worcester': 0,
'CR-Fairmount': 0,
'CR-Kingston': 0,
'CR-Middleborough': 0,
'CR-Needham': 0,
'CR-Newburyport': 0,
'CR-Providence': 0,
DEFAULT: 520580,
};

Expand Down
11 changes: 6 additions & 5 deletions common/constants/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export const CHART_COLORS = {
};

export const LINE_COLORS = {
'line-red': '#D13434',
'line-orange': '#ed8b00',
'line-blue': '#003da5',
'line-green': '#00834d',
'line-bus': '#ffc72c',
'line-red': COLORS.mbta.red,
'line-orange': COLORS.mbta.orange,
'line-blue': COLORS.mbta.blue,
'line-green': COLORS.mbta.green,
'line-bus': COLORS.mbta.bus,
'line-commuter-rail': COLORS.mbta.commuterRail,
default: '#303030',
};

Expand Down
Loading
Loading