TrialCount.tsx 5.29 KB
Newer Older
1
import * as React from 'react';
2
import { Stack, IStackTokens } from '@fluentui/react';
Lijiaoa's avatar
Lijiaoa committed
3
import { EXPERIMENT, TRIALS } from '@static/datamodel';
4
import { CONTROLTYPE, MAX_TRIAL_NUMBERS } from '@static/const';
5
import { EditExperimentParam } from './EditExperimentParam';
6
import ProgressBar from './ProgressBar';
7
8
import { EditExpeParamContext } from './context';
import { ExpDurationContext } from './ExpDurationContext';
9
import { leftProgress, rightEditParam } from './commonStyle';
10

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

18
19
20
21
22
23
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;
24
    const maxTrialNum = EXPERIMENT.maxTrialNumber;
25
    // support type [0, 1], not 98%
26
    const bar2Percent = bar2 / maxTrialNum;
27
28
29
30
31
32
    return (
        <ExpDurationContext.Consumer>
            {(value): React.ReactNode => {
                const { updateOverviewPage } = value;
                return (
                    <React.Fragment>
33
34
35
36
37
38
                        <ProgressBar
                            tooltip={`${bar2.toString()} trials`}
                            percent={bar2Percent}
                            latestVal={String(bar2)}
                            presetVal={String(maxTrialNum)}
                        />
39
40
                        <Stack horizontal className='marginTop'>
                            <div style={leftProgress}>
Lijiaoa's avatar
Lijiaoa committed
41
                                <Stack horizontal className='status-count' tokens={line1Tokens}>
42
43
44
45
46
47
48
49
50
51
52
53
54
                                    <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
55
                                <Stack horizontal className='status-count marginTop' tokens={line2Tokens}>
56
57
58
59
60
61
62
63
64
65
66
                                    <div>
                                        <span>Failed</span>
                                        <p>{count.get('FAILED')}</p>
                                    </div>
                                    <div>
                                        <span>Waiting</span>
                                        <p>{count.get('WAITING')}</p>
                                    </div>
                                </Stack>
                            </div>

67
                            <div style={rightEditParam}>
68
69
                                <EditExpeParamContext.Provider
                                    value={{
70
                                        title: MAX_TRIAL_NUMBERS,
liuzhe-lz's avatar
liuzhe-lz committed
71
                                        field: 'maxTrialNumber',
72
73
                                        editType: CONTROLTYPE[1],
                                        maxExecDuration: '',
74
                                        maxTrialNum: EXPERIMENT.maxTrialNumber,
75
76
77
78
                                        trialConcurrency: EXPERIMENT.profile.params.trialConcurrency,
                                        updateOverviewPage
                                    }}
                                >
79
80
81
                                    <div className='maxTrialNum'>
                                        <EditExperimentParam />
                                    </div>
82
                                </EditExpeParamContext.Provider>
83
84
85
86
87
88
89
90
                                <div className='concurrency'>
                                    <EditExpeParamContext.Provider
                                        value={{
                                            title: 'Concurrency',
                                            field: 'trialConcurrency',
                                            editType: CONTROLTYPE[2],
                                            // maxExecDuration: EXPERIMENT.profile.params.maxExecDuration,
                                            maxExecDuration: '',
91
                                            maxTrialNum: EXPERIMENT.maxTrialNumber,
92
93
94
95
96
97
98
                                            trialConcurrency: EXPERIMENT.profile.params.trialConcurrency,
                                            updateOverviewPage
                                        }}
                                    >
                                        <EditExperimentParam />
                                    </EditExpeParamContext.Provider>
                                </div>
99
100
                            </div>
                        </Stack>
101
102
103
104
105
106
                    </React.Fragment>
                );
            }}
        </ExpDurationContext.Consumer>
    );
};