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

feat(trip-explorer): speed for station pairs #909

Merged
merged 25 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
43c9bf4
feat: speed for station pairs
rudiejd Dec 17, 2023
6abbde7
fix generation of distances file, add both names to new speed chart, …
rudiejd Dec 18, 2023
f205324
use station distance instead of stop distance, do some overly complic…
rudiejd Dec 18, 2023
9273909
this seems to be simpler
rudiejd Dec 18, 2023
d9446cf
fix: lint and add some uncommited changes
rudiejd Dec 19, 2023
ce927ea
fix: typescript
rudiejd Dec 19, 2023
4b2163b
fix: remove debugging change
rudiejd Dec 19, 2023
e001238
fix: lint backend
rudiejd Dec 19, 2023
1bb2337
fix: lint backend again lol
rudiejd Dec 19, 2023
62480e7
improve the distance calculation, add a legend
rudiejd Dec 19, 2023
f055ef1
fix: run lint
rudiejd Dec 19, 2023
224a3df
fix: remove debug
rudiejd Dec 19, 2023
bfb6673
add aggregate speed chart, reorganize
rudiejd Dec 22, 2023
cbb83de
finish up the aggregation nation
rudiejd Dec 23, 2023
818c720
fix build
rudiejd Dec 23, 2023
eb7689e
fix: refactor the distance calculation to do two passes, one of the s…
rudiejd Dec 23, 2023
cdb830b
refactor station distances script
rudiejd Dec 23, 2023
02fe7b7
remove log
rudiejd Dec 23, 2023
1d8d1c8
format
rudiejd Dec 23, 2023
e95a431
fixup: respond to comments
rudiejd Dec 31, 2023
f4d3eec
fix: correct green line distances. WOOOO finally figured it out
rudiejd Jan 11, 2024
018e1fb
fix: move speed to the same graph as travel times
rudiejd Jan 12, 2024
5d93c16
fix: change order and don't capitalize travel times
rudiejd Jan 12, 2024
fea4954
fix: traveltimes default
rudiejd Jan 12, 2024
652bc7f
fix: respond to comments
rudiejd Jan 14, 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
20 changes: 12 additions & 8 deletions common/components/charts/AggregateLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ export const AggregateLineChart: React.FC<AggregateLineProps> = ({
suggestedYMax,
showLegend = true,
byTime = false,
yUnit = 'Minutes',
}) => {
const ref = useRef();
const hourly = timeUnit === 'hour';
const isMobile = !useBreakpoint('md');
const labels = useMemo(() => data.map((item) => item[pointField]), [data, pointField]);

const multiplier = yUnit === 'Minutes' ? 1 / 60 : 1;

return (
<ChartBorder>
<ChartDiv isMobile={isMobile}>
Expand All @@ -72,7 +75,7 @@ export const AggregateLineChart: React.FC<AggregateLineProps> = ({
pointRadius: byTime ? 0 : 3,
pointHitRadius: 10,
stepped: byTime,
data: data.map((item: AggregateDataPoint) => (item['50%'] / 60).toFixed(2)),
data: data.map((item: AggregateDataPoint) => (item['50%'] * multiplier).toFixed(2)),
},
{
label: '25th percentile',
Expand All @@ -81,7 +84,7 @@ export const AggregateLineChart: React.FC<AggregateLineProps> = ({
stepped: byTime,
tension: 0.4,
pointRadius: 0,
data: data.map((item: AggregateDataPoint) => (item['25%'] / 60).toFixed(2)),
data: data.map((item: AggregateDataPoint) => (item['25%'] * multiplier).toFixed(2)),
},
{
label: '75th percentile',
Expand All @@ -90,7 +93,7 @@ export const AggregateLineChart: React.FC<AggregateLineProps> = ({
stepped: byTime,
tension: 0.4,
pointRadius: 0,
data: data.map((item: AggregateDataPoint) => (item['75%'] / 60).toFixed(2)),
data: data.map((item: AggregateDataPoint) => (item['75%'] * multiplier).toFixed(2)),
},
],
}}
Expand All @@ -99,7 +102,7 @@ export const AggregateLineChart: React.FC<AggregateLineProps> = ({
y: {
title: {
display: true,
text: 'Minutes',
text: yUnit,
},
ticks: {
precision: 1,
Expand Down Expand Up @@ -146,10 +149,11 @@ export const AggregateLineChart: React.FC<AggregateLineProps> = ({
position: 'nearest',
callbacks: {
label: (tooltipItem) => {
return `${tooltipItem.dataset.label}: ${getFormattedTimeString(
tooltipItem.parsed.y,
'minutes'
)}`;
return `${tooltipItem.dataset.label}: ${
yUnit === 'Minutes'
? getFormattedTimeString(tooltipItem.parsed.y, 'minutes')
: `${tooltipItem.parsed.y} ${yUnit}`
}`;
},
},
},
Expand Down
12 changes: 11 additions & 1 deletion common/components/charts/SingleChartWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { ChartPlaceHolder } from '../graphics/ChartPlaceHolder';
import { TravelTimesSingleChart } from '../../../modules/traveltimes/charts/TravelTimesSingleChart';
import { HeadwaysSingleChart } from '../../../modules/headways/charts/HeadwaysSingleChart';
import { DwellsSingleChart } from '../../../modules/dwells/charts/DwellsSingleChart';
import { SpeedBetweenStationsSingleChart } from '../../../modules/speed/charts/SpeedBetweenStationsSingleChart';

interface SingleChartWrapperProps {
query: UseQueryResult<SingleDayDataPoint[]>;
toStation: Station | undefined;
fromStation: Station | undefined;
type: 'headways' | 'traveltimes' | 'dwells';
type: 'headways' | 'traveltimes' | 'dwells' | 'speeds';
showLegend?: boolean;
}

Expand Down Expand Up @@ -47,5 +48,14 @@ export const SingleChartWrapper: React.FC<SingleChartWrapperProps> = ({
return (
<DwellsSingleChart dwells={query.data} fromStation={fromStation} toStation={toStation} />
);
case 'speeds':
return (
<SpeedBetweenStationsSingleChart
traveltimes={query.data}
fromStation={fromStation}
toStation={toStation}
showLegend={showLegend}
/>
);
}
};
21 changes: 14 additions & 7 deletions common/components/charts/SingleDayLineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({
fname,
bothStops = false,
location,
units,
showLegend = true,
}) => {
const ref = useRef();
Expand All @@ -79,10 +80,15 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({
);
const displayBenchmarkData = benchmarkData.every((datapoint) => datapoint !== undefined);
// Have to use `as number` because typescript doesn't understand `datapoint` is not undefined.
const multiplier = units === 'Minutes' ? 1 / 60 : 1;
const benchmarkDataFormatted = displayBenchmarkData
? benchmarkData.map((datapoint) => ((datapoint as number) / 60).toFixed(2))
? benchmarkData.map((datapoint) => ((datapoint as number) * multiplier).toFixed(2))
: null;

const convertedData = data.map((datapoint) =>
((datapoint[metricField] as number) * multiplier).toFixed(2)
);

return (
<ChartBorder>
<ChartDiv isMobile={isMobile}>
Expand All @@ -103,7 +109,7 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({
pointHoverBackgroundColor: pointColors(data, metricField, benchmarkField),
pointRadius: 3,
pointHitRadius: 10,
data: data.map((datapoint) => ((datapoint[metricField] as number) / 60).toFixed(2)),
data: convertedData,
},
{
label: `Benchmark MBTA`,
Expand Down Expand Up @@ -133,10 +139,11 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({
) {
return '';
}
return `${tooltipItem.dataset.label}: ${getFormattedTimeString(
tooltipItem.parsed.y,
'minutes'
)}`;
return `${tooltipItem.dataset.label}: ${
units === 'Minutes'
? getFormattedTimeString(tooltipItem.parsed.y, 'minutes')
: `${tooltipItem.parsed.y} ${units}`
}`;
},
afterBody: (tooltipItems) => {
return departureFromNormalString(
Expand All @@ -162,7 +169,7 @@ export const SingleDayLineChart: React.FC<SingleDayLineProps> = ({
},
title: {
display: true,
text: 'Minutes',
text: units,
color: COLORS.design.subtitleGrey,
},
},
Expand Down
Loading