-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathRunsPerLhcPeriodOverviewModel.js
More file actions
227 lines (206 loc) · 6.74 KB
/
Copy pathRunsPerLhcPeriodOverviewModel.js
File metadata and controls
227 lines (206 loc) · 6.74 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { buildUrl, RemoteData } from '/js/src/index.js';
import { TabbedPanelModel } from '../../../components/TabbedPanel/TabbedPanelModel.js';
import { detectorsProvider } from '../../../services/detectors/detectorsProvider.js';
import { jsonFetch } from '../../../utilities/fetch/jsonFetch.js';
import { DetectorType } from '../../../domain/enums/DetectorTypes.js';
import { ObservableData } from '../../../utilities/ObservableData.js';
import { FixedPdpBeamTypeRunsOverviewModel } from '../Overview/FixedPdpBeamTypeRunsOverviewModel.js';
export const RUNS_PER_LHC_PERIOD_PANELS_KEYS = {
DETECTOR_QUALITIES: 'detectorQualities',
SYNCHRONOUS_FLAGS: 'synchronousFlags',
};
/**
* Runs Per LHC Period overview model
*/
export class RunsPerLhcPeriodOverviewModel extends FixedPdpBeamTypeRunsOverviewModel {
/**
* Constructor
*
* @param {Model} model global model
*/
constructor(model) {
super(model);
this._onlineDetectors$ = detectorsProvider.physical$;
this._onlineDetectors$.bubbleTo(this);
this._syncDetectors$ = ObservableData
.builder()
.source(detectorsProvider.qc$)
.apply((remoteDetectors) =>
remoteDetectors.apply({
Success: (detectors) => detectors.filter(({ type }) => [DetectorType.PHYSICAL, DetectorType.MUON_GLO].includes(type)),
}))
.build();
this._syncDetectors$.bubbleTo(this);
this._lhcPeriodId = null;
this._lhcPeriodStatistics$ = new ObservableData(RemoteData.notAsked());
this._lhcPeriodStatistics$.bubbleTo(this);
this._tabbedPanelModel = new RunsPerLhcPeriodTabbedPanelModel();
this._tabbedPanelModel.bubbleTo(this);
}
/**
* Fetch LHC period data which runs are fetched
* @return {Promise<void>} promise
*/
async _fetchLhcPeriod() {
this._lhcPeriodStatistics$.setCurrent(RemoteData.loading());
try {
const { data: [lhcPeriodStatistics] } = await jsonFetch(`/api/lhcPeriodsStatistics?filter[ids][]=${this._lhcPeriodId}`);
this._lhcPeriodStatistics$.setCurrent(RemoteData.success(lhcPeriodStatistics));
} catch (error) {
this._lhcPeriodStatistics$.setCurrent(RemoteData.failure(error));
}
}
/**
* @inheritdoc
*/
async load() {
if (!this._lhcPeriodId) {
return;
}
await this._fetchLhcPeriod().then(() => {
this._lhcPeriodStatistics$.getCurrent().match({
Success: ({ pdpBeamTypes }) => this.setPdpBeamTypes(pdpBeamTypes),
Other: () => null,
});
});
super.load();
}
/**
* @inheritdoc
*/
getRootEndpoint() {
return buildUrl(super.getRootEndpoint(), {
filter: {
lhcPeriodIds: [this._lhcPeriodId],
runQualities: 'good',
definitions: 'PHYSICS',
},
});
}
/**
* Get LHC period which runs are fetched
*/
get lhcPeriodStatistics() {
return this._lhcPeriodStatistics$.getCurrent();
}
/**
* Set id of current LHC period which runs are fetched
*
* @param {string} lhcPeriodId id of a LHC period
*/
set lhcPeriodId(lhcPeriodId) {
this._lhcPeriodId = lhcPeriodId;
this._tabbedPanelModel.lhcPeriodId = lhcPeriodId;
}
/**
* Set mcReproducibleAsNotBad flag
*
* @param {boolean} mcReproducibleAsNotBad new value
*/
setMcReproducibleAsNotBad(mcReproducibleAsNotBad) {
super.setMcReproducibleAsNotBad(mcReproducibleAsNotBad);
this._tabbedPanelModel.mcReproducibleAsNotBad = mcReproducibleAsNotBad;
}
/**
* Get all detectors
*
* @return {RemoteData<Detector[]>} detectors
*/
get onlineDetectors() {
return this._onlineDetectors$.getCurrent();
}
/**
* Get all detectors for synchronous QC flags
*
* @return {RemoteData<Detector[]>} detectors
*/
get syncDetectors() {
return this._syncDetectors$.getCurrent();
}
/**
* Returns the model for the tabbed component
*
* @return {RunsPerLhcPeriodTabbedPanelModel} the tabbed component model
*/
get tabbedPanelModel() {
return this._tabbedPanelModel;
}
}
/**
* RunsPerLhcPeriodTabbedPanelModel
*/
class RunsPerLhcPeriodTabbedPanelModel extends TabbedPanelModel {
/**
* Constructor
*/
constructor() {
super(Object.values(RUNS_PER_LHC_PERIOD_PANELS_KEYS));
}
/**
* @inheritDoc
*/
_fetchCurrentPanelData() {
switch (this.currentPanelKey) {
case RUNS_PER_LHC_PERIOD_PANELS_KEYS.DETECTOR_QUALITIES:
this.currentPanelData = null;
break;
case RUNS_PER_LHC_PERIOD_PANELS_KEYS.SYNCHRONOUS_FLAGS:
this._fetchSynchronousQcSummary();
break;
}
}
/**
* Fetch QC summary for synchronous QC flags
*
* @return {Promise<void>} resolved once data are fetched
*/
async _fetchSynchronousQcSummary() {
if (this._lhcPeriodId) {
this.currentPanelData = RemoteData.loading();
this.notify();
try {
const { data: qcSummary } = await jsonFetch(buildUrl(
'/api/qcFlags/summary',
{
lhcPeriodId: this._lhcPeriodId,
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
},
));
this.currentPanelData = RemoteData.success(qcSummary);
} catch (errors) {
this.currentPanelData = RemoteData.failure(errors);
}
this.notify();
}
}
/**
* Set LHC period id
*
* @param {id} lhcPeriodId id of LHC period
*/
set lhcPeriodId(lhcPeriodId) {
this._lhcPeriodId = lhcPeriodId;
this._fetchCurrentPanelData();
}
/**
* Set mcReproducibleAsNotBad flag
*
* @param {boolean} mcReproducibleAsNotBad new value
*/
set mcReproducibleAsNotBad(mcReproducibleAsNotBad) {
this._mcReproducibleAsNotBad = mcReproducibleAsNotBad;
this._fetchCurrentPanelData();
}
}