Skip to content

Commit 6c8a17f

Browse files
author
NarrowsProjects
committed
feat: create summary view for data pass and data pass versions
1 parent fbb9974 commit 6c8a17f

7 files changed

Lines changed: 109 additions & 52 deletions

File tree

lib/database/adapters/DataPassAdapter.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DataPassAdapter {
2020
*/
2121
constructor() {
2222
this.toEntity = this.toEntity.bind(this);
23+
this.toSummary = this.toSummary.bind(this);
2324
this.dataPassVersionAdapter = null;
2425
}
2526

@@ -30,13 +31,22 @@ class DataPassAdapter {
3031
* @returns {DataPass} Converted entity object.
3132
*/
3233
toEntity(databaseObject) {
33-
const {
34-
id,
35-
name,
36-
versions,
37-
skimmingStage,
38-
isFrozen,
39-
} = databaseObject;
34+
const { versions = [] } = databaseObject;
35+
36+
const entity = this.toSummary(databaseObject);
37+
entity.versions = versions.map(this.dataPassVersionAdapter.toEntity);
38+
39+
return entity
40+
}
41+
42+
/**
43+
* Converts the given database object to an entity object.
44+
*
45+
* @param {SequelizeDataPass} databaseObject Object to convert.
46+
* @returns {DataPass} Converted entity object.
47+
*/
48+
toSummary(databaseObject) {
49+
const { id, name, skimmingStage, versions = [], isFrozen } = databaseObject;
4050

4151
const runsCount = databaseObject.get('runsCount');
4252
const simulationPassesCount = databaseObject.get('simulationPassesCount');
@@ -45,9 +55,9 @@ class DataPassAdapter {
4555
return {
4656
id,
4757
name,
48-
skimmingStage,
49-
versions: (versions ?? []).map(this.dataPassVersionAdapter.toEntity),
58+
versions: versions.map(this.dataPassVersionAdapter.toSummary),
5059
pdpBeamTypes,
60+
skimmingStage,
5161
runsCount,
5262
simulationPassesCount,
5363
isFrozen,

lib/database/adapters/DataPassVersionAdapter.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DataPassVersionAdapter {
2020
*/
2121
constructor() {
2222
this.toEntity = this.toEntity.bind(this);
23+
this.toSummary = this.toSummary.bind(this);
2324
this.dataPassVersionStatusAdapter = null;
2425
}
2526

@@ -30,32 +31,39 @@ class DataPassVersionAdapter {
3031
* @returns {DataPass} Converted entity object.
3132
*/
3233
toEntity(databaseObject) {
34+
const entity = this.toSummary(databaseObject)
35+
const { id, dataPassId, lastSeen, statusHistory = [], createdAt, updatedAt } = databaseObject;
36+
37+
entity.statusHistory = statusHistory.map(this.dataPassVersionStatusAdapter.toEntity);
38+
entity.id = id;
39+
entity.dataPassId = dataPassId;
40+
entity.lastSeen = lastSeen;
41+
entity.createdAt = createdAt ? new Date(createdAt).getTime() : null;
42+
entity.updatedAt = updatedAt ? new Date(updatedAt).getTime() : null;
43+
44+
45+
return entity;
46+
}
47+
48+
/**
49+
* Converts the given database object to an summary object.
50+
*
51+
* @param {SequelizeDataPass} databaseObject Object to convert.
52+
* @returns {DataPass} Converted summary object.
53+
*/
54+
toSummary(databaseObject) {
3355
const {
34-
id,
35-
dataPassId,
3656
description,
3757
reconstructedEventsCount,
3858
outputSize,
39-
lastSeen,
40-
4159
statusHistory = [],
42-
43-
createdAt,
44-
updatedAt,
4560
} = databaseObject;
4661

4762
return {
48-
id,
49-
dataPassId,
5063
description,
5164
reconstructedEventsCount,
5265
outputSize,
53-
lastSeen,
54-
55-
statusHistory: (statusHistory ?? []).map(this.dataPassVersionStatusAdapter.toEntity),
56-
57-
createdAt: createdAt ? new Date(createdAt).getTime() : null,
58-
updatedAt: updatedAt ? new Date(updatedAt).getTime() : null,
66+
statusHistory: statusHistory.map(this.dataPassVersionStatusAdapter.toSummary),
5967
};
6068
}
6169
}

lib/database/adapters/DataPassVersionStatusAdapter.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ class DataPassVersionStatusAdapter {
4343
createdAt: createdAt ? new Date(createdAt).getTime() : null,
4444
};
4545
}
46+
47+
/**
48+
* Converts the given database object to an summary object.
49+
*
50+
* @param {SequelizeDataPassVersionStatus} databaseObject Object to convert.
51+
* @returns {DataPassVersionStatus} Converted summary object.
52+
*/
53+
toSummary(databaseObject) {
54+
const { status } = databaseObject;
55+
return { status };
56+
}
4657
}
4758

4859
module.exports = { DataPassVersionStatusAdapter };

lib/server/services/dataPasses/DataPassService.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const { BadParameterError } = require('../../errors/BadParameterError');
2323
const { SkimmingStage } = require('../../../domain/enums/SkimmingStage');
2424
const { LogManager } = require('@aliceo2/web-ui');
2525
const { NonPhysicsProductionsNamesWords } = require('../../../domain/enums/NonPhysicsProductionsNamesWords.js');
26+
const { dataPassSumary, dataPassVersionSummary } = require('../../views/dataPasses/summary.js');
2627

2728
/**
2829
* @typedef DataPassIdentifier
@@ -141,12 +142,17 @@ class DataPassService {
141142
queryBuilder.where('name').not().substring(`\\_${NonPhysicsProductionsNamesWords.DEBUG}`);
142143
}
143144

145+
queryBuilder.selectAttributes([...dataPassSumary.attributes])
146+
144147
const { count, rows } = await DataPassRepository.findAndCountAll(queryBuilder);
145-
const dataPassesVersions = await DataPassVersionRepository.findAll({
146-
include: 'statusHistory',
147-
where: { dataPassId: { [Op.in]: rows.map(({ id }) => id) } },
148-
order: [['statusHistory', 'createdAt', 'ASC']],
149-
});
148+
const dataPassVersionsQueryBuilder = dataSource.createQueryBuilder();
149+
150+
dataPassVersionsQueryBuilder.selectAttributes([...dataPassVersionSummary.attributes]);
151+
dataPassVersionsQueryBuilder.includeAll([...dataPassVersionSummary.include]);
152+
dataPassVersionsQueryBuilder.where('dataPassId').oneOf(...rows.map(({ id }) => id));
153+
dataPassVersionsQueryBuilder.pushOrders([...dataPassVersionSummary.order]);
154+
const dataPassesVersions = await DataPassVersionRepository.findAll(dataPassVersionsQueryBuilder);
155+
150156
const dataPassIdToVersions = dataPassesVersions.reduce((acc, version) => {
151157
const { dataPassId } = version;
152158
acc[dataPassId] = [...acc[dataPassId] ?? [], version];
@@ -159,7 +165,7 @@ class DataPassService {
159165

160166
return {
161167
count: count.length, // When using grouping sequelize returns from finAndCountAll counts per each group
162-
rows: rows.map(dataPassAdapter.toEntity),
168+
rows: rows.map(dataPassAdapter.toSummary),
163169
};
164170
}
165171

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
export const dataPassSumary = {
15+
attributes: ['id', 'name', 'skimmingStage', 'isFrozen'],
16+
};
17+
18+
export const dataPassVersionSummary = {
19+
attributes: ['outputSize', 'reconstructedEventsCount', 'description', 'dataPassId'],
20+
include: [{ association: 'statusHistory', attributes: ['status'] }],
21+
order: [['statusHistory', 'createdAt', 'ASC']]
22+
};

test/api/dataPasses.test.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,18 @@ const { Op } = require('sequelize');
2222
const { buildUrl } = require('@aliceo2/web-ui');
2323
const { BkpRoles } = require('../../lib/domain/enums/BkpRoles.js');
2424

25-
const LHC22b_apass1 = {
25+
const LHC22b_apass1_summary = {
2626
id: 1,
2727
name: 'LHC22b_apass1',
2828
pdpBeamTypes: ['pp'],
2929
skimmingStage: SkimmingStage.SKIMMABLE,
3030
isFrozen: false,
3131
versions: [
3232
{
33-
id: 1,
34-
dataPassId: 1,
3533
description: 'Some random desc',
3634
reconstructedEventsCount: 50948694,
3735
outputSize: 56875682112600,
38-
lastSeen: 108,
39-
statusHistory: [
40-
{
41-
createdAt: 1704884400000,
42-
dataPassVersionId: 1,
43-
id: 1,
44-
status: 'Running',
45-
},
46-
{
47-
createdAt: 1704885060000,
48-
dataPassVersionId: 1,
49-
id: 2,
50-
status: 'Deleted',
51-
},
52-
],
53-
createdAt: 1704884400000,
54-
updatedAt: 1704884400000,
36+
statusHistory: [{ status: 'Running' }, { status: 'Deleted' }],
5537
},
5638
],
5739
runsCount: 3,
@@ -94,7 +76,7 @@ module.exports = () => {
9476
expect(meta).to.be.eql({ page: { totalCount: 1, pageCount: 1 } });
9577
expect(data).to.be.an('array');
9678
expect(data).to.be.lengthOf(1);
97-
expect(data[0]).to.be.eql(LHC22b_apass1);
79+
expect(data[0]).to.be.eql(LHC22b_apass1_summary);
9880

9981
done();
10082
});

test/lib/server/services/dataPasses/DataPassService.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ const LHC22b_apass1 = {
5959
simulationPassesCount: 1,
6060
};
6161

62+
const LHC22b_apass1_summary = {
63+
id: 1,
64+
name: 'LHC22b_apass1',
65+
pdpBeamTypes: ['pp'],
66+
skimmingStage: SkimmingStage.SKIMMABLE,
67+
isFrozen: false,
68+
versions: [
69+
{
70+
description: 'Some random desc',
71+
reconstructedEventsCount: 50948694,
72+
outputSize: 56875682112600,
73+
statusHistory: [{ status: 'Running' }, { status: 'Deleted' }],
74+
},
75+
],
76+
runsCount: 3,
77+
simulationPassesCount: 1,
78+
};
79+
6280
module.exports = () => {
6381
before(resetDatabaseContent);
6482

@@ -95,7 +113,7 @@ module.exports = () => {
95113
};
96114
const { rows: dataPasses } = await dataPassService.getAll(dto.query);
97115
expect(dataPasses).to.be.lengthOf(1);
98-
expect(dataPasses[0]).to.be.eql(LHC22b_apass1);
116+
expect(dataPasses[0]).to.be.eql(LHC22b_apass1_summary);
99117
});
100118

101119
it('should successfully filter data passes on ids', async () => {

0 commit comments

Comments
 (0)