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