Browse Source

Reduce amount of required labeled segments for learning #147 (#153)

* rm labeled segments amount check && change query range algorithm

* review fix

* typo fix

* minor fix
pull/1/head
rozetko 6 years ago committed by Alexey Velikiy
parent
commit
74ea83c0b6
  1. 19
      server/src/controllers/analytics_controller.ts

19
server/src/controllers/analytics_controller.ts

@ -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);

Loading…
Cancel
Save