TrialCount.tsx 6.09 KB
Newer Older
1
import * as React from 'react';
2
import { Stack, TooltipHost, ProgressIndicator, DirectionalHint } from '@fluentui/react';
3
import { EXPERIMENT, TRIALS } from '../../../static/datamodel';
4
import { CONTROLTYPE, TOOLTIP_BACKGROUND_COLOR, MAX_TRIAL_NUMBERS } from '../../../static/const';
5
6
7
import { EditExperimentParam } from './EditExperimentParam';
import { EditExpeParamContext } from './context';
import { ExpDurationContext } from './ExpDurationContext';
Lijiaoa's avatar
Lijiaoa committed
8
import { leftProgress, trialCountItem2, progressHeight } from './commonStyle';
9
10
11
12
13
14
15

export const TrialCount = (): any => {
    const count = TRIALS.countStatus();
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    const stoppedCount = count.get('USER_CANCELED')! + count.get('SYS_CANCELED')! + count.get('EARLY_STOPPED')!;
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    const bar2 = count.get('RUNNING')! + count.get('SUCCEEDED')! + count.get('FAILED')! + stoppedCount;
16
    const maxTrialNum = EXPERIMENT.profile.params.maxTrialNum;
17
    // support type [0, 1], not 98%
18
    const bar2Percent = bar2 / maxTrialNum;
19
20
21
22
23
24
25
    return (
        <ExpDurationContext.Consumer>
            {(value): React.ReactNode => {
                const { updateOverviewPage } = value;
                return (
                    <React.Fragment>
                        <Stack horizontal horizontalAlign='space-between' className='ExpDuration'>
Lijiaoa's avatar
Lijiaoa committed
26
                            <div style={leftProgress}>
27
                                <TooltipHost
Lijiaoa's avatar
Lijiaoa committed
28
                                    content={`${bar2.toString()} trials`}
29
30
31
32
33
34
35
36
37
38
39
40
41
42
                                    directionalHint={DirectionalHint.bottomCenter}
                                    tooltipProps={{
                                        calloutProps: {
                                            styles: {
                                                beak: { background: TOOLTIP_BACKGROUND_COLOR },
                                                beakCurtain: { background: TOOLTIP_BACKGROUND_COLOR },
                                                calloutMain: { background: TOOLTIP_BACKGROUND_COLOR }
                                            }
                                        }
                                    }}
                                >
                                    <ProgressIndicator
                                        className={EXPERIMENT.status}
                                        percentComplete={bar2Percent}
Lijiaoa's avatar
Lijiaoa committed
43
                                        barHeight={progressHeight}
44
                                    />
45
                                </TooltipHost>
46
47
48
49
50
                                <div className='exp-progress'>
                                    <span className={`${EXPERIMENT.status} bold`}>{bar2}</span>
                                    <span className='joiner'>/</span>
                                    <span>{maxTrialNum}</span>
                                </div>
51
                            </div>
52
                            <div style={trialCountItem2}>
53
54
                                <EditExpeParamContext.Provider
                                    value={{
55
                                        title: MAX_TRIAL_NUMBERS,
56
57
58
59
60
61
62
63
                                        field: 'maxTrialNum',
                                        editType: CONTROLTYPE[1],
                                        maxExecDuration: '',
                                        maxTrialNum: EXPERIMENT.profile.params.maxTrialNum,
                                        trialConcurrency: EXPERIMENT.profile.params.trialConcurrency,
                                        updateOverviewPage
                                    }}
                                >
64
65
66
                                    <div className='maxTrialNum'>
                                        <EditExperimentParam />
                                    </div>
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
                                </EditExpeParamContext.Provider>
                                <EditExpeParamContext.Provider
                                    value={{
                                        title: 'Concurrency',
                                        field: 'trialConcurrency',
                                        editType: CONTROLTYPE[2],
                                        // maxExecDuration: EXPERIMENT.profile.params.maxExecDuration,
                                        maxExecDuration: '',
                                        maxTrialNum: EXPERIMENT.profile.params.maxTrialNum,
                                        trialConcurrency: EXPERIMENT.profile.params.trialConcurrency,
                                        updateOverviewPage
                                    }}
                                >
                                    <EditExperimentParam />
                                </EditExpeParamContext.Provider>
                            </div>
                        </Stack>
Lijiaoa's avatar
Lijiaoa committed
84
                        <Stack horizontal horizontalAlign='space-between' className='trialStatus'>
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                            <div className='basic'>
                                <p>Running</p>
                                <div>{count.get('RUNNING')}</div>
                            </div>
                            <div className='basic'>
                                <p>Succeeded</p>
                                <div>{count.get('SUCCEEDED')}</div>
                            </div>
                            <div className='basic'>
                                <p>Stopped</p>
                                <div>{stoppedCount}</div>
                            </div>
                            <div className='basic'>
                                <p>Failed</p>
                                <div>{count.get('FAILED')}</div>
                            </div>
                            <div className='basic'>
                                <p>Waiting</p>
                                <div>{count.get('WAITING')}</div>
                            </div>
                        </Stack>
106
107
108
109
110
111
                    </React.Fragment>
                );
            }}
        </ExpDurationContext.Consumer>
    );
};