Skip to content

Commit

Permalink
delete is_manual and is_positive from annotations re #444
Browse files Browse the repository at this point in the history
  • Loading branch information
rassokhin-s committed Oct 25, 2023
1 parent 89fcd14 commit bfed22b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 104 deletions.
24 changes: 24 additions & 0 deletions core/_cli/migrations/20231025000001-delete-annotation-is-manual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async transaction => {
await queryInterface.sequelize.query('DELETE FROM annotations WHERE is_manual IS TRUE;', { transaction })
await queryInterface.removeColumn('annotations', 'is_manual', { transaction })
await queryInterface.removeColumn('annotations', 'is_positive', { transaction })
})
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn('annotations', 'is_manual', {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: true
}, { transaction })
await queryInterface.addColumn('annotations', 'is_positive', {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: true
}, { transaction })
})
}
}
29 changes: 14 additions & 15 deletions core/_cli/seeds/30-annotations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ with open("./50-detections.sql", "r") as f:
created_at = (datetime.datetime.strptime(end, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M:%S')
updated_by_id = created_by_id
updated_at = created_at
is_positive = random.choice(['true', 'false'])
print(f"""INSERT INTO public.annotations (id, start, "end", frequency_min, frequency_max, classification_id, stream_id, created_by_id, created_at, updated_by_id, updated_at, is_manual, is_positive) VALUES ('{id}', '{start}', '{end}', {frequency_min}, {frequency_max}, {classification_id}, '{stream_id}', {created_by_id}, '{created_at}', {updated_by_id}, '{updated_at}', true, {is_positive});""")
print(f"""INSERT INTO public.annotations (id, start, "end", frequency_min, frequency_max, classification_id, stream_id, created_by_id, created_at, updated_by_id, updated_at) VALUES ('{id}', '{start}', '{end}', {frequency_min}, {frequency_max}, {classification_id}, '{stream_id}', {created_by_id}, '{created_at}', {updated_by_id}, '{updated_at}');""")
*/
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('89098e06-d59f-455f-a90c-c0b373208d32', 'lgndfyp1enmu', 303, '2020-05-24 15:34:05.500', '2020-05-24 15:34:09.000', 2000, 7800, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('5bf7dd68-ef61-452d-bc42-e28ae1de230d', 'lgndfyp1enmu', 303, '2020-05-24 15:38:45.000', '2020-05-24 15:39:09.000', 2600, 6800, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('e309c97c-01ed-4db3-a3f2-946904c62a02', 'lgndfyp1enmu', 303, '2020-05-24 15:39:22.500', '2020-05-24 15:39:25.500', 2900, 8900, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('eda9c5c7-de13-4d5b-96bd-03ecd9158490', 'lgndfyp1enmu', 303, '2020-05-24 15:35:03.000', '2020-05-24 15:35:29.000', 1800, 8100, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('331d3d7b-1788-4ee9-8e7c-77516a280be4', 'lgndfyp1enmu', 303, '2020-05-24 19:10:53.500', '2020-05-24 19:12:05.500', 2000, 9200, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('3e426fa1-7f51-42d2-8361-b69e145f5169', 'lgndfyp1enmu', 303, '2020-05-24 19:29:00.000', '2020-05-24 19:29:16.750', 1800, 7400, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('df51db27-bf11-4b1a-9493-d7ebb572c181', 'lgndfyp1enmu', 345, '2020-05-24 15:30:45.000', '2020-05-24 15:30:59.500', 7700, 12000, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('bbcb7e6c-d09c-4845-9245-2328662eaad9', 'lgndfyp1enmu', 345, '2020-05-24 15:35:33.500', '2020-05-24 15:35:51.500', 9000, 13500, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('768d27ef-ea77-4c1e-9841-78dd5525dba8', 'ev69cht895gc', 268, '2020-05-24 12:25:05.500', '2020-05-24 12:25:14.000', 1300, 5220, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('2301646d-0654-4467-affd-9b6709be5358', 'ev69cht895gc', 268, '2020-05-24 12:28:45.000', '2020-05-24 12:28:49.000', 600, 5800, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('2301646d-0654-4467-affd-9b6709be5123', 'ev69cht895gc', 268, '2020-05-25 12:00:21.750', '2020-05-25 12:01:25.500', 900, 5900, 8, 8, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, is_manual, is_positive, created_at, updated_at) VALUES ('2301646d-0654-4467-affd-9b6709be5124', 'ev69cht895gc', 353, '2020-05-25 12:15:00.000', '2020-05-25 12:15:05.000', 300, 10000, 1, 1, true, true, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public.annotations (id, start, "end", frequency_min, frequency_max, classification_id, stream_id, created_by_id, created_at, updated_by_id, updated_at, is_manual, is_positive) VALUES ('ed8e2907-4e02-47b6-9b70-0aa75b1b1c51', '2020-10-16 04:02:25', '2020-10-16 04:02:27', 9600, 10420, 303, 'LilSjZJkRK06', 8, '2020-10-16 04:04:25', 8, '2020-10-16 04:04:25', true, true);
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('89098e06-d59f-455f-a90c-c0b373208d32', 'lgndfyp1enmu', 303, '2020-05-24 15:34:05.500', '2020-05-24 15:34:09.000', 2000, 7800, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('5bf7dd68-ef61-452d-bc42-e28ae1de230d', 'lgndfyp1enmu', 303, '2020-05-24 15:38:45.000', '2020-05-24 15:39:09.000', 2600, 6800, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('e309c97c-01ed-4db3-a3f2-946904c62a02', 'lgndfyp1enmu', 303, '2020-05-24 15:39:22.500', '2020-05-24 15:39:25.500', 2900, 8900, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('eda9c5c7-de13-4d5b-96bd-03ecd9158490', 'lgndfyp1enmu', 303, '2020-05-24 15:35:03.000', '2020-05-24 15:35:29.000', 1800, 8100, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('331d3d7b-1788-4ee9-8e7c-77516a280be4', 'lgndfyp1enmu', 303, '2020-05-24 19:10:53.500', '2020-05-24 19:12:05.500', 2000, 9200, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('3e426fa1-7f51-42d2-8361-b69e145f5169', 'lgndfyp1enmu', 303, '2020-05-24 19:29:00.000', '2020-05-24 19:29:16.750', 1800, 7400, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('df51db27-bf11-4b1a-9493-d7ebb572c181', 'lgndfyp1enmu', 345, '2020-05-24 15:30:45.000', '2020-05-24 15:30:59.500', 7700, 12000, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('bbcb7e6c-d09c-4845-9245-2328662eaad9', 'lgndfyp1enmu', 345, '2020-05-24 15:35:33.500', '2020-05-24 15:35:51.500', 9000, 13500, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('768d27ef-ea77-4c1e-9841-78dd5525dba8', 'ev69cht895gc', 268, '2020-05-24 12:25:05.500', '2020-05-24 12:25:14.000', 1300, 5220, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('2301646d-0654-4467-affd-9b6709be5358', 'ev69cht895gc', 268, '2020-05-24 12:28:45.000', '2020-05-24 12:28:49.000', 600, 5800, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('2301646d-0654-4467-affd-9b6709be5123', 'ev69cht895gc', 268, '2020-05-25 12:00:21.750', '2020-05-25 12:01:25.500', 900, 5900, 8, 8, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public."annotations" (id, stream_id, classification_id, start, "end", frequency_min, frequency_max, created_by_id, updated_by_id, created_at, updated_at) VALUES ('2301646d-0654-4467-affd-9b6709be5124', 'ev69cht895gc', 353, '2020-05-25 12:15:00.000', '2020-05-25 12:15:05.000', 300, 10000, 1, 1, '2020-05-29 11:30:00.000', '2020-05-29 11:30:00.000');
INSERT INTO public.annotations (id, start, "end", frequency_min, frequency_max, classification_id, stream_id, created_by_id, created_at, updated_by_id, updated_at) VALUES ('ed8e2907-4e02-47b6-9b70-0aa75b1b1c51', '2020-10-16 04:02:25', '2020-10-16 04:02:27', 9600, 10420, 303, 'LilSjZJkRK06', 8, '2020-10-16 04:04:25', 8, '2020-10-16 04:04:25');
5 changes: 0 additions & 5 deletions core/_cli/seeds/51-detections-reviews.sql

This file was deleted.

12 changes: 0 additions & 12 deletions core/_docs/requestBodies.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,11 @@
},
"frequency_min": {
"type": "integer",
"description": "Required if is_manual is not provided or set to false",
"example": 1530
},
"frequency_max": {
"type": "integer",
"description": "Required if is_manual is not provided or set to false",
"example": 4010
},
"is_manual": {
"type": "boolean",
"description": "An annotation which was suggested to user by a system (e.g. detection review)",
"example": true
},
"is_positive": {
"type": "boolean",
"description": "Whether this annotation represents absence of specified classification",
"example": true
}
},
"required": [
Expand Down
10 changes: 0 additions & 10 deletions core/_models/annotations/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ module.exports = (sequelize, DataTypes) => {
classification_id: {
type: DataTypes.INTEGER
},
is_manual: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
is_positive: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
created_by_id: {
type: DataTypes.INTEGER,
allowNull: false
Expand Down
8 changes: 2 additions & 6 deletions core/annotations/clustered.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ router.get('/', (req, res) => {
params.convert('interval').default('1d').toTimeInterval()
params.convert('aggregate').default('count').toAggregateFunction()
params.convert('field').default('id').isEqualToAny(models.Annotation.attributes.full)
params.convert('is_manual').optional().toBoolean()
params.convert('is_positive').optional().toBoolean()
params.convert('descending').default(false).toBoolean()
params.convert('limit').default(100).toInt()
params.convert('offset').default(0).toInt()
Expand All @@ -118,16 +116,14 @@ router.get('/', (req, res) => {
throw new ForbiddenError('You do not have permission to access this stream.')
}
}
const { start, end, interval, aggregate, field, is_manual, is_positive, descending, limit, offset } = convertedParams // eslint-disable-line camelcase
const { start, end, interval, aggregate, field, descending, limit, offset } = convertedParams // eslint-disable-line camelcase
const streamsOnlyPublic = convertedParams.streams_public
const annotation = {
start,
end,
streamId,
user,
createdBy,
isManual: is_manual,
isPositive: is_positive
createdBy
}
return dao.timeAggregatedQuery(
annotation,
Expand Down
29 changes: 5 additions & 24 deletions core/annotations/dao/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const { getAccessibleObjectsIDs, STREAM } = require('../../roles/dao')
* @param {string} filters.streamId
* @param {string} filters.start
* @param {string} filters.end
* @param {boolean} filters.isManual Whether annotation was drawn or created as detection review
* @param {boolean} filters.isPositive Whether annotation represents absence of specified classification
* @param {boolean} filters.streamsOnlyPublic
* @param {object} filters.user
* @param {string[]} filters.classifications
Expand All @@ -26,9 +24,7 @@ async function defaultQueryOptions (filters, options = {}) {
start: {
[models.Sequelize.Op.gte]: moment.utc(filters.start).valueOf(),
[models.Sequelize.Op.lt]: moment.utc(filters.end).valueOf()
},
is_manual: !!filters.isManual,
...filters.isPositive !== undefined && { is_positive: filters.isPositive }
}
}
if (filters.streamId !== undefined) {
condition.stream_id = filters.streamId
Expand Down Expand Up @@ -76,8 +72,6 @@ function formatFull (annotation) {
* @param {string} filters.streamId
* @param {string} filters.start
* @param {string} filters.end
* @param {boolean} filters.isManual Whether annotation was drawn or created as detection review
* @param {boolean} filters.isPositive Whether annotation represents absence of specified classification
* @param {boolean} filters.streamsOnlyPublic
* @param {object} filters.user
* @param {string | number} filters.streamsOnlyCreatedBy
Expand All @@ -89,14 +83,6 @@ function formatFull (annotation) {
*/
async function query (filters, options = {}) {
const queryOptions = await defaultQueryOptions(filters, options)
if (filters.isManual === false) {
queryOptions.include.push({
as: 'created_by',
model: models.User,
attributes: models.User.attributes.lite
})
queryOptions.attributes.push('is_positive')
}
return models.Annotation.findAll(queryOptions)
}

Expand All @@ -106,8 +92,6 @@ async function query (filters, options = {}) {
* @param {string} filters.streamId
* @param {string} filters.start
* @param {string} filters.end
* @param {boolean} filters.isManual Whether annotation was drawn or created as detection review
* @param {boolean} filters.isPositive Whether annotation represents absence of specified classification
* @param {boolean} filters.streamsOnlyPublic
* @param {object} filters.user
* @param {number} filters.createdBy
Expand Down Expand Up @@ -137,21 +121,19 @@ async function timeAggregatedQuery (filters, options = {}) {
}

function create (annotation) {
const { streamId, start, end, classificationId, frequencyMin, frequencyMax, userId, isManual, isPositive } = annotation
const { streamId, start, end, classificationId, frequencyMin, frequencyMax, userId } = annotation
const where = {
start,
end,
stream_id: streamId,
classification_id: classificationId,
created_by_id: userId,
is_manual: isManual
created_by_id: userId
}
const defaults = {
...where,
frequency_min: frequencyMin,
frequency_max: frequencyMax,
updated_by_id: userId,
is_positive: isPositive
updated_by_id: userId
}
return models.Annotation.findOrCreate({ where, defaults }).spread((annotation, created) => formatFull(annotation))
}
Expand Down Expand Up @@ -194,8 +176,7 @@ function update (annotationId, start, end, classificationId, frequencyMin, frequ
frequency_min: frequencyMin,
frequency_max: frequencyMax,
updated_by_id: userId,
updated_at: new Date(),
...isPositive !== undefined && { is_positive: isPositive }
updated_at: new Date()
}, { transaction, silent: true })
})
})
Expand Down
Loading

0 comments on commit bfed22b

Please sign in to comment.