TrialCount.tsx 6.71 KB
Newer Older
1
import * as React from 'react';
Lijiaoa's avatar
Lijiaoa committed
2
import { Stack, TooltipHost, ProgressIndicator, DirectionalHint, IStackTokens } from '@fluentui/react';
Lijiaoa's avatar
Lijiaoa committed
3
4
import { EXPERIMENT, TRIALS } from '@static/datamodel';
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';
8
import { leftProgress, rightEidtParam, progressHeight } from './commonStyle';
9

Lijiaoa's avatar
Lijiaoa committed
10
11
12
13
14
15
16
const line1Tokens: IStackTokens = {
    childrenGap: 60
};
const line2Tokens: IStackTokens = {
    childrenGap: 80
};

17
18
19
20
21
22
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;
23
    const maxTrialNum = EXPERIMENT.maxTrialNumber;
24
    // support type [0, 1], not 98%
25
    const bar2Percent = bar2 / maxTrialNum;
26
27
28
29
30
31
    return (
        <ExpDurationContext.Consumer>
            {(value): React.ReactNode => {
                const { updateOverviewPage } = value;
                return (
                    <React.Fragment>
32
                        <Stack horizontal className='ExpDuration'>
Lijiaoa's avatar
Lijiaoa committed
33
                            <div style={leftProgress}>
34
                                <TooltipHost
Lijiaoa's avatar
Lijiaoa committed
35
                                    content={`${bar2.toString()} trials`}
36
37
38
39
40
41
42
43
44
45
46
47
48
49
                                    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
50
                                        barHeight={progressHeight}
51
                                    />
52
                                </TooltipHost>
53
54
55
56
57
                                <div className='exp-progress'>
                                    <span className={`${EXPERIMENT.status} bold`}>{bar2}</span>
                                    <span className='joiner'>/</span>
                                    <span>{maxTrialNum}</span>
                                </div>
58
                            </div>
59
60
61
                        </Stack>
                        <Stack horizontal className='marginTop'>
                            <div style={leftProgress}>
Lijiaoa's avatar
Lijiaoa committed
62
                                <Stack horizontal className='status-count' tokens={line1Tokens}>
63
64
65
66
67
68
69
70
71
72
73
74
75
                                    <div>
                                        <span>Running</span>
                                        <p>{count.get('RUNNING')}</p>
                                    </div>
                                    <div>
                                        <span>Succeeded</span>
                                        <p>{count.get('SUCCEEDED')}</p>
                                    </div>
                                    <div>
                                        <span>Stopped</span>
                                        <p>{stoppedCount}</p>
                                    </div>
                                </Stack>
Lijiaoa's avatar
Lijiaoa committed
76
                                <Stack horizontal className='status-count marginTop' tokens={line2Tokens}>
77
78
79
80
81
82
83
84
85
86
87
88
                                    <div>
                                        <span>Failed</span>
                                        <p>{count.get('FAILED')}</p>
                                    </div>
                                    <div>
                                        <span>Waiting</span>
                                        <p>{count.get('WAITING')}</p>
                                    </div>
                                </Stack>
                            </div>

                            <div style={rightEidtParam}>
89
90
                                <EditExpeParamContext.Provider
                                    value={{
91
                                        title: MAX_TRIAL_NUMBERS,
liuzhe-lz's avatar
liuzhe-lz committed
92
                                        field: 'maxTrialNumber',
93
94
                                        editType: CONTROLTYPE[1],
                                        maxExecDuration: '',
95
                                        maxTrialNum: EXPERIMENT.maxTrialNumber,
96
97
98
99
                                        trialConcurrency: EXPERIMENT.profile.params.trialConcurrency,
                                        updateOverviewPage
                                    }}
                                >
100
101
102
                                    <div className='maxTrialNum'>
                                        <EditExperimentParam />
                                    </div>
103
                                </EditExpeParamContext.Provider>
104
105
106
107
108
109
110
111
                                <div className='concurrency'>
                                    <EditExpeParamContext.Provider
                                        value={{
                                            title: 'Concurrency',
                                            field: 'trialConcurrency',
                                            editType: CONTROLTYPE[2],
                                            // maxExecDuration: EXPERIMENT.profile.params.maxExecDuration,
                                            maxExecDuration: '',
112
                                            maxTrialNum: EXPERIMENT.maxTrialNumber,
113
114
115
116
117
118
119
                                            trialConcurrency: EXPERIMENT.profile.params.trialConcurrency,
                                            updateOverviewPage
                                        }}
                                    >
                                        <EditExperimentParam />
                                    </EditExpeParamContext.Provider>
                                </div>
120
121
                            </div>
                        </Stack>
122
123
124
125
126
127
                    </React.Fragment>
                );
            }}
        </ExpDurationContext.Consumer>
    );
};