-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
36 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |