11import { FC , useMemo } from 'react'
2- import Icon from 'components/icons/Icon'
32import InfoMessage from 'components/InfoMessage'
4- import { colorTextSuccess } from 'common/theme/tokens'
53import { BayesianResultsSummary , Experiment } from 'common/types/responses'
64import { getPrimaryMetric } from 'components/experiments/constants'
75import {
@@ -19,14 +17,16 @@ type ExperimentSummaryScorecardProps = {
1917 results ?: BayesianResultsSummary
2018}
2119
22- type SummaryStats = {
20+ export type SummaryStats = {
2321 winnerName : string
22+ winnerColour : string
23+ controlColour : string
2424 chanceToBest : string
2525 liftVsControl : string
2626 liftFavourable : boolean
2727}
2828
29- const deriveSummary = (
29+ export const deriveSummary = (
3030 experiment : Experiment ,
3131 results : BayesianResultsSummary ,
3232) : SummaryStats | null => {
@@ -39,13 +39,18 @@ const deriveSummary = (
3939 const winner = getWinningVariant ( metricResult , identities )
4040 if ( ! winner ) return null
4141
42+ const winnerIdentity = identities . find ( ( v ) => v . key === winner . key )
43+ const controlIdentity = identities . find ( ( v ) => v . isControl )
44+
4245 return {
4346 chanceToBest : `${ Math . round ( winner . chanceToWin * 100 ) } %` ,
47+ controlColour : controlIdentity ?. colour ?? '' ,
4448 liftFavourable : isLiftFavourable (
4549 winner . inference . lift ,
4650 metric . expected_direction ,
4751 ) ,
4852 liftVsControl : formatLiftPct ( winner . inference . lift ) ,
53+ winnerColour : winnerIdentity ?. colour ?? '' ,
4954 winnerName : winner . name ,
5055 }
5156}
@@ -63,25 +68,11 @@ const ExperimentSummaryScorecard: FC<ExperimentSummaryScorecardProps> = ({
6368
6469 return (
6570 < >
66- { summary ? (
67- < div className = 'alert alert-success mb-3' >
68- < div className = 'd-flex align-items-center gap-2 mb-1' >
69- < Icon name = 'checkmark-circle' width = { 20 } fill = { colorTextSuccess } />
70- < span className = 'text-success fw-normal' > Recommendation</ span >
71- </ div >
72- < div >
73- < strong > { summary . winnerName } </ strong > is outperforming{ ' ' }
74- < strong > Control</ strong > with { summary . chanceToBest } probability of
75- being the best variant.
76- </ div >
77- </ div >
78- ) : (
79- hasResults && (
80- < InfoMessage title = 'Collecting data' >
81- The experiment is still gathering data. Results will appear once
82- there is enough traffic for statistically meaningful analysis.
83- </ InfoMessage >
84- )
71+ { ! summary && hasResults && (
72+ < InfoMessage title = 'Collecting data' >
73+ The experiment is still gathering data. Results will appear once there
74+ is enough traffic for statistically meaningful analysis.
75+ </ InfoMessage >
8576 ) }
8677 < div className = 'row g-3 mb-4' >
8778 < div className = 'col-md-3' >
0 commit comments