module.exports = function lrc (s, key, length, source_key) { if (!source_key) source_key = 'close' if (s.lookback.length > length) { let data = [] for (var i=length-1; i>=0; i--) { data.push([length-1-i, s.lookback[i][source_key]]) } let result = regression.linear(data) s.period[key] = result.equation[1] + result.equation[0]*(length-1) } }
.map(series => { const timeseries = get(bucket, `${series.id}.timeseries`); const buckets = get(bucket, `${series.id}.buckets`); if (!timeseries && buckets) { const meta = get(bucket, `${series.id}.meta`); const timeseries = { buckets: get(bucket, `${series.id}.buckets`), }; set(bucket, series.id, { meta, timeseries }); } const processor = buildProcessorFunction(processors, bucket, panel, series); const result = first(processor([])); if (!result) return null; const data = get(result, 'data', []); const linearRegression = regression.linear(data); result.last = getLastValue(data); result.slope = linearRegression.equation[0]; return result; });