From 640b2cc07846f87a62f2a5c2a164d579b5ec4de7 Mon Sep 17 00:00:00 2001 From: Masaki Hamano Date: Fri, 16 Feb 2018 15:18:30 +0900 Subject: [PATCH] Fix the naming of R dataset file --- build/dev/lib/js/analysis/holt_winters.js | 2 +- build/dev/lib/maps/analysis/holt_winters.js.map | 2 +- src/lib/js/analysis/holt_winters.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/dev/lib/js/analysis/holt_winters.js b/build/dev/lib/js/analysis/holt_winters.js index c728562..d73e4ec 100644 --- a/build/dev/lib/js/analysis/holt_winters.js +++ b/build/dev/lib/js/analysis/holt_winters.js @@ -1,2 +1,2 @@ -"use strict";define(["../chart/line_chart","../chart/datatables","../util/utils","ng!$q","../../vendor/d3-format.min"],function(e,a,t,r,o){return{createCube:function(e,a){var r=a.layout,o=t.validateDimension(r.props.dimensions[0]),s=[{qNullSuppression:!0,qDef:{qFieldDefs:[o]}}],i=t.validateMeasure(r.props.measures[0]),l="";r.props.frequency>0&&(l=",frequency="+r.props.frequency);var p="";r.props.autoHoltWinters||(p=",alpha="+r.props.holtWintersAlpha+",beta="+r.props.holtWintersBeta+",gamma="+r.props.holtWintersGamma),t.displayDebugModeMessage(r.props.debugMode);var n=t.getDebugSaveDatasetScript(r.props.debugMode,"debug_timeseries_forecast.rda"),d="R.ScriptEvalExStr('N', '"+n+" library(jsonlite);library(dplyr);library(forecast);data<-ts(na.omit(q$Measure) "+l+');\n fit<-HoltWinters(data, seasonal="'+r.props.seasonal+'" '+p+");\n res<-forecast(fit, level="+r.props.confidenceLevel+", h="+r.props.forecastingPeriods+");\n json<-toJSON(list(as.double(res$mean),as.double(res$upper),as.double(res$lower),list(fit$alpha, fit$beta, fit$gamma, fit$coefficients))); json;', "+i+" as Measure)";t.displayRScriptsToConsole(r.props.debugMode,[d]);var u=[{qDef:{qDef:i}},{qDef:{qDef:d}},{qDef:{qLabel:"-",qDef:""}},{qDef:{qLabel:"-",qDef:""}},{qDef:{qLabel:"-",qDef:""}}];return a.backendApi.applyPatches([{qPath:"/qHyperCubeDef/qDimensions",qOp:"replace",qValue:JSON.stringify(s)},{qPath:"/qHyperCubeDef/qMeasures",qOp:"replace",qValue:JSON.stringify(u)}],!1),a.patchApplied=!0,null},drawChart:function(o,s){var i=r.defer(),l=o.layout,p=[{qTop:0,qLeft:0,qWidth:6,qHeight:1500}];return o.backendApi.getData(p).then(function(r){if(0===r[0].qMatrix[0][1].qText.length||"-"==r[0].qMatrix[0][1].qText)t.displayConnectionError(o.extId);else{t.displayReturnedDatasetToConsole(l.props.debugMode,r[0]);var p=t.getDefaultPaletteColor(),n=JSON.parse(r[0].qMatrix[0][2].qText),d=n[0],u=n[1],m=n[2],h=n[3],c=h[0],f=h[1],b=h[2];if("undefined"==typeof o.layout.props.displayTable||0==o.layout.props.displayTable){var q={},y=r[0].qMatrix.length,g=[],x=[],v=[];$.each(r[0].qMatrix,function(e,a){g.push(a[0].qElemNumber),x.push(a[0].qText),v.push(a[1].qNum)}),q.elemNum=g,q.dim1=x,q.mea1=v;for(var D=new Array(y),M=new Array(y),w=new Array(y),N=0;Nalpha='+c+", beta="+f+", gamma="+b+'\n
\n '):$(".advanced-analytics-toolsets-"+o.extId).html('
');var A=e.draw(o,S,"aat-chart-"+o.extId,T);e.setEvents(A,o,s)}else{var F=t.getLocale(o,0),L=t.getNumberFormat(o,0),P=(r[0].qMatrix.length,[]);$.each(r[0].qMatrix,function(e,a){P.push([a[0].qElemNumber,a[0].qText,F.format(L)(a[1].qNum).replace(/G/,"B"),"","",""])});for(var W=0;W\n \n \n qElemNumber\n '+o.layout.props.dimensions[0].label+"\n "+o.layout.props.measures[0].label+"\n Fit\n Lower\n Upper\n \n \n \n \n ";a.draw(s,o,"#aat-table-"+o.extId,P,C,null).then(function(e){a.setEvents(e,o,s)})}}return i.resolve()}),i.promise}}}); +"use strict";define(["../chart/line_chart","../chart/datatables","../util/utils","ng!$q","../../vendor/d3-format.min"],function(e,t,a,r,o){return{createCube:function(e,t){var r=t.layout,o=a.validateDimension(r.props.dimensions[0]),s=[{qNullSuppression:!0,qDef:{qFieldDefs:[o]}}],l=a.validateMeasure(r.props.measures[0]),i="";r.props.frequency>0&&(i=",frequency="+r.props.frequency);var p="";r.props.autoHoltWinters||(p=",alpha="+r.props.holtWintersAlpha+",beta="+r.props.holtWintersBeta+",gamma="+r.props.holtWintersGamma),a.displayDebugModeMessage(r.props.debugMode);var n=a.getDebugSaveDatasetScript(r.props.debugMode,"debug_holt_winters.rda"),d="R.ScriptEvalExStr('N', '"+n+" library(jsonlite);library(dplyr);library(forecast);data<-ts(na.omit(q$Measure) "+i+');\n fit<-HoltWinters(data, seasonal="'+r.props.seasonal+'" '+p+");\n res<-forecast(fit, level="+r.props.confidenceLevel+", h="+r.props.forecastingPeriods+");\n json<-toJSON(list(as.double(res$mean),as.double(res$upper),as.double(res$lower),list(fit$alpha, fit$beta, fit$gamma, fit$coefficients))); json;', "+l+" as Measure)";a.displayRScriptsToConsole(r.props.debugMode,[d]);var u=[{qDef:{qDef:l}},{qDef:{qDef:d}},{qDef:{qLabel:"-",qDef:""}},{qDef:{qLabel:"-",qDef:""}},{qDef:{qLabel:"-",qDef:""}}];return t.backendApi.applyPatches([{qPath:"/qHyperCubeDef/qDimensions",qOp:"replace",qValue:JSON.stringify(s)},{qPath:"/qHyperCubeDef/qMeasures",qOp:"replace",qValue:JSON.stringify(u)}],!1),t.patchApplied=!0,null},drawChart:function(o,s){var l=r.defer(),i=o.layout,p=[{qTop:0,qLeft:0,qWidth:6,qHeight:1500}];return o.backendApi.getData(p).then(function(r){var p=null,n=r[0].qMatrix;if(0===n[0][2].qText.length||"-"==n[0][2].qText)for(var d=0;dalpha='+b+", beta="+q+", gamma="+y+'\n
\n '):($(".advanced-analytics-toolsets-"+o.extId).html('
'),$("#aat-chart-"+o.extId).after("test"));var I=e.draw(o,A,"aat-chart-"+o.extId,F);e.setEvents(I,o,s)}else{var L=a.getLocale(o,0),P=a.getNumberFormat(o,0),W=(r[0].qMatrix.length,[]);$.each(r[0].qMatrix,function(e,t){W.push([t[0].qElemNumber,t[0].qText,L.format(P)(t[1].qNum).replace(/G/,"B"),"","",""])});for(var C=0;C\n \n \n qElemNumber\n '+o.layout.props.dimensions[0].label+"\n "+o.layout.props.measures[0].label+"\n Fit\n Lower\n Upper\n \n \n \n \n ";t.draw(s,o,"#aat-table-"+o.extId,W,E,null).then(function(e){t.setEvents(e,o,s)})}}return l.resolve()}),l.promise}}}); //# sourceMappingURL=../../maps/analysis/holt_winters.js.map diff --git a/build/dev/lib/maps/analysis/holt_winters.js.map b/build/dev/lib/maps/analysis/holt_winters.js.map index 74d0513..c105092 100644 --- a/build/dev/lib/maps/analysis/holt_winters.js.map +++ b/build/dev/lib/maps/analysis/holt_winters.js.map @@ -1 +1 @@ -{"version":3,"sources":["analysis/holt_winters.js"],"names":["define","lineChart","datatables","utils","$q","d3","createCube","app","$scope","layout","dimension","validateDimension","props","dimensions","qNullSuppression","qDef","qFieldDefs","measure","validateMeasure","measures","frequency","holtWintersParams","autoHoltWinters","holtWintersAlpha","holtWintersBeta","holtWintersGamma","displayDebugModeMessage","debugMode","saveRDataset","getDebugSaveDatasetScript","defMea1","seasonal","confidenceLevel","forecastingPeriods","displayRScriptsToConsole","qLabel","backendApi","applyPatches","qPath","qOp","qValue","JSON","stringify","patchApplied","drawChart","defer","requestPage","qTop","qLeft","qWidth","qHeight","getData","then","dataPages","qMatrix","qText","length","displayConnectionError","extId","displayReturnedDatasetToConsole","palette","getDefaultPaletteColor","result","parse","mean","upper","lower","params","alpha","beta","gamma","displayTable","datasets","dataLength","elemNum","dim1","mea1","$","each","key","value","push","qElemNumber","qNum","mea2","Array","mea3","mea4","i","chartData","x","y","name","mode","fill","line","fillcolor","colors","colorForMain","marker","color","size","datapoints","pointRadius","width","borderWidth","colorForSub","type","customOptions","xaxis","title","xLabelsAndTitle","label","showgrid","xScale","side","xAxisPosition","displayHoltWintersParams","html","chart","draw","setEvents","locale","getLoc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,OAAOG,MAAMO,SAAS,GAAG6F,MANxC,+OAgBN9G,GAAWsH,KAAKjH,EAAKC,EAArB,cAA2CA,EAAOkD,MAASoE,EAASR,EAAM,MAAMlE,KAAK,SAAC6E,GACpF/H,EAAWuH,UAAUQ,EAAOzH,EAAQD,MAI1C,MAAOsC,GAAMqF,YAERrF,EAAMsF","file":"../../js/analysis/holt_winters.js","sourcesContent":["define([\r\n '../chart/line_chart',\r\n '../chart/datatables',\r\n '../util/utils',\r\n 'ng!$q',\r\n '../../vendor/d3-format.min',\r\n], (lineChart, datatables, utils, $q, d3) => {\r\n return {\r\n /**\r\n * createCube - create HyperCubes\r\n *\r\n * @param {Object} app reference to app\r\n * @param {Object} $scope angular $scope\r\n *\r\n * @return {Null} null\r\n */\r\n createCube(app, $scope) {\r\n const layout = $scope.layout;\r\n\r\n // Display loader\r\n // utils.displayLoader($scope.extId);\r\n\r\n const dimension = utils.validateDimension(layout.props.dimensions[0]);\r\n\r\n // Set definitions for dimensions and measures\r\n const dimensions = [{\r\n qNullSuppression: true,\r\n qDef: {\r\n qFieldDefs: [dimension]\r\n },\r\n }];\r\n const measure = utils.validateMeasure(layout.props.measures[0]);\r\n\r\n let frequency = '';\r\n if (layout.props.frequency > 0) {\r\n frequency = `,frequency=${layout.props.frequency}`;\r\n }\r\n\r\n let holtWintersParams = '';\r\n if (!layout.props.autoHoltWinters) {\r\n holtWintersParams = `,alpha=${layout.props.holtWintersAlpha},beta=${layout.props.holtWintersBeta},gamma=${layout.props.holtWintersGamma}`\r\n }\r\n\r\n // Debug mode - set R dataset name to store the q data.\r\n utils.displayDebugModeMessage(layout.props.debugMode);\r\n const saveRDataset = utils.getDebugSaveDatasetScript(layout.props.debugMode, 'debug_timeseries_forecast.rda');\r\n\r\n const defMea1 = `R.ScriptEvalExStr('N', '${saveRDataset} library(jsonlite);library(dplyr);library(forecast);data<-ts(na.omit(q$Measure) ${frequency});\r\n fit<-HoltWinters(data, seasonal=\"${layout.props.seasonal}\" ${holtWintersParams});\r\n res<-forecast(fit, level=${layout.props.confidenceLevel}, h=${layout.props.forecastingPeriods});\r\n json<-toJSON(list(as.double(res$mean),as.double(res$upper),as.double(res$lower),list(fit$alpha, fit$beta, fit$gamma, fit$coefficients))); json;', ${measure} as Measure)`;\r\n\r\n // Debug mode - display R Scripts to console\r\n utils.displayRScriptsToConsole(layout.props.debugMode, [defMea1]);\r\n\r\n const measures = [\r\n {\r\n qDef: {\r\n qDef: measure,\r\n },\r\n },\r\n {\r\n qDef: {\r\n qDef: defMea1,\r\n },\r\n },\r\n {\r\n qDef: {\r\n qLabel: '-',\r\n qDef: '', // Dummy\r\n },\r\n },\r\n {\r\n qDef: {\r\n qLabel: '-',\r\n qDef: '', // Dummy\r\n },\r\n },\r\n {\r\n qDef: {\r\n qLabel: '-',\r\n qDef: '', // Dummy\r\n },\r\n },\r\n ];\r\n\r\n $scope.backendApi.applyPatches([\r\n {\r\n qPath: '/qHyperCubeDef/qDimensions',\r\n qOp: 'replace',\r\n qValue: JSON.stringify(dimensions),\r\n },\r\n {\r\n qPath: '/qHyperCubeDef/qMeasures',\r\n qOp: 'replace',\r\n qValue: JSON.stringify(measures),\r\n },\r\n ], false);\r\n\r\n $scope.patchApplied = true;\r\n return null;\r\n },\r\n\r\n /**\r\n * drawChart - draw chart with updated data\r\n *\r\n * @param {Object} $scope angular $scope\r\n *\r\n * @return {Object} Promise object\r\n */\r\n drawChart($scope, app) {\r\n const defer = $q.defer();\r\n const layout = $scope.layout;\r\n\r\n // const dimension = utils.validateDimension(layout.props.dimensions[0]);\r\n const requestPage = [{\r\n qTop: 0,\r\n qLeft: 0,\r\n qWidth: 6,\r\n qHeight: 1500,\r\n }];\r\n\r\n $scope.backendApi.getData(requestPage).then((dataPages) => {\r\n if (dataPages[0].qMatrix[0][1].qText.length === 0 || dataPages[0].qMatrix[0][1].qText == '-') {\r\n utils.displayConnectionError($scope.extId);\r\n } else {\r\n // Debug mode - display returned dataset to console\r\n utils.displayReturnedDatasetToConsole(layout.props.debugMode, dataPages[0]);\r\n\r\n const palette = utils.getDefaultPaletteColor();\r\n\r\n const result = JSON.parse(dataPages[0].qMatrix[0][2].qText);\r\n const mean = result[0];\r\n const upper = result[1];\r\n const lower = result[2];\r\n const params = result[3];\r\n\r\n // Holt-Winters parameters\r\n const alpha = params[0];\r\n const beta = params[1];\r\n const gamma = params[2];\r\n\r\n // Chart mode\r\n if (typeof $scope.layout.props.displayTable == 'undefined' || $scope.layout.props.displayTable == false) {\r\n\r\n const datasets = {};\r\n\r\n // Store actual values to datasets\r\n const dataLength = dataPages[0].qMatrix.length;\r\n const elemNum = [];\r\n const dim1 = []; // Dimension\r\n const mea1 = []; // Actual values\r\n\r\n $.each(dataPages[0].qMatrix, (key, value) => {\r\n elemNum.push(value[0].qElemNumber);\r\n dim1.push(value[0].qText);\r\n mea1.push(value[1].qNum);\r\n });\r\n datasets.elemNum = elemNum;\r\n datasets.dim1 = dim1;\r\n datasets.mea1 = mea1;\r\n\r\n // Store forecast values to datasets\r\n const mea2 = new Array(dataLength); // Forecast (mean)\r\n const mea3 = new Array(dataLength); // Forecast (upper)\r\n const mea4 = new Array(dataLength); // Forecast (lower)\r\n\r\n for (let i = 0; i < layout.props.forecastingPeriods; i++) {\r\n datasets.dim1.push(`+${i + 1}`); // Forecast period is displayed as +1, +2, +3...\r\n mea2.push(mean[i]);\r\n mea3.push(upper[i]);\r\n mea4.push(lower[i]);\r\n }\r\n datasets.mea2 = mea2;\r\n datasets.mea3 = mea3;\r\n datasets.mea4 = mea4;\r\n\r\n const chartData = [\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea1,\r\n elemNum: datasets.elemNum,\r\n name: 'Observed',\r\n mode: 'lines+markers',\r\n fill: layout.props.line,\r\n fillcolor: (layout.props.colors) ? `rgba(${palette[3]},0.3)` : `rgba(${palette[layout.props.colorForMain]},0.3)`,\r\n marker: {\r\n color: (layout.props.colors) ? `rgba(${palette[3]},1)` : `rgba(${palette[layout.props.colorForMain]},1)`,\r\n size: (layout.props.datapoints) ? layout.props.pointRadius : 1,\r\n },\r\n line: {\r\n width: layout.props.borderWidth,\r\n },\r\n },\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea2,\r\n name: 'Fit',\r\n mode: 'lines+markers',\r\n marker: {\r\n color: (layout.props.colors) ? `rgba(${palette[7]},1)` : `rgba(${palette[layout.props.colorForSub]},1)`,\r\n size: (layout.props.datapoints) ? layout.props.pointRadius : 1,\r\n },\r\n line: {\r\n width: layout.props.borderWidth,\r\n //color: `rgba(${palette[layout.props.colorForSub]},1)`,\r\n },\r\n },\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea3,\r\n name: 'Upper',\r\n fill: 'tonexty',\r\n fillcolor: `rgba(${palette[layout.props.colorForSub]},0.3)`,\r\n type: 'scatter',\r\n mode: 'none',\r\n },\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea4,\r\n name: 'Lower',\r\n fill: 'tonexty',\r\n fillcolor: `rgba(${palette[layout.props.colorForSub]},0.3)`,\r\n type: 'scatter',\r\n mode: 'none',\r\n },\r\n ];\r\n\r\n const customOptions = {\r\n xaxis: {\r\n type: 'category',\r\n title: $scope.layout.props.xLabelsAndTitle ? $scope.layout.props.dimensions[0].label : '',\r\n showgrid: $scope.layout.props.xScale,\r\n side: $scope.layout.props.xAxisPosition,\r\n },\r\n };\r\n\r\n if (layout.props.displayHoltWintersParams) {\r\n // Display ARIMA parameters\r\n $(`.advanced-analytics-toolsets-${$scope.extId}`)\r\n .html(`\r\n
alpha=${alpha}, beta=${beta}, gamma=${gamma}
\r\n
\r\n `);\r\n } else {\r\n // Hide ARIM parameters\r\n $(`.advanced-analytics-toolsets-${$scope.extId}`).html(`
`);\r\n }\r\n const chart = lineChart.draw($scope, chartData, `aat-chart-${$scope.extId}`, customOptions);\r\n lineChart.setEvents(chart, $scope, app);\r\n\r\n // Table display mode\r\n } else {\r\n // Get locale info\r\n const locale = utils.getLocale($scope, 0);\r\n\r\n // Get number format\r\n const numberFormat = utils.getNumberFormat($scope, 0);\r\n\r\n // Store actual values to datasets\r\n const dataLength = dataPages[0].qMatrix.length;\r\n const dataset = [];\r\n\r\n $.each(dataPages[0].qMatrix, (key, value) => {\r\n dataset.push([\r\n value[0].qElemNumber,\r\n value[0].qText,\r\n locale.format(numberFormat)(value[1].qNum).replace(/G/, 'B'),\r\n '',\r\n '',\r\n '',\r\n ]);\r\n });\r\n\r\n for (let i = 0; i < layout.props.forecastingPeriods; i++) {\r\n dataset.push([\r\n '',\r\n `+${i + 1}`, // Forecast period is displayed as +1, +2, +3...\r\n '',\r\n locale.format(numberFormat)(mean[i]).replace(/G/, 'B'),\r\n locale.format(numberFormat)(upper[i]).replace(/G/, 'B'),\r\n locale.format(numberFormat)(lower[i]).replace(/G/, 'B'),\r\n ]);\r\n }\r\n\r\n const html = `\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
qElemNumber${$scope.layout.props.dimensions[0].label}${$scope.layout.props.measures[0].label}FitLowerUpper
`;\r\n\r\n datatables.draw(app, $scope, `#aat-table-${$scope.extId}`, dataset, html, null).then((table) => {\r\n datatables.setEvents(table, $scope, app);\r\n });\r\n }\r\n }\r\n return defer.resolve();\r\n });\r\n return defer.promise;\r\n },\r\n };\r\n});\r\n"]} \ No newline at end of file +{"version":3,"sources":["analysis/holt_winters.js"],"names":["define","lineChart","datatables","utils","$q","d3","createCube","app","$scope","layout","dimension","validateDimension","props","dimensions","qNullSuppression","qDef","qFieldDefs","measure","validateMeasure","measures","frequency","holtWintersParams","autoHoltWinters","holtWintersAlpha","holtWintersBeta","holtWintersGamma","displayDebugModeMessage","debugMode","saveRDataset","getDebugSaveDatasetScript","defMea1","seasonal","confidenceLevel","forecastingPeriods","displayRScriptsToConsole","qLabel","backendApi","applyPatches","qPath","qOp","qValue","JSON","stringify","patchApplied","drawChart","defer","requestPage","qTop","qLeft","qWidth","qHeight","getData","then","dataPages","result","qMatrix","qText","length","i","parse","displayConnectionError","extId","displayReturnedDatasetToConsole","palette","getDefaultPaletteColor","mean","upper","lower","params","alpha","beta","gamma","displayTable","datasets","dataLength","elemNum","dim1","mea1","$","each","key","value","push","qElemNumber","qNum","mea2","Array","mea3","mea4","chartData","x","y","name","mode","fill","line","fillcolor","colors","colorForMain","marker","color","size","datapoints","pointRadius","width","borderWidth","colorForSub","type","customOptions","xaxis","title","xLabelsAndTitle","label","showgrid","xScale","side","xAxisPosition","displayHoltWintersParams","html","after","chart","draw","setEvents","locale","getLocale","numberFormat","getNumberFormat","dataset","format","replace","table","resolve","promise"],"mappings":"AAAA,YAAAA,SACE,sBACA,sBACA,gBACA,QACA,8BACC,SAACC,EAAWC,EAAYC,EAAOC,EAAIC,GACpC,OASEC,WATK,SASMC,EAAKC,GACd,GAAMC,GAASD,EAAOC,OAKhBC,EAAYP,EAAMQ,kBAAkBF,EAAOG,MAAMC,WAAW,IAG5DA,IACJC,kBAAkB,EAClBC,MACEC,YAAaN,MAGXO,EAAUd,EAAMe,gBAAgBT,EAAOG,MAAMO,SAAS,IAExDC,EAAY,EACZX,GAAOG,MAAMQ,UAAY,IAC3BA,EAAAA,cAA0BX,EAAOG,MAAMQ,UAGzC,IAAIC,GAAoB,EACnBZ,GAAOG,MAAMU,kBAChBD,EAAAA,UAA8BZ,EAAOG,MAAMW,iBAA3C,SAAoEd,EAAOG,MAAMY,gBAAjF,UAA0Gf,EAAOG,MAAMa,kBAIzHtB,EAAMuB,wBAAwBjB,EAAOG,MAAMe,UAC3C,IAAMC,GAAezB,EAAM0B,0BAA0BpB,EAAOG,MAAMe,UAAW,0BAEvEG,EAAAA,2BAAqCF,EAArC,mFAAoIR,EAApI,8CAC6BX,EAAOG,MAAMmB,SAD1C,KACuDV,EADvD,sCAEqBZ,EAAOG,MAAMoB,gBAFlC,OAEwDvB,EAAOG,MAAMqB,mBAFrE,+JAG8IhB,EAH9I,cAMNd,GAAM+B,yBAAyBzB,EAAOG,MAAMe,WAAYG,GAExD,IAA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,QAAS,SAACyB,EAAKC,GACjC8C,EAAQ7C,MACND,EAAM,GAAGE,YACTF,EAAM,GAAGzB,MACTmE,EAAOK,OAAOH,GAAc5C,EAAM,GAAGG,MAAM6C,QAAQ,IAAK,KACxD,GACA,GACA,MAIJ,KAAK,GAAIvE,GAAI,EAAGA,EAAIjD,EAAOG,MAAMqB,mBAAoByB,IACnDqE,EAAQ7C,MACN,GADW,KAEPxB,EAAI,GACR,GACAiE,EAAOK,OAAOH,GAAc5D,EAAKP,IAAIuE,QAAQ,IAAK,KAClDN,EAAOK,OAAOH,GAAc3D,EAAMR,IAAIuE,QAAQ,IAAK,KACnDN,EAAOK,OAAOH,GAAc1D,EAAMT,IAAIuE,QAAQ,IAAK,MAIvD,IAAMX,GAAAA,wCACmB9G,EAAOqD,MAD1B,0IAKQrD,EAAOC,OAAOG,MAAMC,WAAW,GAAGmG,MAL1C,kCAMQxG,EAAOC,OAAOG,MAAMO,SAAS,GAAG6F,MANxC,+OAgBN9G,GAAWuH,KAAKlH,EAAKC,EAArB,cAA2CA,EAAOqD,MAASkE,EAAST,EAAM,MAAMlE,KAAK,SAAC8E,GACpFhI,EAAWwH,UAAUQ,EAAO1H,EAAQD,MAI1C,MAAOsC,GAAMsF,YAERtF,EAAMuF","file":"../../js/analysis/holt_winters.js","sourcesContent":["define([\r\n '../chart/line_chart',\r\n '../chart/datatables',\r\n '../util/utils',\r\n 'ng!$q',\r\n '../../vendor/d3-format.min',\r\n], (lineChart, datatables, utils, $q, d3) => {\r\n return {\r\n /**\r\n * createCube - create HyperCubes\r\n *\r\n * @param {Object} app reference to app\r\n * @param {Object} $scope angular $scope\r\n *\r\n * @return {Null} null\r\n */\r\n createCube(app, $scope) {\r\n const layout = $scope.layout;\r\n\r\n // Display loader\r\n // utils.displayLoader($scope.extId);\r\n\r\n const dimension = utils.validateDimension(layout.props.dimensions[0]);\r\n\r\n // Set definitions for dimensions and measures\r\n const dimensions = [{\r\n qNullSuppression: true,\r\n qDef: {\r\n qFieldDefs: [dimension]\r\n },\r\n }];\r\n const measure = utils.validateMeasure(layout.props.measures[0]);\r\n\r\n let frequency = '';\r\n if (layout.props.frequency > 0) {\r\n frequency = `,frequency=${layout.props.frequency}`;\r\n }\r\n\r\n let holtWintersParams = '';\r\n if (!layout.props.autoHoltWinters) {\r\n holtWintersParams = `,alpha=${layout.props.holtWintersAlpha},beta=${layout.props.holtWintersBeta},gamma=${layout.props.holtWintersGamma}`\r\n }\r\n\r\n // Debug mode - set R dataset name to store the q data.\r\n utils.displayDebugModeMessage(layout.props.debugMode);\r\n const saveRDataset = utils.getDebugSaveDatasetScript(layout.props.debugMode, 'debug_holt_winters.rda');\r\n\r\n const defMea1 = `R.ScriptEvalExStr('N', '${saveRDataset} library(jsonlite);library(dplyr);library(forecast);data<-ts(na.omit(q$Measure) ${frequency});\r\n fit<-HoltWinters(data, seasonal=\"${layout.props.seasonal}\" ${holtWintersParams});\r\n res<-forecast(fit, level=${layout.props.confidenceLevel}, h=${layout.props.forecastingPeriods});\r\n json<-toJSON(list(as.double(res$mean),as.double(res$upper),as.double(res$lower),list(fit$alpha, fit$beta, fit$gamma, fit$coefficients))); json;', ${measure} as Measure)`;\r\n\r\n // Debug mode - display R Scripts to console\r\n utils.displayRScriptsToConsole(layout.props.debugMode, [defMea1]);\r\n\r\n const measures = [\r\n {\r\n qDef: {\r\n qDef: measure,\r\n },\r\n },\r\n {\r\n qDef: {\r\n qDef: defMea1,\r\n },\r\n },\r\n {\r\n qDef: {\r\n qLabel: '-',\r\n qDef: '', // Dummy\r\n },\r\n },\r\n {\r\n qDef: {\r\n qLabel: '-',\r\n qDef: '', // Dummy\r\n },\r\n },\r\n {\r\n qDef: {\r\n qLabel: '-',\r\n qDef: '', // Dummy\r\n },\r\n },\r\n ];\r\n\r\n $scope.backendApi.applyPatches([\r\n {\r\n qPath: '/qHyperCubeDef/qDimensions',\r\n qOp: 'replace',\r\n qValue: JSON.stringify(dimensions),\r\n },\r\n {\r\n qPath: '/qHyperCubeDef/qMeasures',\r\n qOp: 'replace',\r\n qValue: JSON.stringify(measures),\r\n },\r\n ], false);\r\n\r\n $scope.patchApplied = true;\r\n return null;\r\n },\r\n\r\n /**\r\n * drawChart - draw chart with updated data\r\n *\r\n * @param {Object} $scope angular $scope\r\n *\r\n * @return {Object} Promise object\r\n */\r\n drawChart($scope, app) {\r\n const defer = $q.defer();\r\n const layout = $scope.layout;\r\n\r\n // const dimension = utils.validateDimension(layout.props.dimensions[0]);\r\n const requestPage = [{\r\n qTop: 0,\r\n qLeft: 0,\r\n qWidth: 6,\r\n qHeight: 1500,\r\n }];\r\n\r\n $scope.backendApi.getData(requestPage).then((dataPages) => {\r\n\r\n let result = null;\r\n const qMatrix = dataPages[0].qMatrix;\r\n\r\n // Check the result returned from R\r\n if (qMatrix[0][2].qText.length === 0 || qMatrix[0][2].qText == '-') {\r\n for (let i = 0; i < qMatrix.length; i++) {\r\n if (qMatrix[i][2].qText.length !== 0 && qMatrix[i][2].qText !== '-') {\r\n result = JSON.parse(qMatrix[i][2].qText);\r\n }\r\n }\r\n } else {\r\n result = JSON.parse(qMatrix[0][2].qText);\r\n }\r\n\r\n if (result == null) {\r\n utils.displayConnectionError($scope.extId);\r\n } else {\r\n // Debug mode - display returned dataset to console\r\n utils.displayReturnedDatasetToConsole(layout.props.debugMode, dataPages[0]);\r\n\r\n const palette = utils.getDefaultPaletteColor();\r\n\r\n // const result = JSON.parse(dataPages[0].qMatrix[0][2].qText);\r\n const mean = result[0];\r\n const upper = result[1];\r\n const lower = result[2];\r\n const params = result[3];\r\n\r\n // Holt-Winters parameters\r\n const alpha = params[0];\r\n const beta = params[1];\r\n const gamma = params[2];\r\n\r\n // Chart mode\r\n if (typeof $scope.layout.props.displayTable == 'undefined' || $scope.layout.props.displayTable == false) {\r\n\r\n const datasets = {};\r\n\r\n // Store actual values to datasets\r\n const dataLength = dataPages[0].qMatrix.length;\r\n const elemNum = [];\r\n const dim1 = []; // Dimension\r\n const mea1 = []; // Actual values\r\n\r\n $.each(dataPages[0].qMatrix, (key, value) => {\r\n elemNum.push(value[0].qElemNumber);\r\n dim1.push(value[0].qText);\r\n mea1.push(value[1].qNum);\r\n });\r\n datasets.elemNum = elemNum;\r\n datasets.dim1 = dim1;\r\n datasets.mea1 = mea1;\r\n\r\n // Store forecast values to datasets\r\n const mea2 = new Array(dataLength); // Forecast (mean)\r\n const mea3 = new Array(dataLength); // Forecast (upper)\r\n const mea4 = new Array(dataLength); // Forecast (lower)\r\n\r\n for (let i = 0; i < layout.props.forecastingPeriods; i++) {\r\n datasets.dim1.push(`+${i + 1}`); // Forecast period is displayed as +1, +2, +3...\r\n mea2.push(mean[i]);\r\n mea3.push(upper[i]);\r\n mea4.push(lower[i]);\r\n }\r\n datasets.mea2 = mea2;\r\n datasets.mea3 = mea3;\r\n datasets.mea4 = mea4;\r\n\r\n const chartData = [\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea1,\r\n elemNum: datasets.elemNum,\r\n name: 'Observed',\r\n mode: 'lines+markers',\r\n fill: layout.props.line,\r\n fillcolor: (layout.props.colors) ? `rgba(${palette[3]},0.3)` : `rgba(${palette[layout.props.colorForMain]},0.3)`,\r\n marker: {\r\n color: (layout.props.colors) ? `rgba(${palette[3]},1)` : `rgba(${palette[layout.props.colorForMain]},1)`,\r\n size: (layout.props.datapoints) ? layout.props.pointRadius : 1,\r\n },\r\n line: {\r\n width: layout.props.borderWidth,\r\n },\r\n },\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea2,\r\n name: 'Fit',\r\n mode: 'lines+markers',\r\n marker: {\r\n color: (layout.props.colors) ? `rgba(${palette[7]},1)` : `rgba(${palette[layout.props.colorForSub]},1)`,\r\n size: (layout.props.datapoints) ? layout.props.pointRadius : 1,\r\n },\r\n line: {\r\n width: layout.props.borderWidth,\r\n //color: `rgba(${palette[layout.props.colorForSub]},1)`,\r\n },\r\n },\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea3,\r\n name: 'Upper',\r\n fill: 'tonexty',\r\n fillcolor: `rgba(${palette[layout.props.colorForSub]},0.3)`,\r\n type: 'scatter',\r\n mode: 'none',\r\n },\r\n {\r\n x: datasets.dim1,\r\n y: datasets.mea4,\r\n name: 'Lower',\r\n fill: 'tonexty',\r\n fillcolor: `rgba(${palette[layout.props.colorForSub]},0.3)`,\r\n type: 'scatter',\r\n mode: 'none',\r\n },\r\n ];\r\n\r\n const customOptions = {\r\n xaxis: {\r\n type: 'category',\r\n title: $scope.layout.props.xLabelsAndTitle ? $scope.layout.props.dimensions[0].label : '',\r\n showgrid: $scope.layout.props.xScale,\r\n side: $scope.layout.props.xAxisPosition,\r\n },\r\n };\r\n\r\n if (layout.props.displayHoltWintersParams) {\r\n // Display ARIMA parameters\r\n $(`.advanced-analytics-toolsets-${$scope.extId}`)\r\n .html(`\r\n
alpha=${alpha}, beta=${beta}, gamma=${gamma}
\r\n
\r\n `);\r\n } else {\r\n // Hide ARIM parameters\r\n $(`.advanced-analytics-toolsets-${$scope.extId}`).html(`
`);\r\n $(`#aat-chart-${$scope.extId}`).after(\"test\")\r\n }\r\n const chart = lineChart.draw($scope, chartData, `aat-chart-${$scope.extId}`, customOptions);\r\n lineChart.setEvents(chart, $scope, app);\r\n\r\n // Table display mode\r\n } else {\r\n // Get locale info\r\n const locale = utils.getLocale($scope, 0);\r\n\r\n // Get number format\r\n const numberFormat = utils.getNumberFormat($scope, 0);\r\n\r\n // Store actual values to datasets\r\n const dataLength = dataPages[0].qMatrix.length;\r\n const dataset = [];\r\n\r\n $.each(dataPages[0].qMatrix, (key, value) => {\r\n dataset.push([\r\n value[0].qElemNumber,\r\n value[0].qText,\r\n locale.format(numberFormat)(value[1].qNum).replace(/G/, 'B'),\r\n '',\r\n '',\r\n '',\r\n ]);\r\n });\r\n\r\n for (let i = 0; i < layout.props.forecastingPeriods; i++) {\r\n dataset.push([\r\n '',\r\n `+${i + 1}`, // Forecast period is displayed as +1, +2, +3...\r\n '',\r\n locale.format(numberFormat)(mean[i]).replace(/G/, 'B'),\r\n locale.format(numberFormat)(upper[i]).replace(/G/, 'B'),\r\n locale.format(numberFormat)(lower[i]).replace(/G/, 'B'),\r\n ]);\r\n }\r\n\r\n const html = `\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
qElemNumber${$scope.layout.props.dimensions[0].label}${$scope.layout.props.measures[0].label}FitLowerUpper
`;\r\n\r\n datatables.draw(app, $scope, `#aat-table-${$scope.extId}`, dataset, html, null).then((table) => {\r\n datatables.setEvents(table, $scope, app);\r\n });\r\n }\r\n }\r\n return defer.resolve();\r\n });\r\n return defer.promise;\r\n },\r\n };\r\n});\r\n"]} \ No newline at end of file diff --git a/src/lib/js/analysis/holt_winters.js b/src/lib/js/analysis/holt_winters.js index 807ff3d..16b82ff 100644 --- a/src/lib/js/analysis/holt_winters.js +++ b/src/lib/js/analysis/holt_winters.js @@ -43,7 +43,7 @@ define([ // Debug mode - set R dataset name to store the q data. utils.displayDebugModeMessage(layout.props.debugMode); - const saveRDataset = utils.getDebugSaveDatasetScript(layout.props.debugMode, 'debug_timeseries_forecast.rda'); + const saveRDataset = utils.getDebugSaveDatasetScript(layout.props.debugMode, 'debug_holt_winters.rda'); const defMea1 = `R.ScriptEvalExStr('N', '${saveRDataset} library(jsonlite);library(dplyr);library(forecast);data<-ts(na.omit(q$Measure) ${frequency}); fit<-HoltWinters(data, seasonal="${layout.props.seasonal}" ${holtWintersParams});