-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathEosReportService.js
More file actions
209 lines (191 loc) · 8.41 KB
/
EosReportService.js
File metadata and controls
209 lines (191 loc) · 8.41 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
/**
* @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.
*/
const { formatEosReport } = require('./formatEosReport.js');
const { getUserOrFail } = require('../user/getUserOrFail.js');
const { getTagsByText } = require('../tag/getTagsByText.js');
const { getShiftFromTimestamp } = require('../shift/getShiftFromTimestamp.js');
const { logService } = require('../log/LogService.js');
const { shiftService } = require('../shift/ShiftService');
const { getShiftIssues } = require('./getShiftIssues.js');
const { getShiftEnvironments } = require('../shift/getShiftEnvironments.js');
const { getEosReportTagsByType } = require('./eosTypeSpecificFormatter/getEosReportTagsByType.js');
const { ShiftTypes } = require('../../../domain/enums/ShiftTypes.js');
const { getShiftTagsFiltersByType } = require('../shift/getShiftTagsFiltersByType.js');
const { getShiftRuns } = require('../shift/getShiftRuns.js');
const { getShiftIssuesTagsOccurrences } = require('../log/getShiftIssuesTagsOccurrences.js');
/**
* @typedef EosReport
* @property {string} type
* @property {number} shiftStart start of the shift (UNIX timestamp in ms)
* @property {Log[]} issuesLogEntries
* @property {EcsEosReportTypeSpecific|QcPdpEosReportTypeSpecific|ShiftLeaderEosReportTypeSpecific|null} typeSpecific
* @property {string} shifterName
* @property {string} [traineeName]
* @property {string} [lhcTransitions]
* @property {string} [shiftFlow]
* @property {string} [infoFromPreviousShifter]
* @property {string} [infoForNextShifter]
* @property {string} [infoForRmRc]
*/
/**
* @typedef EcsEosReportTypeSpecific
* @property {SequelizeEnvironment[]} environments
* @property {object} environmentComments
* @property {object} runComments
*/
/**
* @typedef QcPdpEosReportTypeSpecific
* @property {Object<string, SequelizeRun[]>} runs
* @property {object} runComments
*/
/**
* @typedef EosReportMagnetInformation
* @property {{dipole: string, solenoid: string}} start the magnet information at the start of the shift
* @property {{timestamp: number, magnetsConfiguration: {dipole: string, solenoid: string}}[]} intermediates the list of intermediates magnet
* configuration
* @property {{dipole: string, solenoid: string}} end the magnet information at the end of the shift
*/
/**
* @typedef ShiftLeaderEosReportTypeSpecific
* @property {EosReportMagnetInformation} magnets magnet information at the start and the end of the shift
* @property {number} efficiency efficiency of the shift
* @property {SequelizeLog[]} shiftIssues the list of issues created during the shift relevant for ShiftLeader logs' tags counter
* @property {Object<string, SequelizeRun[]>} runs list of runs in the shifts, grouped by definition
*/
/**
* @typedef DcsEosReportTypeSpecific
* @property {string} alerts the DCS alerts concatenated
*/
/**
* Service to generate end of shift report
*/
class EosReportService {
/**
* Constructor
*/
constructor() {
}
/**
* Create an end of shift report log
*
* @param {string} reportType the type of EOS report
* @param {EosReportCreationRequest} reportCreationRequest the data of the EOS report
* @param {UserIdentifier} currentUserIdentifier the identifier of the current user creating the EOS report
* @return {Promise<Log>} resolves with the created log entry
*/
async createLogEntry(reportType, reportCreationRequest, currentUserIdentifier) {
const currentUser = await getUserOrFail(currentUserIdentifier);
const shift = getShiftFromTimestamp(reportCreationRequest.shiftStart);
const shiftIssues = await getShiftIssues(shift, getShiftTagsFiltersByType(reportType));
const infoFromPreviousShifter = await shiftService.getInfoFromPreviousShifter(shift, reportType);
/**
* @type {Partial<EosReport>}
*/
const eosReport = {
type: reportType,
shiftStart: reportCreationRequest.shiftStart,
shifterName: reportCreationRequest.shifterName,
traineeName: reportCreationRequest.traineeName,
issuesLogEntries: shiftIssues,
lhcTransitions: reportCreationRequest.lhcTransitions,
shiftFlow: reportCreationRequest.shiftFlow,
infoFromPreviousShifter: !infoFromPreviousShifter.errorMessage && infoFromPreviousShifter.value || '-',
infoForNextShifter: reportCreationRequest.infoForNextShifter,
infoForRmRc: reportCreationRequest.infoForRmRc,
};
const logRunNumbers = [];
const logEnvironmentIds = [];
switch (reportType) {
case ShiftTypes.ECS:
eosReport.typeSpecific = {
...await getEcsSpecificReportData(shift),
environmentComments: reportCreationRequest.typeSpecific.environmentComments,
runComments: reportCreationRequest.typeSpecific.runComments,
};
for (const { id, runs } of eosReport.typeSpecific.environments) {
logRunNumbers.push(...runs.map(({ runNumber }) => runNumber));
logEnvironmentIds.push(id);
}
break;
case ShiftTypes.QC_PDP:
eosReport.typeSpecific = {
...await getQcPdpSpecificReportData(shift),
runComments: reportCreationRequest.typeSpecific.runComments,
};
for (const runs of Object.values(eosReport.typeSpecific.runs)) {
logRunNumbers.push(...runs.map(({ runNumber }) => runNumber));
logEnvironmentIds.push(...runs.map(({ envId }) => envId).filter((id) => id));
}
break;
case ShiftTypes.SL:
eosReport.typeSpecific = {
...await getShiftLeaderSpecificReportData(shift),
magnets: reportCreationRequest.typeSpecific.magnets,
};
for (const runs of Object.values(eosReport.typeSpecific.runs)) {
logRunNumbers.push(...runs.map(({ runNumber }) => runNumber));
logEnvironmentIds.push(...runs.map(({ envId }) => envId).filter((id) => id));
}
break;
case ShiftTypes.DCS:
eosReport.typeSpecific = {
alerts: reportCreationRequest.typeSpecific.alerts,
};
break;
}
const report = await formatEosReport(eosReport);
return logService.create(
{
userId: currentUser.id,
title: report.substring(2, report.indexOf('\n')),
text: report,
subtype: 'comment',
origin: 'process',
},
logRunNumbers,
// Use only existing tags
(await getTagsByText(getEosReportTagsByType(reportType))).map(({ text }) => text),
logEnvironmentIds,
);
}
}
/**
* Returns the ECS-specific report data
*
* @param {Shift} shift the shift for which data should be fetched
* @return {Promise<EcsEosReportTypeSpecific>} the ECS EOS report type specific
*/
const getEcsSpecificReportData = async (shift) => ({
environments: await getShiftEnvironments(shift, ShiftTypes.ECS),
});
/**
* Returns the QC/PDP-specific report data
*
* @param {Shift} shift the shift for which data should be fetched
* @return {Promise<QcPdpEosReportTypeSpecific>} the QC/PDP report type specific
*/
const getQcPdpSpecificReportData = async (shift) => ({
runs: await getShiftRuns(shift, ShiftTypes.QC_PDP),
});
/**
* Returns the SL-specific report data
*
* @param {Shift} shift the shift for which data should be fetched
* @return {Promise<ShiftLeaderEosReportTypeSpecific>} the Shift Leader report type specific
*/
const getShiftLeaderSpecificReportData = async (shift) => ({
tagsCounters: await getShiftIssuesTagsOccurrences(shift),
runs: await getShiftRuns(shift, ShiftTypes.SL),
});
exports.EosReportService = EosReportService;
exports.eosReportService = new EosReportService();