|
|
@ -74,15 +74,16 @@ async function runTask(task: AnalyticsTask): Promise<TaskResult> { |
|
|
|
* @param segments labeled segments |
|
|
|
* @param segments labeled segments |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function getQueryRangeForLearningBySegments(segments: Segment.Segment[]) { |
|
|
|
function getQueryRangeForLearningBySegments(segments: Segment.Segment[]) { |
|
|
|
if(segments.length < 2) { |
|
|
|
if(segments.length === 0) { |
|
|
|
throw new Error('Need at least 2 labeled segments'); |
|
|
|
throw new Error('Need at least 1 labeled segment'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let from = _.minBy(segments, s => s.from).from; |
|
|
|
let from = _.minBy(segments, s => s.from).from; |
|
|
|
let to = _.maxBy(segments, s => s.to).to; |
|
|
|
let to = _.maxBy(segments, s => s.to).to; |
|
|
|
let diff = to - from; |
|
|
|
let now = Date.now(); |
|
|
|
from -= Math.round(diff); |
|
|
|
let leftOffset = now - to; |
|
|
|
to = Date.now(); |
|
|
|
from -= Math.round(leftOffset); |
|
|
|
|
|
|
|
to = now; |
|
|
|
|
|
|
|
|
|
|
|
return { from, to }; |
|
|
|
return { from, to }; |
|
|
|
} |
|
|
|
} |
|
|
@ -96,8 +97,8 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
|
if(segments.length < 2) { |
|
|
|
if(segments.length === 0) { |
|
|
|
throw new Error('Need at least 2 labeled segments'); |
|
|
|
throw new Error('Need at least 1 labeled segment'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let segmentObjs = segments.map(s => s.toObject()); |
|
|
|
let segmentObjs = segments.map(s => s.toObject()); |
|
|
@ -140,8 +141,8 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { |
|
|
|
let pattern = unit.type; |
|
|
|
let pattern = unit.type; |
|
|
|
|
|
|
|
|
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
|
let segments = await Segment.findMany(id, { labeled: true }); |
|
|
|
if(segments.length < 2) { |
|
|
|
if(segments.length === 0) { |
|
|
|
throw new Error('Need at least 2 labeled segments'); |
|
|
|
throw new Error('Need at least 1 labeled segment'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let { from, to } = getQueryRangeForLearningBySegments(segments); |
|
|
|
let { from, to } = getQueryRangeForLearningBySegments(segments); |
|
|
|