From a0ee61fe7a2821a39718c51d214cd2d49b8c8fd4 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Fri, 8 Nov 2024 15:57:09 +0000 Subject: [PATCH] fix(classifier): set started_at timestamp when annotation starts - add `metadata._inProgress` to classifications, and set it to true when a volunteer first updates an annotation. - set `classification.metadata.started_at` to the current time when `metadata._inProgress` is set to true. --- app/classifier/classifier.jsx | 11 +++++++++-- app/classifier/task.jsx | 2 +- app/redux/ducks/classify.js | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/classifier/classifier.jsx b/app/classifier/classifier.jsx index 29ca933697..4032c60cc7 100644 --- a/app/classifier/classifier.jsx +++ b/app/classifier/classifier.jsx @@ -141,9 +141,15 @@ class Classifier extends React.Component { }); } - updateAnnotations(annotations) { + updateAnnotations(annotations, fromUserAction = false) { this.setState({ annotations }); this.props.actions.classify.saveAnnotations(annotations); + if (fromUserAction && !this.props.classification?.metadata._inProgress) { + this.props.actions.classify.updateMetadata({ + _inProgress: true, + started_at: new Date().toISOString() + }); + } } updateFeedback(taskId) { @@ -203,12 +209,13 @@ class Classifier extends React.Component { actions.classify.updateMetadata({ subject_dimensions }); } + // handle annotation changes from the subject viewer eg. drawing tasks handleAnnotationChange(classification, newAnnotation) { const { annotations } = this.state; const index = findLastIndex(annotations, annotation => annotation.task === newAnnotation.task); if (index > -1) { annotations[index] = newAnnotation; - this.updateAnnotations(annotations); + this.updateAnnotations(annotations, true); } } diff --git a/app/classifier/task.jsx b/app/classifier/task.jsx index 49e4591302..b8e252fb82 100644 --- a/app/classifier/task.jsx +++ b/app/classifier/task.jsx @@ -16,7 +16,7 @@ class Task extends React.Component { const index = findLastIndex(annotations, annotation => annotation.task === newAnnotation.task); if (index > -1) { annotations[index] = newAnnotation; - this.props.updateAnnotations(annotations); + this.props.updateAnnotations(annotations, true); } } diff --git a/app/redux/ducks/classify.js b/app/redux/ducks/classify.js index 039629a775..d4f0e563e8 100644 --- a/app/redux/ducks/classify.js +++ b/app/redux/ducks/classify.js @@ -51,6 +51,7 @@ function createNewClassification(project, workflow, subject, goldStandardMode, l // Delete the metadata key because we don't want volunteers to see it. subject.update({ 'metadata.intervention': undefined }); const newMetadata = { + _inProgress: false, workflow_version: workflow.version, started_at: (new Date()).toISOString(), user_agent: navigator.userAgent,