diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 17f0a4b..be7befa 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -190,6 +190,10 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { // } // } + let lastPredictedSegments = await Segment.findMany(id, { labeled: false, deleted: false }); + let segmentsToRemove = lastPredictedSegments.filter(s => payload.segments.indexOf(s) === -1); + Segment.removeSegments(segmentsToRemove.map(s => s.id)); + Segment.insertSegments(payload.segments); AnalyticUnitCache.setData(id, payload.cache); AnalyticUnit.setPredictionTime(id, payload.lastPredictionTime); diff --git a/server/src/models/segment_model.ts b/server/src/models/segment_model.ts index 9a397c3..60e93ab 100644 --- a/server/src/models/segment_model.ts +++ b/server/src/models/segment_model.ts @@ -56,6 +56,14 @@ export class Segment { obj.labeled, obj.deleted, obj._id ); } + + public equals(obj: Segment) : boolean { + return this.analyticUnitId === obj.analyticUnitId && + this.from === obj.from && + this.to === obj.to && + this.labeled === this.labeled && + this.deleted === this.deleted; + } } export type FindManyQuery = {