Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ORCT-192] update legacy endpoint to handle migrated flags #233

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e5588f0
update get_run_det_data function
xsalonx Sep 28, 2023
1c6c914
adjust forntend to new api
xsalonx Sep 28, 2023
4f06acd
refactor flags view
xsalonx Sep 28, 2023
0c07959
refactor
xsalonx Sep 28, 2023
6334293
amend escaping
xsalonx Sep 28, 2023
b3c70d5
verification display amendment
xsalonx Sep 28, 2023
f409f9a
remove dead code
xsalonx Oct 5, 2023
029df9c
Merge branch 'master' into improvement/ORCT-192/update-legacy-endpoin…
xsalonx Oct 5, 2023
cd25622
structurize flags summary
xsalonx Oct 5, 2023
b4a80ae
return correct timestamps for entire qcf's
xsalonx Oct 5, 2023
d377c9b
add timestamp for flags_view
xsalonx Oct 5, 2023
c7660d0
add color for good
xsalonx Oct 5, 2023
c1f8d30
handle no qc data
xsalonx Oct 5, 2023
693a783
display no qc data
xsalonx Oct 5, 2023
a9bdf43
differentiate between synchronous and asynchronus flags
xsalonx Oct 5, 2023
dc3cc47
Merge branch 'master' into improvement/ORCT-192/update-legacy-endpoin…
xsalonx Oct 9, 2023
3278fef
refactor
xsalonx Oct 9, 2023
2ce9228
Merge branch 'master' into improvement/ORCT-192/update-legacy-endpoin…
xsalonx Oct 10, 2023
bf73d13
replace shortcuts
xsalonx Oct 10, 2023
89b001e
remove problematic data
xsalonx Oct 10, 2023
d37a4d4
amend invalid date
xsalonx Oct 10, 2023
e94f90e
apply the same formatting for verification time:
xsalonx Oct 10, 2023
fd752e2
use css instead of text objects
xsalonx Oct 10, 2023
31ce9d4
css
xsalonx Oct 10, 2023
bdb8310
refactor
xsalonx Oct 10, 2023
e6eca24
refactor
xsalonx Oct 10, 2023
72fd3e1
refactor
xsalonx Oct 10, 2023
f427ff9
simplify method and add docs
xsalonx Oct 10, 2023
eb69693
Merge branch 'master' into improvement/ORCT-192/update-legacy-endpoin…
xsalonx Oct 11, 2023
cb7abb0
refactor ternary operator
xsalonx Oct 11, 2023
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
37 changes: 23 additions & 14 deletions app/lib/database/views/flags_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,33 @@
* or submit itself to any jurisdiction.
*/


