-
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.
Add a reliability page for alert analysis
- Loading branch information
1 parent
fcd4bef
commit 918759a
Showing
17 changed files
with
874 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { ONE_HOUR } from '../../constants/time'; | ||
import { fetchLineDelaysByLine } from '../reliability'; | ||
import type { FetchAlertDelaysByLineOptions } from '../../types/api'; | ||
|
||
export const useAlertDelays = (options: FetchAlertDelaysByLineOptions, enabled?: boolean) => { | ||
return useQuery({ | ||
queryKey: ['lineReliability', options], | ||
queryFn: () => fetchLineDelaysByLine(options), | ||
enabled: enabled, | ||
staleTime: ONE_HOUR, | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FetchAlertDelaysByLineParams, type FetchAlertDelaysByLineOptions } from '../types/api'; | ||
import type { LineDelays } from '../types/reliability'; | ||
import { apiFetch } from './utils/fetch'; | ||
|
||
export const fetchLineDelaysByLine = async ( | ||
options: FetchAlertDelaysByLineOptions | ||
): Promise<LineDelays[]> => { | ||
if (!options[FetchAlertDelaysByLineParams.line]) return []; | ||
|
||
return await apiFetch({ | ||
path: '/api/linedelays', | ||
options, | ||
errorMessage: 'Failed to fetch reliability metrics', | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Line } from './lines'; | ||
|
||
export interface LineDelays { | ||
date: string; | ||
disabled_train: number; | ||
door_problem: number; | ||
flooding: number; | ||
fire: number; | ||
line: Line; | ||
medical_emergency: number; | ||
other: number; | ||
police_activity: number; | ||
power_problem: number; | ||
signal_problem: number; | ||
brake_problem: number; | ||
switch_problem: number; | ||
total_delay_time: number; | ||
track_issue: number; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import { useDelimitatedRoute } from '../../common/utils/router'; | ||
import { ChartPlaceHolder } from '../../common/components/graphics/ChartPlaceHolder'; | ||
import { Layout } from '../../common/layouts/layoutTypes'; | ||
import { PageWrapper } from '../../common/layouts/PageWrapper'; | ||
import { ChartPageDiv } from '../../common/components/charts/ChartPageDiv'; | ||
import { useAlertDelays } from '../../common/api/hooks/reliability'; | ||
import { Widget } from '../../common/components/widgets'; | ||
import { TotalDelayGraph } from './charts/TotalDelayGraph'; | ||
import { DelayBreakdownGraph } from './charts/DelayBreakdownGraph'; | ||
import { DelayByCategoryGraph } from './charts/DelayByCategoryGraph'; | ||
|
||
dayjs.extend(utc); | ||
|
||
export function ReliabilityDetails() { | ||
const { | ||
line, | ||
query: { startDate, endDate }, | ||
} = useDelimitatedRoute(); | ||
|
||
const enabled = Boolean(startDate && endDate && line); | ||
const alertDelays = useAlertDelays( | ||
{ | ||
start_date: startDate, | ||
end_date: endDate, | ||
line, | ||
}, | ||
enabled | ||
); | ||
const reliabilityReady = alertDelays && line && !alertDelays.isError && alertDelays.data; | ||
if (!startDate || !endDate) { | ||
return <p>Select a date range to load graphs.</p>; | ||
} | ||
|
||
return ( | ||
<PageWrapper pageTitle={'Reliability'}> | ||
<ChartPageDiv> | ||
<Widget title="Total Time Delayed" ready={[alertDelays]}> | ||
{reliabilityReady ? ( | ||
<TotalDelayGraph data={alertDelays.data} startDate={startDate} endDate={endDate} /> | ||
) : ( | ||
<div className="relative flex h-full"> | ||
<ChartPlaceHolder query={alertDelays} /> | ||
</div> | ||
)} | ||
</Widget> | ||
<Widget title="Delay Time by Reason" ready={[alertDelays]}> | ||
{reliabilityReady ? ( | ||
<DelayBreakdownGraph data={alertDelays.data} startDate={startDate} endDate={endDate} /> | ||
) : ( | ||
<div className="relative flex h-full"> | ||
<ChartPlaceHolder query={alertDelays} /> | ||
</div> | ||
)} | ||
</Widget> | ||
<Widget title="Delay Time by Reason" ready={[alertDelays]}> | ||
{reliabilityReady ? ( | ||
<DelayByCategoryGraph data={alertDelays.data} /> | ||
) : ( | ||
<div className="relative flex h-full"> | ||
<ChartPlaceHolder query={alertDelays} /> | ||
</div> | ||
)} | ||
</Widget> | ||
</ChartPageDiv> | ||
</PageWrapper> | ||
); | ||
} | ||
|
||
ReliabilityDetails.Layout = Layout.Dashboard; |
Oops, something went wrong.