Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sendScores(def, passive = false) {
const scoreData = dividersToPartition(def, model.scores);
if (scoreData === null) {
console.error('Cannot translate scores to send to provider');
return;
}
if (model.provider.isA('SelectionProvider')) {
if (!scoreData.name) {
AnnotationBuilder.setDefaultName(scoreData);
if (model.provider.isA('AnnotationStoreProvider')) {
scoreData.name = model.provider.getNextStoredAnnotationName(
scoreData.name
);
}
}
if (!passive) {
model.provider.setAnnotation(scoreData);
} else if (
model.provider.isA('AnnotationStoreProvider') &&
model.provider.getStoredAnnotation(scoreData.id)
) {
// Passive means we don't want to set the active annotation, but if there is
// a stored annotation matching these score dividers, we still need to update
// that stored annotation
model.provider.updateStoredAnnotations({
const selection = model.axes.getSelection();
if (selection.type === 'empty') {
lastAnnotationPushed = AnnotationBuilder.EMPTY_ANNOTATION;
} else if (
!lastAnnotationPushed ||
model.provider.shouldCreateNewAnnotation() ||
lastAnnotationPushed.selection.type !== 'range'
) {
lastAnnotationPushed = AnnotationBuilder.annotation(
selection,
[model.defaultScore],
model.defaultWeight
);
if (lastAnnotationPushed.name === '') {
// set default range annotation name
AnnotationBuilder.setDefaultName(lastAnnotationPushed);
if (model.provider.isA('AnnotationStoreProvider')) {
lastAnnotationPushed.name = model.provider.getNextStoredAnnotationName(
lastAnnotationPushed.name
);
}
}
} else {
lastAnnotationPushed = AnnotationBuilder.update(
lastAnnotationPushed,
{
selection,
score: [model.defaultScore],
weight: model.defaultWeight,
}
);
}
const selection = SelectionBuilder.range(vars);
if (model.useAnnotation) {
lastAnnotationPushed = model.provider.getAnnotation();
if (
!lastAnnotationPushed ||
model.provider.shouldCreateNewAnnotation() ||
lastAnnotationPushed.selection.type !== 'range'
) {
lastAnnotationPushed = AnnotationBuilder.annotation(
selection,
[model.defaultScore],
model.defaultWeight
);
if (lastAnnotationPushed.name === '') {
// set default range annotation name
AnnotationBuilder.setDefaultName(lastAnnotationPushed);
if (model.provider.isA('AnnotationStoreProvider')) {
lastAnnotationPushed.name = model.provider.getNextStoredAnnotationName(
lastAnnotationPushed.name
);
}
}
} else {
lastAnnotationPushed = AnnotationBuilder.update(
lastAnnotationPushed,
{
selection,
score: [model.defaultScore],
weight: model.defaultWeight,
}
);
}