Browse Source

Do not insert found segment if it intersects with deleted #434 (#442)

pull/1/head
rozetko 6 years ago committed by GitHub
parent
commit
6c1a4e806e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      server/src/models/segment_model.ts

30
server/src/models/segment_model.ts

@ -52,7 +52,7 @@ export class Segment {
throw new Error('obj is undefined'); throw new Error('obj is undefined');
} }
return new Segment( return new Segment(
obj.analyticUnitId, obj.analyticUnitId,
+obj.from, +obj.to, +obj.from, +obj.to,
obj.labeled, obj.deleted, obj._id obj.labeled, obj.deleted, obj._id
); );
@ -100,23 +100,39 @@ export async function insertSegments(segments: Segment[]) {
if(_.isEmpty(segments)) { if(_.isEmpty(segments)) {
return []; return [];
} }
let analyticUnitId: AnalyticUnitId = segments[0].analyticUnitId; const analyticUnitId: AnalyticUnitId = segments[0].analyticUnitId;
let segmentIdsToRemove: SegmentId[] = []; const learningSegments: Segment[] = await db.findMany({
let segmentsToInsert: Segment[] = [];
let learningSegments: Segment[] = await db.findMany({
analyticUnitId, analyticUnitId,
labeled: true, labeled: true,
deleted: false deleted: false
}); });
let segmentIdsToRemove: SegmentId[] = [];
let segmentsToInsert: Segment[] = [];
for(let segment of segments) { for(let segment of segments) {
let intersectedLearning = learningSegments.filter(s => { const intersectedLearning = learningSegments.filter(s => {
return segment.from <= s.to && segment.to >= s.from; return segment.from <= s.to && segment.to >= s.from;
}); });
if(intersectedLearning.length > 0) { if(intersectedLearning.length > 0) {
continue; continue;
} }
let intersectedSegments = await db.findMany({ if(!segment.deleted && !segment.labeled) {
const intersectedWithDeletedSegments = await db.findMany({
analyticUnitId,
to: { $gte: segment.from },
from: { $lte: segment.to },
labeled: false,
deleted: true
});
if(intersectedWithDeletedSegments.length > 0) {
continue;
}
}
const intersectedSegments = await db.findMany({
analyticUnitId, analyticUnitId,
to: { $gte: segment.from }, to: { $gte: segment.from },
from: { $lte: segment.to }, from: { $lte: segment.to },

Loading…
Cancel
Save