Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/database/adapters/RunAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class RunAdapter {
*/
this.userAdapter = null;

/**
* @type {QcFlagAdapter|null}
*/
this.qcFlagAdapter = null;

this.toEntity = this.toEntity.bind(this);
this.toDatabase = this.toDatabase.bind(this);
this.toMinifiedEntity = this.toMinifiedEntity.bind(this);
Expand Down Expand Up @@ -167,6 +172,7 @@ class RunAdapter {
phaseShiftAtEndBeam2,
userStart,
userStop,
qcFlags,
} = databaseObject;

/**
Expand Down Expand Up @@ -281,6 +287,13 @@ class RunAdapter {
entityObject.muInelasticInteractionRate = null;
}

const adaptedQcFlags = qcFlags ? qcFlags.map(this.qcFlagAdapter.toEntity) : [];
entityObject.qcFlags = adaptedQcFlags.reduce((acc, qcFlag) => {
acc[qcFlag.dplDetectorId] = acc[qcFlag.dplDetectorId] ?? [];
acc[qcFlag.dplDetectorId].push(qcFlag);
return acc;
}, {});

return entityObject;
}

Expand Down
1 change: 1 addition & 0 deletions lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ runAdapter.logAdapter = logAdapter;
runAdapter.runTypeAdapter = runTypeAdapter;
runAdapter.tagAdapter = tagAdapter;
runAdapter.userAdapter = userAdapter;
runAdapter.qcFlagAdapter = qcFlagAdapter;

simulationPassQcFlagAdapter.simulationPassAdapter = simulationPassAdapter;
simulationPassQcFlagAdapter.qcFlagAdapter = qcFlagAdapter;
Expand Down
6 changes: 6 additions & 0 deletions lib/database/seeders/20240404100811-qc-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ module.exports = {
from: '2019-08-08 13:46:40',
to: '2019-08-09 07:50:00',
},
{
id: 6,
flag_id: 6,
from: '2019-08-09 08:50:00',
to: null,
},
{
id: 7,
flag_id: 7,
Expand Down
10 changes: 10 additions & 0 deletions lib/domain/dtos/GetAllRunsDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const QueryDto = Joi.object({
filter: RunFilterDto,
page: PaginationDto,
sort: DtoFactory.order(['id', 'runNumber', 'text']),
include: Joi.object({ effectiveQcFlags: Joi.boolean().custom((effectiveQcFlags, helpers) => {
const [, { filter: { dataPassIds, simulationPassIds, lhcPeriodIds } = {} }] = helpers.state.ancestors;
const runsCollectionFilters = [dataPassIds, simulationPassIds, lhcPeriodIds].filter(({ length } = {}) => length >= 1);
if (runsCollectionFilters.length !== 1 || runsCollectionFilters[0].length !== 1) {
return helpers.message('Including effectiveQcFlags is allowed only when filtering by one nd exactly one of: ' +
'dataPassIds, simulationPassIds, lhcPeriodIds with exactly one ID.');
}

return effectiveQcFlags;
}) }),
token: Joi.string(),
});

Expand Down
1 change: 1 addition & 0 deletions lib/domain/dtos/filters/RunFilterDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ exports.RunFilterDto = Joi.object({
odcTopologyFullName: Joi.string().trim(),
detectors: DetectorsFilterDto,
lhcPeriods: Joi.string().trim(),
lhcPeriodIds: Joi.array().items(Joi.number().positive().integer()),
dataPassIds: Joi.array().items(Joi.number()),
simulationPassIds: Joi.array().items(Joi.number()),
runTypes: CustomJoi.stringArray().items(Joi.string()).single().optional(),
Expand Down
207 changes: 207 additions & 0 deletions lib/public/models/DataExportModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/**
* @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 { Observable } from '/js/src/index.js';
import { createCSVExport, createJSONExport } from '../utilities/export.js';
import pick from '../utilities/pick.js';

/**
* @typedef FieldExportConfiguration
*
* @property {function|null} exportFormat
*/

/**
* @typdef DataExportConfiguration
*
* @type {object<string, FieldExportConfiguration>} mapping: field name -> field export configuration
*/

/**
* Model handling export configuration and creation
*/
export class DataExportModel extends Observable {
/**
* Constructor
*
* @param {ObservableData<RemoteData<T[]>>} items$ observable data used as source for export
* @param {DataExportConfiguration} dataExportConfiguration defines selectable fields and their formatting
* @param {function} onDataNotAskedAction function to be called in case of missing data
*/
constructor(items$, dataExportConfiguration, onDataNotAskedAction) {
super();

this._items$ = items$;
this._items$.bubbleTo(this);

this._selectedFields = [];

this._selectedExportType = 'JSON';

this._visualChange$ = new Observable();

this._exportName = 'data';

this._dataExportConfiguration = dataExportConfiguration;
this._onDataNotAskedAction = onDataNotAskedAction;

this._disabled = null;

this._totalExistingItemsCount = null;
}

/**
* Get data export configuration
*
* @return {DataExportConfiguration} configuration
*/
get dataExportConfiguration() {
return this._dataExportConfiguration;
}

/**
* Get total number of items that model knows they exist
*
* @return {number} totalExistingItemsCount
*/
get totalExistingItemsCount() {
return this._totalExistingItemsCount;
}

/**
* Set total number of items that model should they exist
* @param {number} totalExistingItemsCount count
*/
setTotalExistingItemsCount(totalExistingItemsCount) {
this._totalExistingItemsCount = totalExistingItemsCount;
}

/**
* State whether exporting is enabled
* @return {boolean} if true disabled, otherwise enabled
*/
get disabled() {
return this._disabled;
}

/**
* Set whether exporting is enabled
* @param {boolean} disabled if true disabled, otherwise enabled
*/
setDisabled(disabled) {
this._disabled = disabled;
}

/**
* If the model has no data to be exported, it calls for it via action function provided in constructor
* @return {Promise<void>|null} promise if data were not asked for, null otherwise
*/
callForData() {
if (this._onDataNotAskedAction) {
return this.items.match({
NotAsked: () => this._onDataNotAskedAction(),
Other: () => null,
});
} else {
throw new Error('onDataNotAskedAction was not provided');
}
}

/**
* Return the current items remote data
*
* @return {RemoteData<T[]>} the items
*/
get items() {
return this._items$.getCurrent();
}

/**
* Observable notified when the export configuration visually changes
*
* @return {Observable} the visual change observable
*/
get visualChange$() {
return this._visualChange$;
}

/**
* Get export type selected by the user
*
* @return {string} export type
*/
get selectedExportType() {
return this._selectedExportType;
}

/**
* Set export type
*
* @param {string} exportType export type
* @return {void}
*/
setSelectedExportType(exportType) {
this._selectedExportType = exportType;
this.notify();
this._visualChange$.notify();
}

/**
* Get selected fields
*
* @return {string[]} selected fields
*/
get selectedFields() {
return this._selectedFields;
}

/**
* Update selected fields from HTML options list
*
* @param {HTMLCollection|Array} selectedOptions options collection
* @return {void}
*/
setSelectedFields(selectedOptions) {
this._selectedFields = [];
[...selectedOptions].forEach(({ value }) => this._selectedFields.push(value));
this.notify();
this._visualChange$.notify();
}

/**
* Create export using current items observable
*
* @return {Promise<void>} void
*/
async createExport() {
this.items.apply({
Success: (items) => {
const { selectedFields } = this;

const formatted = items.map((item) => {
const selectedEntries = Object.entries(pick(item, selectedFields));
const mappedEntries = selectedEntries.map(([key, value]) => {
const formatter = this.dataExportConfiguration[key]?.exportFormat || ((v) => v);
return [key, formatter(value, item)];
});

return Object.fromEntries(mappedEntries);
});

this.selectedExportType === 'CSV'
? createCSVExport(formatted, `${this._exportName}.csv`, 'text/csv;charset=utf-8;')
: createJSONExport(formatted, `${this._exportName}.json`, 'application/json');
},
});
}
}
Loading
Loading