|
|
@ -96,11 +96,24 @@ export async function findMany(id: AnalyticUnitId, query: FindManyQuery): Promis |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function insertSegments(segments: Segment[]) { |
|
|
|
export async function insertSegments(segments: Segment[]) { |
|
|
|
|
|
|
|
let analyticUnitId: AnalyticUnitId = segments[0].analyticUnitId; |
|
|
|
let segmentIdsToRemove: SegmentId[] = []; |
|
|
|
let segmentIdsToRemove: SegmentId[] = []; |
|
|
|
let segmentsToInsert: Segment[] = []; |
|
|
|
let segmentsToInsert: Segment[] = []; |
|
|
|
|
|
|
|
let learningSegments: Segment[] = await db.findMany({ |
|
|
|
|
|
|
|
analyticUnitId, |
|
|
|
|
|
|
|
labeled: true, |
|
|
|
|
|
|
|
deleted: false |
|
|
|
|
|
|
|
}); |
|
|
|
for(let segment of segments) { |
|
|
|
for(let segment of segments) { |
|
|
|
|
|
|
|
let intersectedLearning = learningSegments.filter(s => { |
|
|
|
|
|
|
|
return segment.from <= s.to && segment.to >= s.from; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if(intersectedLearning.length > 0) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let intersectedSegments = await db.findMany({ |
|
|
|
let intersectedSegments = await db.findMany({ |
|
|
|
analyticUnitId: segments[0].analyticUnitId, |
|
|
|
analyticUnitId, |
|
|
|
to: { $gte: segment.from }, |
|
|
|
to: { $gte: segment.from }, |
|
|
|
from: { $lte: segment.to }, |
|
|
|
from: { $lte: segment.to }, |
|
|
|
labeled: segment.labeled, |
|
|
|
labeled: segment.labeled, |
|
|
@ -121,7 +134,7 @@ export async function insertSegments(segments: Segment[]) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await db.removeMany(segmentIdsToRemove); |
|
|
|
await db.removeMany(segmentIdsToRemove); |
|
|
|
return db.insertMany(segments.map(s => s.toObject())); |
|
|
|
return db.insertMany(segmentsToInsert.map(s => s.toObject())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function setSegmentsDeleted(ids: SegmentId[]) { |
|
|
|
export async function setSegmentsDeleted(ids: SegmentId[]) { |
|
|
|