experimentsManager.ts 1.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { MANAGER_IP } from '../const';
import { AllExperimentList } from '../interface';
import { requestAxios } from '../function';

class ExperimentsManager {
    private experimentList: AllExperimentList[] = [];
    private platform: string[] = [];
    private errorMessage: string = '';

    public getExperimentList(): AllExperimentList[] {
        return this.experimentList;
    }

    public getPlatformList(): string[] {
        return this.platform;
    }

    public getExpErrorMessage(): string {
        return this.errorMessage;
    }

    public async init(): Promise<void> {
        await requestAxios(`${MANAGER_IP}/experiments-info`)
            .then(data => {
                const platforms: Set<string> = new Set();
                for (const item of data) {
                    if (item.port !== undefined) {
                        if (typeof item.port === 'string') {
                            item.port = JSON.parse(item.port);
                        }
                    }
                    platforms.add(item.platform);
                }
                this.experimentList = data;
                this.platform = Array.from(platforms);
            })
            .catch(error => {
                this.errorMessage = error.message;
            });
    }
}

export { ExperimentsManager };