Browse Source

Anti-segments do not fall into analytics #181 (#190)

pull/1/head
Evgeny Smyshlyaev 6 years ago committed by rozetko
parent
commit
df4866ce29
  1. 5
      server/src/controllers/analytics_controller.ts
  2. 8
      server/src/models/segment_model.ts

5
server/src/controllers/analytics_controller.ts

@ -120,6 +120,11 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) {
} else { } else {
await AnalyticUnitCache.create(id); await AnalyticUnitCache.create(id);
} }
let deletedSegments = await Segment.findMany(id, { deleted: true });
let deletedSegmentsObjs = deletedSegments.map(s => s.toObject());
segmentObjs = _.concat(segmentObjs, deletedSegmentsObjs);
let task = new AnalyticsTask( let task = new AnalyticsTask(
id, AnalyticsTaskType.LEARN, { pattern, segments: segmentObjs, data, cache: oldCache } id, AnalyticsTaskType.LEARN, { pattern, segments: segmentObjs, data, cache: oldCache }
); );

8
server/src/models/segment_model.ts

@ -62,7 +62,8 @@ export type FindManyQuery = {
timeFromGTE?: number, timeFromGTE?: number,
timeToLTE?: number, timeToLTE?: number,
intexGT?: number, intexGT?: number,
labeled?: boolean labeled?: boolean,
deleted?: boolean
} }
export async function findMany(id: AnalyticUnitId, query: FindManyQuery): Promise<Segment[]> { export async function findMany(id: AnalyticUnitId, query: FindManyQuery): Promise<Segment[]> {
@ -76,6 +77,9 @@ export async function findMany(id: AnalyticUnitId, query: FindManyQuery): Promis
if(query.labeled !== undefined) { if(query.labeled !== undefined) {
dbQuery.labeled = query.labeled; dbQuery.labeled = query.labeled;
} }
if(query.deleted !== undefined) {
dbQuery.deleted = query.deleted;
}
let segs = await db.findMany(dbQuery); let segs = await db.findMany(dbQuery);
if(segs === null) { if(segs === null) {
return []; return [];
@ -113,7 +117,7 @@ export async function insertSegments(segments: Segment[]) {
} }
export async function setSegmentsDeleted(ids: SegmentId[]) { export async function setSegmentsDeleted(ids: SegmentId[]) {
return db.updateMany(ids, { deleted: true }); return db.updateMany(ids, { deleted: true, labeled: false });
} }
export function removeSegments(idsToRemove: SegmentId[]) { export function removeSegments(idsToRemove: SegmentId[]) {

Loading…
Cancel
Save