Browse Source

Labeled pattern intersects with predicted #253 (#371)

pull/1/head
Evgeny Smyshlyaev 6 years ago committed by rozetko
parent
commit
8e6260859c
  1. 17
      server/src/models/segment_model.ts

17
server/src/models/segment_model.ts

@ -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[]) {

Loading…
Cancel
Save