Skip to content
83 changes: 50 additions & 33 deletions lib/public/views/Runs/Overview/RunsWithQcModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class RunsWithQcModel extends RunsOverviewModel {
constructor(model) {
super(model);

this._observablesQcFlagsSummaryDependsOn$ = null;
this._mcReproducibleAsNotBad = false;

this._runDetectorsSelectionModel = new RunDetectorsSelectionModel();
Expand Down Expand Up @@ -131,57 +132,73 @@ export class RunsWithQcModel extends RunsOverviewModel {
*/
async load() {
this._runDetectorsSelectionModel.reset();
this._fetchQcSummary();
// Only fetch QC summary manually if no observer is registered
if (!this._observablesQcFlagsSummaryDependsOn$) {
this._fetchQcSummary();
}
super.load();
}

/**
* Register not-bad fraction detectors filtering model
* Register not-bad fraction detectors filtering model and update it when detectors are loaded
* Also, trigger an immediate update if detectors are already loaded at the moment of registration
*
* @param {ObservableData<RemoteData<Detector>>} detectors$ detectors remote data observable
*/
registerDetectorsNotBadFractionFilterModels(detectors$) {
detectors$.observe((observableData) => observableData.getCurrent().apply({
Success: (detectors) => detectors.forEach(({ id }) => {
this._filteringModel.put(`detectorsQc[_${id}][notBadFraction]`, new NumericalComparisonFilterModel({
scale: 0.01,
integer: false,
}));
}),
}));
const callback = (observableData) => {
const current = observableData.getCurrent();
current?.apply({
Success: (detectors) => detectors.forEach(({ id }) => {
this._filteringModel.put(`detectorsQc[_${id}][notBadFraction]`, new NumericalComparisonFilterModel({
scale: 0.01,
integer: false,
}));
}),
});
};
detectors$.observe(callback);
callback(detectors$);
}

/**
* Register detectors for QC flags data export
* Register detectors for QC flags data export and update export configuration when detectors are loaded
* Also, trigger an immediate update if detectors are already loaded at the moment of registration
*
* @param {ObservableData<RemoteData<Detector>>} detectors$ detectors remote data observable
*/
registerDetectorsForQcFlagsDataExport(detectors$) {
detectors$.observe((observableData) => observableData.getCurrent().apply({
Success: (detectors) => {
this._exportModel.setDataExportConfiguration({
...baseDataExportConfiguration,
...qcFlagsExportConfigurationFactory(detectors),
});
},
Other: () => null,
}));
const callback = (observableData) => {
const current = observableData.getCurrent();
current?.apply({
Success: (detectors) => {
this._exportModel.setDataExportConfiguration({
...baseDataExportConfiguration,
...qcFlagsExportConfigurationFactory(detectors),
});
},
Other: () => null,
});
};
detectors$.observe(callback);
// Also trigger immediately if detectors are already loaded
callback(detectors$);
}

/**
* Register obervables data, which QC flags fetching operation success dependes on
* Register observables data, which QC flags fetching operation success depends on
*
* @param {ObservableData<RemoteData>[]} observables obervable data list
* @param {ObservableData<RemoteData<Detector>>} detectors$ observable data which QC flags fetching operation success depends on
*/
registerObervablesQcSummaryDependesOn(observables) {
this._observablesQcFlagsSummaryDepndsOn$ = ObservableData
.builder()
.sources(observables)
.apply((remoteDataList) => mergeRemoteData(remoteDataList))
.build();

this._observablesQcFlagsSummaryDepndsOn$
.observe((observableData) => observableData.getCurrent().apply({ Success: () => this._fetchQcSummary() }));
registerObservablesQcSummaryDependsOn(detectors$) {
this._observablesQcFlagsSummaryDependsOn$ = detectors$;
const callback = (observableData) => {
const current = observableData.getCurrent();
current?.apply({ Success: () => this._fetchQcSummary() });
};
this._observablesQcFlagsSummaryDependsOn$.observe(callback);
// Also trigger immediately if detectors are already loaded
callback(this._observablesQcFlagsSummaryDependsOn$);
}

/**
Expand All @@ -208,8 +225,8 @@ export class RunsWithQcModel extends RunsOverviewModel {
async _fetchQcSummary() {
const qcSummaryScopeValid = Object.entries(this.qcSummaryScope).filter(([, id]) => id).length == 1;

if (qcSummaryScopeValid && this.detectors && this._observablesQcFlagsSummaryDepndsOn$.getCurrent()) {
mergeRemoteData([this.detectors, this._observablesQcFlagsSummaryDepndsOn$.getCurrent()]).match({
if (qcSummaryScopeValid && this.detectors && this._observablesQcFlagsSummaryDependsOn$?.getCurrent()) {
mergeRemoteData([this.detectors, this._observablesQcFlagsSummaryDependsOn$.getCurrent()]).match({
Success: async ([detectors]) => {
this._qcSummary$.setCurrent(RemoteData.loading());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
.build();

this._detectors$.bubbleTo(this);
this.registerDetectorsNotBadFractionFilterModels(this._detectors$);
this.registerDetectorsForQcFlagsDataExport(this._detectors$);
this.registerObervablesQcSummaryDependesOn([this._detectors$]);

this._markAsSkimmableRequestResult$ = new ObservableData(RemoteData.notAsked());
this._markAsSkimmableRequestResult$.bubbleTo(this);
Expand Down Expand Up @@ -135,6 +132,11 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
},
Other: () => null,
}));

this.registerDetectorsNotBadFractionFilterModels(this._detectors$);
this.registerDetectorsForQcFlagsDataExport(this._detectors$);
this.registerObservablesQcSummaryDependsOn(this._detectors$);

super.load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export class RunsPerLhcPeriodOverviewModel extends FixedPdpBeamTypeRunsOverviewM
}))
.build();

this.registerDetectorsForQcFlagsDataExport(this._syncDetectors$);
this.registerObervablesQcSummaryDependesOn([this._syncDetectors$]);

this._syncDetectors$.bubbleTo(this);
this._onlineDetectors$.bubbleTo(this);
this._lhcPeriodStatistics$.bubbleTo(this);
Expand Down Expand Up @@ -82,12 +79,15 @@ export class RunsPerLhcPeriodOverviewModel extends FixedPdpBeamTypeRunsOverviewM
return;
}

await this._fetchLhcPeriod().then(() => {
this._lhcPeriodStatistics$.getCurrent().match({
Success: ({ pdpBeamTypes }) => this.setPdpBeamTypes(pdpBeamTypes),
Other: () => null,
});
await this._fetchLhcPeriod();
this._lhcPeriodStatistics$.getCurrent().match({
Success: ({ pdpBeamTypes }) => this.setPdpBeamTypes(pdpBeamTypes),
Other: () => null,
});

this.registerDetectorsForQcFlagsDataExport(this._syncDetectors$);
this.registerObservablesQcSummaryDependsOn(this._syncDetectors$);

super.load();
}

Expand Down
18 changes: 16 additions & 2 deletions lib/public/views/Runs/RunsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ export class RunsModel extends Observable {
loadPerDataPassOverview({ dataPassId }) {
if (!this._perDataPassOverviewModel.pagination.isInfiniteScrollEnabled) {
this._perDataPassOverviewModel.dataPassId = parseInt(dataPassId, 10);
this._perDataPassOverviewModel.load();
if (this._perDataPassOverviewModel.pagination._defaultItemsPerPage) {
/**
* If the default items per page is set, it means model has loaded already once,
* so the pagination trigger will not refresh the data.
* Thus, we need to trigger the load here.
*/
this._perDataPassOverviewModel.load();
}
}
}

Expand All @@ -135,7 +142,14 @@ export class RunsModel extends Observable {
loadPerSimulationPassOverview({ simulationPassId }) {
if (!this._perSimulationPassOverviewModel.pagination.isInfiniteScrollEnabled) {
this._perSimulationPassOverviewModel.simulationPassId = parseInt(simulationPassId, 10);
this._perSimulationPassOverviewModel.load();
if (this._perSimulationPassOverviewModel.pagination._defaultItemsPerPage) {
/**
* If the default items per page is set, it means model has loaded already once,
* so the pagination trigger will not refresh the data.
* Thus, we need to trigger the load here.
*/
this._perSimulationPassOverviewModel.load();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class RunsPerSimulationPassOverviewModel extends FixedPdpBeamTypeRunsOver

this._detectors$ = rctDetectorsProvider.qc$;

this.registerObervablesQcSummaryDependesOn([this._detectors$]);
this.registerDetectorsNotBadFractionFilterModels(this._detectors$);
this.registerDetectorsForQcFlagsDataExport(this._detectors$);

this._detectors$.bubbleTo(this);
this._simulationPass$.bubbleTo(this);
}
Expand All @@ -61,12 +57,16 @@ export class RunsPerSimulationPassOverviewModel extends FixedPdpBeamTypeRunsOver
return;
}

this._fetchSimulationPass().then(() => {
this._simulationPass$.getCurrent().match({
Success: ({ pdpBeamTypes }) => this.setPdpBeamTypes(pdpBeamTypes),
Other: () => null,
});
await this._fetchSimulationPass();
this._simulationPass$.getCurrent().match({
Success: ({ pdpBeamTypes }) => this.setPdpBeamTypes(pdpBeamTypes),
Other: () => null,
});

this.registerDetectorsNotBadFractionFilterModels(this._detectors$);
this.registerDetectorsForQcFlagsDataExport(this._detectors$);
this.registerObservablesQcSummaryDependsOn(this._detectors$);

super.load();
}

Expand Down
Loading