|
|
@ -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 }, |
|
|
|