Skip to content

Commit

Permalink
move colorByExecution handler to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
shootermv committed Oct 9, 2023
1 parent 42e4396 commit b528a26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
10 changes: 7 additions & 3 deletions src/pages/GapsPatternsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ import {
TooltipProps,
} from 'recharts'
import { FormControlLabel, Radio, RadioGroup } from '@mui/material'
import { GetColorByExecution } from './components/utils/ColorBySeverity'
import { HourlyData, byHourHandler, bySeverityHandler } from './components/utils'
import {
HourlyData,
byHourHandler,
bySeverityHandler,
mapColorByExecution,
} from './components/utils'

// Define prop types for the component
interface BusLineStatisticsProps {
Expand Down Expand Up @@ -173,7 +177,7 @@ function GapsByHour({ lineRef, operatorRef, fromDate, toDate }: BusLineStatistic
{hourlyData.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={GetColorByExecution(entry.planned_rides, entry.actual_rides)}
fill={mapColorByExecution(entry.planned_rides, entry.actual_rides)}
/>
))}
</Bar>
Expand Down
12 changes: 0 additions & 12 deletions src/pages/components/utils/ColorBySeverity.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions src/pages/components/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ export const bySeverityHandler = (a: HourlyData, b: HourlyData) => {
}
return b.planned_rides - a.planned_rides
}

export const mapColorByExecution = (planned: number, actual: number) => {
const misses = planned - actual
const percentageMisses = (misses / planned) * 100

if (percentageMisses <= 5) {
return 'green'
} else if (percentageMisses <= 50) {
return 'orange'
} else {
return 'red'
}
}

0 comments on commit b528a26

Please sign in to comment.