Skip to content

Commit

Permalink
Merge pull request #971 from rfcx/feature/923-add-the-ability-to-unva…
Browse files Browse the repository at this point in the history
…lidate-aed-boxes-on-the-visualizer-page

#923 User has an ability to unvalidate audio event detections boxes on the Visualizer Page
  • Loading branch information
rassokhina-e authored May 9, 2022
2 parents 99cc806 + 1f2d22e commit a404bbc
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Arbimon Release Notes

## v3.0.52 - May XX, 2022

New features:

- #923 User has an ability to unvalidate audio event detections boxes on the Visualizer Page

## v3.0.51 - May 06, 2022

New features:
Expand Down
7 changes: 5 additions & 2 deletions app/model/audio-event-detections-clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let AudioEventDetectionsClustering = {
find: function (options) {
let constraints=['1=1'];
let postprocess=[];
let data=[];
let select = [];
let tables = ['job_params_audio_event_detection_clustering JP'];

Expand Down Expand Up @@ -45,9 +44,13 @@ let AudioEventDetectionsClustering = {
"A.`time_min` as `time_min`",
"A.`time_max` as `time_max`",
"A.`frequency_min` as `freq_min`",
"A.`frequency_max` as `freq_max`"
"A.`frequency_max` as `freq_max`",
'A.aed_id', 'A.species_id', 'A.songtype_id',
'Sp.scientific_name as species_name', 'St.songtype as songtype_name'
);
tables.push("JOIN audio_event_detections_clustering A ON JP.job_id = A.job_id");
tables.push('LEFT JOIN species Sp ON A.species_id = Sp.species_id');
tables.push('LEFT JOIN songtypes St ON A.songtype_id = St.songtype_id');
}

if (options.rec_id) {
Expand Down
34 changes: 33 additions & 1 deletion app/routes/data-api/project/audio-event-detections-clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ router.post('/validate', function(req, res, next) {
}
let oldValidation = await model.recordings.getRecordingValidation(params);
if (oldValidation[0].present_aed > 1) {
await model.AudioEventDetectionsClustering.updatePresentAedCount(params)
await model.AudioEventDetectionsClustering.updatePresentAedCount({ ...params, validate: false })
}
if (oldValidation[0].present_aed === 1 && oldValidation[0].present_review === 0 && oldValidation[0].present === null) {
await model.AudioEventDetectionsClustering.deletePresentAedCount(params)
Expand Down Expand Up @@ -116,5 +116,37 @@ router.post('/validate', function(req, res, next) {
.catch(httpErrorHandler(req, res, 'Failed audio event detections validation'))
});

router.post('/unvalidate', function(req, res, next) {
res.type('json');
const converter = new Converter(req.body, {});
converter.convert('aed').toArray();
return converter.validate()
.then(async (params) => {
for (let d of params.aed) {
// Get existing aed row
const [aedRow] = await model.AudioEventDetectionsClustering.getDetectionsById([d]);
// If aed box is validated decrease or remove the old present_aed count from the recording_validations first
if (aedRow.species_id && aedRow.songtype_id) {
const params = {
projectId: req.project.project_id,
speciesId: aedRow.species_id,
songtypeId: aedRow.songtype_id,
recordingId: aedRow.recording_id
}
let [oldValidation] = await model.recordings.getRecordingValidation(params);
if (oldValidation.present_aed > 1) {
await model.AudioEventDetectionsClustering.updatePresentAedCount({ ...params, validate: false })
}
if (oldValidation.present_aed === 1 && oldValidation.present_review === 0 && oldValidation.present === null) {
await model.AudioEventDetectionsClustering.deletePresentAedCount(params)
}
await model.AudioEventDetectionsClustering.validateDetections([d], null, null);
}
}
res.sendStatus(200)
})
.catch(httpErrorHandler(req, res, 'Error while removing audio event detections validation'))
});

module.exports = router;

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ angular.module('a2.srv.audio-event-detections-clustering', [
return response.data;
});
},
unvalidate: function(opts) {
return $http.post('/api/project/' + Project.getUrl() + '/audio-event-detections-clustering/unvalidate', opts)
.then(function(response){
return response.data;
});
},
};
})
;
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,33 @@ angular.module('a2.visualizer.layers.species-presence', [
visible: true
});
})
.controller('a2VisualizerSpeciesPresenceController', function($scope, a2PatternMatching, Project){
.controller('a2VisualizerSpeciesPresenceController', function($scope, a2PatternMatching, a2AudioEventDetectionsClustering) {
var self = this;
self.speciesPresence = null;
self.isRemoving = false;
self.checkSpectroWidth = function(leftBox, widthBox, widthSpectro) {
return leftBox + widthBox + 50 < widthSpectro;
return leftBox + widthBox + 200 < widthSpectro;
};
self.togglePopup = function(roi) {
roi.isPopupOpened = !roi.isPopupOpened;
};
self.confirmPopup = function(roi) {
self.isRemoving = true;
return a2PatternMatching.validateRois(roi.pattern_matching_id, roi.pattern_matching_roi_id, null).then(function(){
self.isRemoving = false;
self.isPopupOpened = false;
if (roi.aed_id) {
return a2AudioEventDetectionsClustering.unvalidate({ aed: [roi.aed_id] }).then(function(){
self.closePopup(roi)
roi.name = ''
})
}
else return a2PatternMatching.validateRois(roi.pattern_matching_id, roi.pattern_matching_roi_id, null).then(function(){
self.closePopup(roi)
roi.display = "none"
})
};
self.closePopup = function(roi) {
self.isRemoving = false;
roi.isPopupOpened = false;
};
self.fetchSpeciesPresence = function() {
var rec = $scope.visobject && ($scope.visobject_type == 'recording') && $scope.visobject.id;
if (rec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
height:layout.dhz2height(roi.y2, roi.y1) + 'px',
display: roi.display || ''
}">
<button ng-if="!roi.aed_id" class="close" ng-click="layer.species_presence.togglePopup(roi)" style="position: absolute; right: -4px; top:-6px; font-size: 12px; opacity: 1;">
<button class="close" ng-click="layer.species_presence.togglePopup(roi)" style="position: absolute; right: -4px; top:-6px; font-size: 12px; opacity: 1;">
<img src="/images/ic-cross.svg"
onmouseover="this.src='/images/ic-cross-hover.svg'"
onmouseout="this.src='/images/ic-cross.svg'"
/>
</button>
<div class="popover top" style="display: block; transform: translate(-43%, -100%); min-width: 20em;" ng-if="roi.isPopupOpened">
<div class="arrow" style="bottom: -8%"></div>
<div class="popover" style="display: block; min-width: 30em; position: fixed; top: 45%; left: 50%;" ng-if="roi.isPopupOpened">
<h3 class="popover-title">
Remove validated species
</h3>
Expand Down
1 change: 0 additions & 1 deletion assets/app/app/visualizer/visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ angular.module('a2.visualizer', [
if (!validations) return 0;
var count = 0
validations.forEach(function(validation) {
console.log(validation, validation.presentReview, validation.presentAed)
if (validation.presentReview > 0 || validation.presentAed > 0 || validation.present == 1) {
count++;
}
Expand Down

0 comments on commit a404bbc

Please sign in to comment.