-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a evaluation is run show results in the frontend whenever they're
processed
- Loading branch information
1 parent
07767df
commit d5e5428
Showing
34 changed files
with
956 additions
and
358 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...itUuid]/documents/[documentUuid]/evaluations/[evaluationId]/_components/Content/index.tsx
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,51 @@ | ||
'use client' | ||
|
||
import { | ||
Commit, | ||
EvaluationAggregationTotals, | ||
EvaluationDto, | ||
EvaluationMeanValue, | ||
EvaluationModalValue, | ||
} from '@latitude-data/core/browser' | ||
import { EvaluationResultWithMetadata } from '@latitude-data/core/repositories' | ||
|
||
import { EvaluationResults } from '../EvaluationResults' | ||
import { MetricsSummary } from '../MetricsSummary' | ||
import { useEvaluationStatus } from './useEvaluationStatus' | ||
|
||
export default function Content<T extends boolean>({ | ||
commit, | ||
evaluation, | ||
evaluationResults, | ||
documentUuid, | ||
aggregationTotals, | ||
isNumeric, | ||
meanOrModal, | ||
}: { | ||
commit: Commit | ||
evaluation: EvaluationDto | ||
documentUuid: string | ||
evaluationResults: EvaluationResultWithMetadata[] | ||
aggregationTotals: EvaluationAggregationTotals | ||
isNumeric: T | ||
meanOrModal: T extends true ? EvaluationMeanValue : EvaluationModalValue | ||
}) { | ||
const { jobs } = useEvaluationStatus({ evaluation }) | ||
return ( | ||
<> | ||
<MetricsSummary | ||
commit={commit} | ||
evaluation={evaluation} | ||
documentUuid={documentUuid} | ||
aggregationTotals={aggregationTotals} | ||
isNumeric={isNumeric} | ||
meanOrModal={meanOrModal} | ||
/> | ||
<EvaluationResults | ||
evaluation={evaluation} | ||
evaluationResults={evaluationResults} | ||
jobs={jobs} | ||
/> | ||
</> | ||
) | ||
} |
72 changes: 72 additions & 0 deletions
72
...ents/[documentUuid]/evaluations/[evaluationId]/_components/Content/useEvaluationStatus.ts
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,72 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react' | ||
|
||
import { Evaluation } from '@latitude-data/core/browser' | ||
import { useCurrentDocument } from '@latitude-data/web-ui' | ||
import { | ||
useSockets, | ||
type EventArgs, | ||
} from '$/components/Providers/WebsocketsProvider/useSockets' | ||
|
||
import { isEvaluationRunDone } from '../../_lib/isEvaluationRunDone' | ||
import { useRefetchStats } from './useRefetchStats' | ||
|
||
const DISAPERING_IN_MS = 5000 | ||
|
||
export function useEvaluationStatus({ | ||
evaluation, | ||
}: { | ||
evaluation: Evaluation | ||
}) { | ||
const timeoutRef = useRef<number | null>(null) | ||
const [jobs, setJobs] = useState<EventArgs<'evaluationStatus'>[]>([]) | ||
const document = useCurrentDocument() | ||
const { refetchStats } = useRefetchStats({ evaluation, document }) | ||
const onMessage = useCallback( | ||
(args: EventArgs<'evaluationStatus'>) => { | ||
if (evaluation.id !== args.evaluationId) return | ||
if (document.documentUuid !== args.documentUuid) return | ||
|
||
const done = isEvaluationRunDone(args) | ||
|
||
if (done) { | ||
refetchStats() | ||
} | ||
|
||
setJobs((prevJobs) => { | ||
const jobIndex = prevJobs.findIndex( | ||
(job) => job.batchId === args.batchId, | ||
) | ||
|
||
if (jobIndex === -1) { | ||
return [...prevJobs, args] | ||
} else { | ||
const newJobs = [...prevJobs] | ||
newJobs[jobIndex] = args | ||
|
||
if (done) { | ||
setTimeout(() => { | ||
setJobs((currentJobs) => | ||
currentJobs.filter((job) => job.batchId !== args.batchId), | ||
) | ||
}, DISAPERING_IN_MS) | ||
} | ||
|
||
return newJobs | ||
} | ||
}) | ||
}, | ||
[evaluation.id, document.documentUuid, refetchStats], | ||
) | ||
|
||
useEffect(() => { | ||
return () => { | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current) | ||
} | ||
} | ||
}, []) | ||
|
||
useSockets({ event: 'evaluationStatus', onMessage }) | ||
|
||
return { jobs } | ||
} |
79 changes: 79 additions & 0 deletions
79
...ocuments/[documentUuid]/evaluations/[evaluationId]/_components/Content/useRefetchStats.ts
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,79 @@ | ||
import { useCallback } from 'react' | ||
|
||
import { | ||
DocumentVersion, | ||
Evaluation, | ||
EvaluationResultableType, | ||
} from '@latitude-data/core/browser' | ||
import { useCurrentCommit } from '@latitude-data/web-ui' | ||
import useEvaluationResultsCounters from '$/stores/evaluationResultCharts/evaluationResultsCounters' | ||
import useEvaluationResultsMeanValue from '$/stores/evaluationResultCharts/evaluationResultsMeanValue' | ||
import useEvaluationResultsModalValue from '$/stores/evaluationResultCharts/evaluationResultsModalValue' | ||
import useAverageResultsAndCostOverCommit from '$/stores/evaluationResultCharts/numericalResults/averageResultAndCostOverCommitStore' | ||
import useAverageResultOverTime from '$/stores/evaluationResultCharts/numericalResults/averageResultOverTimeStore' | ||
|
||
export function useRefetchStats({ | ||
evaluation, | ||
document, | ||
}: { | ||
evaluation: Evaluation | ||
document: DocumentVersion | ||
}) { | ||
const { commit } = useCurrentCommit() | ||
const evaluationId = evaluation.id | ||
const commitUuid = commit.uuid | ||
const documentUuid = document.documentUuid | ||
const isNumeric = | ||
evaluation.configuration.type === EvaluationResultableType.Number | ||
|
||
const { refetch: refetchAverageResulstAndCostsOverCommit } = | ||
useAverageResultsAndCostOverCommit({ | ||
evaluation, | ||
documentUuid, | ||
}) | ||
const { refetch: refetchAverageResultOverTime } = useAverageResultOverTime({ | ||
evaluation, | ||
documentUuid, | ||
}) | ||
const { refetch: refetchMean } = useEvaluationResultsMeanValue({ | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}) | ||
const { refetch: refetchModal } = useEvaluationResultsModalValue({ | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}) | ||
const { refetch: refetchTotals } = useEvaluationResultsCounters({ | ||
commitUuid, | ||
documentUuid, | ||
evaluationId, | ||
}) | ||
|
||
const refetchStats = useCallback(() => { | ||
console.log('refetchStats') | ||
|
||
Promise.all([ | ||
refetchTotals(), | ||
...(isNumeric | ||
? [ | ||
refetchMean(), | ||
refetchAverageResulstAndCostsOverCommit(), | ||
refetchAverageResultOverTime(), | ||
] | ||
: [refetchModal()]), | ||
]) | ||
}, [ | ||
isNumeric, | ||
refetchMean, | ||
refetchModal, | ||
refetchTotals, | ||
refetchAverageResulstAndCostsOverCommit, | ||
refetchAverageResultOverTime, | ||
]) | ||
|
||
return { | ||
refetchStats, | ||
} | ||
} |
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
Oops, something went wrong.