Skip to content

Commit

Permalink
Ridership max widget + small fix. (#847)
Browse files Browse the repository at this point in the history
* Change historical max to max on widgets

* Add maximum widget to ridership

* lint
  • Loading branch information
PatrickCleary committed Aug 25, 2023
1 parent ffcbf73 commit 6d12ce3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 7 additions & 1 deletion modules/ridership/RidershipGraphWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const RidershipGraphWrapper: React.FC<RidershipGraphWrapperProps> = ({
endDate,
}) => {
if (!data.some((datapoint) => datapoint.count !== null)) return <NoDataNotice isLineMetric />;
const { average, percentage } = getRidershipWidgetValues(data, line, busRoute);
const { average, percentage, peak } = getRidershipWidgetValues(data, line, busRoute);

return (
<CarouselGraphDiv>
Expand All @@ -44,6 +44,12 @@ export const RidershipGraphWrapper: React.FC<RidershipGraphWrapperProps> = ({
layoutKind="no-delta"
widgetValue={new PercentageWidgetValue(percentage)}
/>
<WidgetForCarousel
layoutKind="no-delta"
sentimentDirection={'positiveOnIncrease'}
analysis={`Max - ${config.getWidgetTitle(peak.date)}`}
widgetValue={new RidersWidgetValue(peak ? peak.count : undefined)}
/>
</WidgetCarousel>
<RidershipGraph config={config} data={data} startDate={startDate} endDate={endDate} />
</CarouselGraphDiv>
Expand Down
7 changes: 5 additions & 2 deletions modules/ridership/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export const getRidershipWidgetValues = (
) => {
const routeIndex = busRoute ? busRoute.replaceAll('/', '') : line;
const average = ridership.reduce((sum, current) => sum + current.count, 0) / ridership.length;

const peak = ridership.reduce(
(max, datapoint) => (datapoint.count > max.count ? datapoint : max),
ridership[0]
);
const percentage =
ridership[ridership.length - 1]?.count / PEAK_RIDERSHIP[routeIndex ?? 'DEFAULT'];
return { average: average, percentage: percentage };
return { average: average, percentage: percentage, peak: peak };
};
2 changes: 1 addition & 1 deletion modules/service/ServiceGraphWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ServiceGraphWrapper: React.FC<ServiceGraphWrapperProps> = ({
<WidgetForCarousel
layoutKind="no-delta"
sentimentDirection={'positiveOnIncrease'}
analysis={`Historical Maximum - ${config.getWidgetTitle(peak.date)}`}
analysis={`Max - ${config.getWidgetTitle(peak.date)}`}
widgetValue={new TripsWidgetValue(peak ? peak.count : undefined)}
/>
</WidgetCarousel>
Expand Down
2 changes: 1 addition & 1 deletion modules/speed/SpeedGraphWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const SpeedGraphWrapper: React.FC<SpeedGraphWrapperProps> = ({
/>
<WidgetForCarousel
widgetValue={new MPHWidgetValue(peak.mph, undefined)}
analysis={`Historical Maximum - ${config.getWidgetTitle(peak.date)}`}
analysis={`Max - ${config.getWidgetTitle(peak.date)}`}
sentimentDirection={'positiveOnIncrease'}
layoutKind="no-delta"
/>
Expand Down

0 comments on commit 6d12ce3

Please sign in to comment.