const handleArray = (data, field, escape) => {
let sqlLogicClause = undefined;
if (Array.isArray(data)) {
sqlLogicClause = data.map((d) => escape ? `'${d}'` : d).join(',');
} else if (typeof(data) === 'string' || !data) {
sqlLogicClause = escape ? `'${data}'` : data;
} else {
throw `incorrect format <${data}> for ${field}`;
/**
* Build part of sql where clause like 'FIELD_NAME in (...DATA...)';
* @param {Array<String>|String} data - data to be used to build logical clause
* @param {String} fieldName - field name in database
* @param {Boolean} isString - if true values from data are wrapped with single quote
* @returns {String|undefined} - logical clause
*/
const dataFieldToSQLBelongsLogicalClause = (data, fieldName, isString) => {
if (!data) {
return undefined;

Check warning on line 24 in app/lib/database/views/flags_view.js

View check run for this annotation

Codecov / codecov/patch

app/lib/database/views/flags_view.js#L24

Added line #L24 was not covered by tests
}
sqlLogicClause = sqlLogicClause ? `${field} in (${sqlLogicClause})` : undefined;

return sqlLogicClause;
if (!Array.isArray(data)) {
data = [data];
}
const rightOperand = (isString ? data.map((value) => `'${value}'`) : data).join(',');
return rightOperand ? `${fieldName} in (${rightOperand})` : undefined;
}

/**
* Build sql query to fetch quality control flags for
* one data pass and (if provided) given runs and detector subsystems
* @param {Object} query containing data_pass_name (single name), run_numbers (list), detector (list)
* @returns {String} sql query
*/
const flags_view = (query) => {
martinboulais marked this conversation as resolved.
Show resolved Hide resolved
run_selection_sql = handleArray(query.run_numbers, 'r.run_number')
detector_selection_sql = handleArray(query.detector, 'ds.name', true)
run_selection_sql = dataFieldToSQLBelongsLogicalClause(query.run_numbers, 'r.run_number')
detector_selection_sql = dataFieldToSQLBelongsLogicalClause(query.detector, 'ds.name', true)

const data_pass_sql = `dp.name = '${query.data_pass_name}'`;
const whereClause = [data_pass_sql, run_selection_sql, detector_selection_sql]
Expand Down
2 changes: 0 additions & 2 deletions app/lib/database/views/runs_views.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
const queryForRunsFields = `
--p.name,
r.run_number,
EXTRACT(EPOCH FROM COALESCE(r.time_trg_start, r.time_o2_start)) * 1000 as time_start,
EXTRACT(EPOCH FROM COALESCE(r.time_trg_end, r.time_o2_end)) * 1000 as time_end,
extract( epoch from r.time_o2_start ) * 1000 as time_o2_start,
extract( epoch from r.time_o2_end ) * 1000 as time_o2_end,
extract( epoch from r.time_trg_start ) * 1000 as time_trg_start,
Expand Down
2 changes: 1 addition & 1 deletion app/public/components/detectors/detectorIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
export default function detectorIcon(navigation, item, index, detectorName, timeBased = false, qualityChangePossible = false) {
const runDetectorId = `${index}-${item.run_number}-${detectorName}`;
const runBasedQcModalId = `${runDetectorId}-qc-modal`;
const runDetectorQualityControlFlag = item[`${detectorName.toLowerCase()}_detector`];

Check warning on line 22 in app/public/components/detectors/detectorIcon.js

View check run for this annotation

Codecov / codecov/patch

app/public/components/detectors/detectorIcon.js#L22

Added line #L22 was not covered by tests

const { qcf, qcf_bkp } = runDetectorQualityControlFlag;
const quality = qcf?.quality || qcf_bkp?.quality;
const qcFromBookkeeping = ! qcf?.quality && qcf_bkp?.quality;

Check warning on line 26 in app/public/components/detectors/detectorIcon.js

View check run for this annotation

Codecov / codecov/patch

app/public/components/detectors/detectorIcon.js#L24-L26

Added lines #L24 - L26 were not covered by tests

return [
qualityChangePossible
Expand All @@ -35,7 +35,7 @@
}, item, index, detectorName, runDetectorId, timeBased)))
: '',

h(`button.btn.pointer.run-quality.${quality ?? 'NoData'}`, {
h(`button.btn.pointer.run-quality.${quality ?? 'no-data'}`, {
id: runDetectorId,
onclick: () => {
if (qualityChangePossible) {
Expand Down
4 changes: 3 additions & 1 deletion app/public/components/flags/flagsVisualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
}

export default function flagsVisualization(runData, flagsData) {
const { time_start, time_end } = runData;
const { time_o2_start, time_o2_end, time_trg_start, time_trg_end } = runData;
const time_start = time_trg_start ?? time_o2_start;
const time_end = time_trg_end ?? time_o2_end;

Check warning on line 28 in app/public/components/flags/flagsVisualization.js

View check run for this annotation

Codecov / codecov/patch

app/public/components/flags/flagsVisualization.js#L26-L28

Added lines #L26 - L28 were not covered by tests

const distinctFlagReasons = filterDistinct(flagsData.map((flag) => flag.flag_reason.replace(/\s+/g, '')));

Expand All @@ -38,7 +40,7 @@
case 'Mixed':
return flagReasonColors.limitedAcceptance;
case 'Good':
return flagReasonColors.good;

Check warning on line 43 in app/public/components/flags/flagsVisualization.js

View check run for this annotation

Codecov / codecov/patch

app/public/components/flags/flagsVisualization.js#L43

Added line #L43 was not covered by tests
case 'Notbad':
return flagReasonColors.neutral;
case 'CertifiedbyExpert':
Expand Down
2 changes: 1 addition & 1 deletion app/public/styles/rct/custom/components/run-quality.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
color: var(--white);
}

.rct .run-quality.NoData {
.rct .run-quality.no-data {
background-color: var(--dark-blue) !important;
color: var(--white);
}
8 changes: 6 additions & 2 deletions app/public/styles/rct/custom/tables/flags.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@
}

/* Verification time */
.rct .flags-table .flags-ver_time-cell,
.rct .flags-table .flags-ver_time-header {
.rct .flags-table .flags-verification_time-cell,
.rct .flags-table .flags-verification_time-header {
martinboulais marked this conversation as resolved.
Show resolved Hide resolved
min-width: 10em;
text-align: left;
}

.verification-border {
border-bottom: solid;
}
2 changes: 1 addition & 1 deletion app/public/views/flags/Flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class Flags extends Observable {
const allFlags = this.getAllFlags();
const flags = !Array.isArray(allFlags) ? [] : allFlags.map((flag) => {
const { verifications } = flag;
flag.ver_time = verifications?.map(({ verification_time }) => verification_time);
flag.verification_time = verifications?.map(({ verification_time }) => verification_time);
flag.by = verifications?.map(({ by }) => by);
return flag;
});
Expand Down
2 changes: 1 addition & 1 deletion app/public/views/flags/table/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const fields = [
display: true,
},
{
name: 'ver_time',
name: 'verification_time',
display: true,
},
];
Expand Down
2 changes: 1 addition & 1 deletion app/public/views/userView/data/headersSpecials.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const flagFields = {
flag_reason: 'Reason',
comment: 'Comment',
by: 'Verified by',
ver_time: 'Verification time',
verification_time: 'Verification time',
};

const headersSpecials = {
Expand Down
20 changes: 7 additions & 13 deletions app/public/views/userView/data/pagesCellsSpecials.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,16 @@ pagesCellsSpecials[PN.runsPerPeriod] = {
}, item.fill_number, h('.external-link-15-blue')),
};

const linerUnderVerifier = '--------';
pagesCellsSpecials[PN.flags] = {
time_start: (item) => dateFormatter(item.time_start),
time_end: (item) => dateFormatter(item.time_end),
by: (item) => ! item.by?.length
? 'unverified'
: item.by.map((verifier) => h('', verifier, h('.skinny', linerUnderVerifier))),
ver_time: (item) => ! item.ver_time?.length
? 'unverified'
: item.ver_time.map((e) => {
if (!e) {
return 'unverified';
}
const date = new Date(e);
return dateFormatter(date.getTime());
}),
by: (item) => ! item.verifications?.length ?
'unverified'
: item.verifications.map(({ by: verifier }) => h('.verification-border', h('', verifier, h('.skinny.hidden', '.')))),
verification_time: (item) => ! item.verifications?.length ?
'unverified'
: item.verifications.map(({ verification_time }) =>
h('.verification-border', dateFormatter(new Date(verification_time).getTime()))),
};

pagesCellsSpecials[PN.runsPerDataPass] = pagesCellsSpecials[PN.runsPerPeriod];
Expand Down