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

Add bus ridership baselines #762

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 14 additions & 14 deletions common/constants/baselines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ export const PEAK_RIDERSHIP = {
'line-orange': 169578,
'line-blue': 60129,
'line-green': 87148,
'1': 15000,
'15': 15000,
'22': 15000,
'23': 15000,
'28': 15000,
'32': 15000,
'39': 15000,
'57': 15000,
'66': 15000,
'71': 15000,
'73': 15000,
'77': 15000,
'111': 15000,
'114116117': 15000,
'1': 15272,
'15': 6379,
'22': 8767,
'23': 12225,
'28': 12893,
'32': 10982,
'39': 11792,
'57': 14505,
'66': 14505,
'71': 5789,
'73': 6616,
'77': 8015,
'111': 11258,
'114116117': 12867,
DEFAULT: 0,
};

Expand Down
5 changes: 3 additions & 2 deletions modules/ridership/RidershipDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function RidershipDetails() {
},
enabled
);
const ridershipDataReady = !ridership.isError && startDate && endDate && lineOrRoute;
const ridershipDataReady = !ridership.isError && startDate && endDate && lineOrRoute && line;

return (
<PageWrapper pageTitle={'Ridership'}>
Expand All @@ -41,7 +41,8 @@ export function RidershipDetails() {
config={config}
startDate={startDate}
endDate={endDate}
lineOrRoute={lineOrRoute}
line={line}
busRoute={busRoute}
/>
) : (
<div className="relative flex h-full">
Expand Down
9 changes: 6 additions & 3 deletions modules/ridership/RidershipGraphWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import { WidgetCarousel } from '../../common/components/general/WidgetCarousel';
import { PercentageWidgetValue, RidersWidgetValue } from '../../common/types/basicWidgets';
import { WidgetForCarousel } from '../../common/components/widgets/internal/WidgetForCarousel';
import { CarouselGraphDiv } from '../../common/components/charts/CarouselGraphDiv';
import type { BusRoute, Line } from '../../common/types/lines';
import { NoDataNotice } from '../../common/components/notices/NoDataNotice';
import { getRidershipWidgetValues } from './utils/utils';
import { RidershipGraph } from './RidershipGraph';
interface RidershipGraphWrapperProps {
data: RidershipCount[];
lineOrRoute: string;
line: Line;
busRoute: BusRoute | undefined;
config: ParamsType;
startDate: string;
endDate: string;
}

export const RidershipGraphWrapper: React.FC<RidershipGraphWrapperProps> = ({
data,
lineOrRoute,
line,
busRoute,
config,
startDate,
endDate,
}) => {
if (!data.some((datapoint) => datapoint.count !== null)) return <NoDataNotice isLineMetric />;
const { average, percentage } = getRidershipWidgetValues(data, lineOrRoute);
const { average, percentage } = getRidershipWidgetValues(data, line, busRoute);

return (
<CarouselGraphDiv>
Expand Down
5 changes: 3 additions & 2 deletions modules/ridership/RidershipWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ export const RidershipWidget: React.FC = () => {
start_date: startDate,
end_date: endDate,
});
const serviceReady = !ridership.isError && lineId && lineOrRoute;
const serviceReady = !ridership.isError && lineId && line && lineOrRoute;

return (
<WidgetDiv>
<HomescreenWidgetTitle title="Weekday ridership" tab="ridership" />
{ridership.data && serviceReady ? (
<RidershipGraphWrapper
lineOrRoute={lineOrRoute}
line={line}
busRoute={query.busRoute}
data={ridership.data}
config={config}
startDate={startDate}
Expand Down
12 changes: 10 additions & 2 deletions modules/ridership/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import type { RidershipCount } from '../../../common/types/dataPoints';
import { PEAK_RIDERSHIP } from '../../../common/constants/baselines';
import type { BusRoute, Line } from '../../../common/types/lines';

export const getRidershipWidgetValues = (ridership: RidershipCount[], line: string) => {
export const getRidershipWidgetValues = (
ridership: RidershipCount[],
line: Line,
busRoute?: BusRoute
) => {
const routeIndex = busRoute ? busRoute.replaceAll('/', '') : line;
const average = ridership.reduce((sum, current) => sum + current.count, 0) / ridership.length;
const percentage = ridership[ridership.length - 1]?.count / PEAK_RIDERSHIP[line ?? 'DEFAULT'];

const percentage =
ridership[ridership.length - 1]?.count / PEAK_RIDERSHIP[routeIndex ?? 'DEFAULT'];
return { average: average, percentage: percentage };
};
Loading