Commit f744e14b authored by Kjetil Thuen's avatar Kjetil Thuen
Browse files

Use string literal to call Promis func to make closure compiler happy

parent bf6b8cf1
/*global Promise, XMLHttpRequest */
/*jshint -W069 */
function CommandExecutor() {
"use strict";
var helpTexts = {
"ci": {
"parameters": "varlist [, options]",
"shortDescription": "Displays confidence intervals and standard errors for the variables.",
"description": "The command ci displays standard errors and confidence intervals for each of the variables in varlist.",
"syntax": "ci varlist [, options]",
"examples": [
{
"example": "ci income2004",
"description": "Displays confidence intervals with default level set at 95% and standard errors for the variable income2004."
},
{
"example": "ci income2004 income2003 , level(90)",
"description": "Displays confidence intervals with level set at 90% and standard errors for the variable income2004 and income2003"
}
],
"options" : [
{
"name" : "level(#)",
"shortDescription" : "Set confidence level; default is level(95)",
"description" : "Specifies the confidence level, as a percentage, for confidence intervals. The default is set at 95% and can be set to desired via this."
}
]
},
"correlate": {
"parameters": "varlist [if] [, options]",
"shortDescription": "Generates a correlation matrix.",
"description": "The correlate command displays the correlation matrix for a group of variables. The varlist is mandatory. ",
"syntax": "correlate varlist [if] [, options]",
"examples": [
{
"example": "correlate gender age income",
"description": "Three-way correlation matrix"
},
{
"example": "correlate age income if gender == 'male'",
"description": "Two-way correlation matrix with conditional expression "
}
],
"options" : [
{
"name" : "covariance",
"shortDescription" : "Display covariances",
"description" : "The covariances for the variables are displayed rather than the correlation coefficients."
}
]
},
"describe": {
"parameters": "[varlist]",
"shortDescription": "Lists variables from the current dataset.",
"description": "The command describe displays variables along with available metadata from the current dataset. If [varlist] is not specified, all variables in the dataset are displayed. To get metadata for specific variables, they need to be specified.",
"syntax": "describe [varlist]",
"examples": [
{
"example": "describe",
"description": "List all variables and variable metadata in the current dataset"
},
{
"example": "describe gender age income",
"description": "List variable properties for three variables"
}
]
},
"drop": {
"parameters": "[varlist] [if]",
"shortDescription": "Removes variables or observations from the current dataset.",
"description": "The command drop removes variables or observations from the current dataset. Either the [varlist] or the [if] statement need to be specified. Both can not be specified together. When the [varlist] is specified the variable column is removed from the dataset. And, when the [if] statement is specified, observations (rows) matching the condition are removed from the dataset.\n\nThe drop command is irreversible.",
"syntax": "drop [varlist] [if]",
"examples": [
{
"example": "drop gender",
"description": "Remove variable \"gender\" from the current dataset."
},
{
"example": "drop if age < 5",
"description": "Remove observations where variable age has value less than 5."
}
]
},
"generate": {
"parameters": "newvar = expression [if ...]",
"shortDescription": "Creates new variable as per the expression defined. CURRENTLY NOT SUPPORTED",
"description": "The command generate creates a new variable where its values are as per the expression defined.\n\nThe type of new variable will be determined by the result returned by the expression.\nThe arithmetic functions supported are +, - , *, / and ^ . \n\nCURRENTLY NOT SUPPORTED",
"syntax": "generate newvar =exp [if ...]",
"examples": [
{
"example": "generate fakeVar = age + 5",
"description": "Create a variable called \"fakeVar\". The value for each case will be the value of variable age plus five."
},
{
"example": "generate fakeVar = age + 5 if gender = 0",
"description": "As above, but only when gender is equal to zero. Value of fakeVar will otherwise be missing"
}
]
},
"help": {
"parameters": "commandName",
"shortDescription": "Displays documentation of the command.",
"description": "The commands supported are:",
"syntax": "help commandName",
"examples": [
{
"example": "help tabulate",
"description": "Documentation of the tabulate command is displayed."
}
]
},
"import": {
"parameters": "registervar timestamp [as] [newvar]",
"shortDescription": "Creates a new status variable from the register variable.",
"description": "The command import creates a new status variable in the current dataset from the register variable at the specified timestamp. When the new status variable name is not specified, a default name is assigned.",
"syntax": "import registervar timestamp [as] [newstatusvar]",
"examples": [
{
"example": "import UTVALG_WLONN '2011-11-11'",
"description": "A new status variable with default name is created from the register variable UTVALG_WLONN with timestamp ‘2011-11-11’"
},
{
"example": "import F_REHAB_INNV_GRAD '2011-11-11' as rehab2011",
"description": "A new status variable with rehab2011 as name is created from the register variable F_REHAB_INNV_GRAD with timestamp ‘2011-11-11’"
}
]
},
"pwcorr": {
"parameters": "varlist [if] [, options]",
"shortDescription": "Generates pairwise correlation matrix.",
"description": "The pwcorr command displays the pairwise correlation matrix for a group of variables. The varlist is mandatory. Missing values are by default handled by pairwise deletion. ",
"syntax": "pwcorr varlist [if] [, options]",
"examples": [
{
"example": "pwcorr gender age income",
"description": "Three-way pairwise correlation matrix"
},
{
"example": "pwcorr age income if gender == 'male' , obs sig ",
"description": "Two-way pairwise correlation matrix with conditional expression. Number of observations and significance levels are display. "
}
],
"options" : [
{
"name" : "listwise",
"shortDescription" : "Use listwise deletion to handle missing values",
"description" : "Overrides the default pairwise deletion with listwise deletion in handling the missing values."
},
{
"name" : "obs",
"shortDescription" : "Display number of observations for each entry",
"description" : "The matrix includes the number of observations used to calculate the correlation coefficient for each entry."
},
{
"name" : "sig",
"shortDescription" : "Display the level of significance for each entry",
"description" : "The matrix includes the level of significance used to calculate the correlation coefficient for each entry."
}
]
},
"recode": {
"parameters": "varlist (rule) [(rule) ...] [, generate(newvar)]",
"shortDescription": "Recode categorical variables. CURRENTLY NOT SUPPORTED",
"description": "The command recode creates a new status variable in the current dataset from the existing status variable where its values are as per the specified rules. Values that do not meet any of the conditions of the rules are left unchanged, unless an otherwise rule is specified. When the new status variable name is not specified, a default name is assigned.",
"syntax": "recode varlist rule [(rule) ...] [, generate(newvar)]",
"examples": [
{
"example": "recode v001 (1 3 = 1) (4/7 = 2) (missing = .) (* = 9), gen(v001b)",
"description": "recode v001 so that values 1 and 3 are recoded to 4,\nvalues 4 through 7 are recoded to 2,\nall missing values are recoded to sysmiss and\nall other values (including 2) are recoded to 9.\nCURRENTLY NOT SUPPORTED"
}
]
},
"regress": {
"parameters": "depvar indepvarlist [, options]",
"shortDescription": "Displays linear regression for the variables.",
"description": "The command regress fits a model of dependent variable on the independent variables using linear regression.",
"syntax": "regress depvar indepvarlist [, options]",
"examples": [
{
"example": "regress income2004 income2003",
"description": "Displays linear regression model for income2004 based on income2003 with default confidence interval level set at 95%."
},
{
"example": "ci income2004 income2003 , level(90)",
"description": "Displays linear regression model for income2004 based on income2003 with confidence interval level set at 90%."
}
],
"options" : [
{
"name" : "noconstant",
"shortDescription" : "Suppress constant term",
"description" : "Suppresses the constant term (the y intercept) in the model"
},
{
"name" : "level(#)",
"shortDescription" : "Set confidence level; default is level(95)",
"description" : "Specifies the confidence level, as a percentage, for confidence intervals. The default is set at 95% and can be set to desired via this."
}
]
},
"summarize": {
"parameters": "varlist [if]",
"shortDescription": "List summary statistics for variables.",
"description": "The command summarize displays univariant summary statistics of the status variables. If no varlist is specified then summary statistics for all variables in current dataset are displayed. When a condition is specified the summary is displayed only if it is met.",
"syntax": "summarize varlist [if]",
"examples": [
{
"example": "summarize age income",
"description": "Display summary statistics for two variables"
},
{
"example": "summarize age income if age > 45",
"description": "Display summary statistics for two variables with a conditional expression"
}
]
},
"tabulate": {
"parameters": "varname1 [varname2] [if] [, options]",
"shortDescription": "Generate tables of frequencies with one or more variables.",
"description": "The command tabulate displays univariant summary statistics of the status variables. When a condition is specified the subset of the cases that match the condition are displayed.",
"syntax": "tabulate varname1 [varname2] [if] [, options]",
"examples": [
{
"example": "tabulate gender age",
"description": "Two-way tabulation"
},
{
"example": "tabulate gender age if age > 5",
"description": "Two-way tabulatiton with a conditional expression."
}
],
"options" : [
{
"name" : "missing",
"shortDescription" : "Treat missing values like other values",
"description" : "The missing values are treated like any other value in calculations of counts, percentages, and other statistics."
},
{
"name" : "nolabel",
"shortDescription" : "Display numeric codes for the categories rather than value labels",
"description" : "The numeric codes of the categories are requested to be displayed rather than the value labels."
}
]
},
"topics": {
"parameters": "[topiclist]",
"shortDescription": "Displays topics and register variables within each topic.",
"description": "The command topics displays topics along with their metadata. When a topiclist is specified topic metadata along with the register variables within it are displayed.",
"syntax": "topics [topiclist]",
"examples": [
{
"example": "topics",
"description": "Displays all topics along with metadata."
},
{
"example": "topics ‘demography’",
"description": "Displays metadata for the specified topic along with sub-topics and register variables within it."
}
]
},
"variables": {
"parameters": "[regvarlist]",
"shortDescription": "Displays register variables.",
"description": "The command variables displays register variables along with their metadata. When a regvarlist is specified metadata for them is displayed.",
"syntax": "variables [regvarlist]",
"examples": [
{
"example": "variables",
"description": "Displays all register variables along with their metadata."
},
{
"example": "variables F_REHAB_INNV_GRAD UTVALG_WLONN",
"description": "Displays metadata for the specified register variables."
}
]
}
},
req = new XMLHttpRequest(),
ajaxPostPromise = function (postData, url) {
return new Promise(function (resolve, reject) {
req.open('POST', url);
req.onload = function () {
if (req.status === 200) {
resolve(JSON.parse(req.response));
} else {
reject(JSON.parse(req.response));
}
};
req.onerror = function () {
reject({error: {type: "NETWORK", message: "Network Error"}});
};
// Make the request
req.send(JSON.stringify(postData));
});
},
helpCommands = Object.keys(helpTexts).sort();
/*jslint sub: true */
helpTexts["help"].description = [helpTexts["help"].description, helpCommands];
/*jslint sub: false */
return {
//Eww! This method should not be exported, but it has to be done to
//enable mocking for the tests
requestControllerResult: function (parserObj, controllerUrl) {
return ajaxPostPromise(parserObj, controllerUrl);
},
abort: function () {
if (req.readyState !== 0) {
req.abort();
}
},
execute: function (parserObject, controllerUrl, sessionId, callbackFun, errorFun) {
var intermediateResult,
helpText,
timeBeforeExecute = (new Date()).getTime();
switch (parserObject.type) {
case "help":
helpText = helpTexts[parserObject.helpTopic || "help"];
intermediateResult = new Promise(function (resolve) {
resolve(helpText ?
{
result: helpText,
"runTimeMillis": (new Date()).getTime() - timeBeforeExecute || 1
} :
{error: { type: "NO_RESULT", message: "Got no result"}}
);
});
break;
case "history":
intermediateResult = new Promise(function (resolve) {
resolve({result: "history"});
});
break;
default:
if (sessionId) {
parserObject.sessionId = sessionId;
}
intermediateResult = this.requestControllerResult(parserObject, controllerUrl);
break;
}
return intermediateResult.then(callbackFun, errorFun);
},
getShortHelpDescription: function (command) {
if (helpTexts[command]) {
/*jslint sub: true */
return helpTexts[command]["shortDescription"];
}
},
getParameters: function (command) {
if (helpTexts[command]) {
/*jslint sub: true */
return helpTexts[command]["parameters"];
}
}
};
}
\ No newline at end of file
/*global Promise, XMLHttpRequest */
/*jshint -W069 */
function CommandExecutor() {
"use strict";
var helpTexts = {
"ci": {
"parameters": "varlist [, options]",
"shortDescription": "Displays confidence intervals and standard errors for the variables.",
"description": "The command ci displays standard errors and confidence intervals for each of the variables in varlist.",
"syntax": "ci varlist [, options]",
"examples": [
{
"example": "ci income2004",
"description": "Displays confidence intervals with default level set at 95% and standard errors for the variable income2004."
},
{
"example": "ci income2004 income2003 , level(90)",
"description": "Displays confidence intervals with level set at 90% and standard errors for the variable income2004 and income2003"
}
],
"options" : [
{
"name" : "level(#)",
"shortDescription" : "Set confidence level; default is level(95)",
"description" : "Specifies the confidence level, as a percentage, for confidence intervals. The default is set at 95% and can be set to desired via this."
}
]
},
"correlate": {
"parameters": "varlist [if] [, options]",
"shortDescription": "Generates a correlation matrix.",
"description": "The correlate command displays the correlation matrix for a group of variables. The varlist is mandatory. ",
"syntax": "correlate varlist [if] [, options]",
"examples": [
{
"example": "correlate gender age income",
"description": "Three-way correlation matrix"
},
{
"example": "correlate age income if gender == 'male'",
"description": "Two-way correlation matrix with conditional expression "
}
],
"options" : [
{
"name" : "covariance",
"shortDescription" : "Display covariances",
"description" : "The covariances for the variables are displayed rather than the correlation coefficients."
}
]
},
"describe": {
"parameters": "[varlist]",
"shortDescription": "Lists variables from the current dataset.",
"description": "The command describe displays variables along with available metadata from the current dataset. If [varlist] is not specified, all variables in the dataset are displayed. To get metadata for specific variables, they need to be specified.",
"syntax": "describe [varlist]",
"examples": [
{
"example": "describe",
"description": "List all variables and variable metadata in the current dataset"
},
{
"example": "describe gender age income",
"description": "List variable properties for three variables"
}
]
},
"drop": {
"parameters": "[varlist] [if]",
"shortDescription": "Removes variables or observations from the current dataset.",
"description": "The command drop removes variables or observations from the current dataset. Either the [varlist] or the [if] statement need to be specified. Both can not be specified together. When the [varlist] is specified the variable column is removed from the dataset. And, when the [if] statement is specified, observations (rows) matching the condition are removed from the dataset.\n\nThe drop command is irreversible.",
"syntax": "drop [varlist] [if]",
"examples": [
{
"example": "drop gender",
"description": "Remove variable \"gender\" from the current dataset."
},
{
"example": "drop if age < 5",
"description": "Remove observations where variable age has value less than 5."
}
]
},
"generate": {
"parameters": "newvar = expression [if ...]",
"shortDescription": "Creates new variable as per the expression defined. CURRENTLY NOT SUPPORTED",
"description": "The command generate creates a new variable where its values are as per the expression defined.\n\nThe type of new variable will be determined by the result returned by the expression.\nThe arithmetic functions supported are +, - , *, / and ^ . \n\nCURRENTLY NOT SUPPORTED",
"syntax": "generate newvar =exp [if ...]",
"examples": [
{
"example": "generate fakeVar = age + 5",
"description": "Create a variable called \"fakeVar\". The value for each case will be the value of variable age plus five."
},
{
"example": "generate fakeVar = age + 5 if gender = 0",
"description": "As above, but only when gender is equal to zero. Value of fakeVar will otherwise be missing"
}
]
},
"help": {
"parameters": "commandName",
"shortDescription": "Displays documentation of the command.",
"description": "The commands supported are:",
"syntax": "help commandName",
"examples": [
{
"example": "help tabulate",
"description": "Documentation of the tabulate command is displayed."
}
]
},
"import": {
"parameters": "registervar timestamp [as] [newvar]",
"shortDescription": "Creates a new status variable from the register variable.",
"description": "The command import creates a new status variable in the current dataset from the register variable at the specified timestamp. When the new status variable name is not specified, a default name is assigned.",
"syntax": "import registervar timestamp [as] [newstatusvar]",
"examples": [
{
"example": "import UTVALG_WLONN '2011-11-11'",
"description": "A new status variable with default name is created from the register variable UTVALG_WLONN with timestamp ‘2011-11-11’"
},
{
"example": "import F_REHAB_INNV_GRAD '2011-11-11' as rehab2011",
"description": "A new status variable with rehab2011 as name is created from the register variable F_REHAB_INNV_GRAD with timestamp ‘2011-11-11’"
}
]
},
"pwcorr": {
"parameters": "varlist [if] [, options]",
"shortDescription": "Generates pairwise correlation matrix.",
"description": "The pwcorr command displays the pairwise correlation matrix for a group of variables. The varlist is mandatory. Missing values are by default handled by pairwise deletion. ",
"syntax": "pwcorr varlist [if] [, options]",
"examples": [
{
"example": "pwcorr gender age income",
"description": "Three-way pairwise correlation matrix"
},
{
"example": "pwcorr age income if gender == 'male' , obs sig ",
"description": "Two-way pairwise correlation matrix with conditional expression. Number of observations and significance levels are display. "
}
],
"options" : [
{
"name" : "listwise",
"shortDescription" : "Use listwise deletion to handle missing values",
"description" : "Overrides the default pairwise deletion with listwise deletion in handling the missing values."
},
{
"name" : "obs",
"shortDescription" : "Display number of observations for each entry",
"description" : "The matrix includes the number of observations used to calculate the correlation coefficient for each entry."
},
{
"name" : "sig",
"shortDescription" : "Display the level of significance for each entry",
"description" : "The matrix includes the level of significance used to calculate the correlation coefficient for each entry."
}
]
},
"recode": {
"parameters": "varlist (rule) [(rule) ...] [, generate(newvar)]",
"shortDescription": "Recode categorical variables. CURRENTLY NOT SUPPORTED",
"description": "The command recode creates a new status variable in the current dataset from the existing status variable where its values are as per the specified rules. Values that do not meet any of the conditions of the rules are left unchanged, unless an otherwise rule is specified. When the new status variable name is not specified, a default name is assigned.",
"syntax": "recode varlist rule [(rule) ...] [, generate(newvar)]",
"examples": [
{
"example": "recode v001 (1 3 = 1) (4/7 = 2) (missing = .) (* = 9), gen(v001b)",
"description": "recode v001 so that values 1 and 3 are recoded to 4,\nvalues 4 through 7 are recoded to 2,\nall missing values are recoded to sysmiss and\nall other values (including 2) are recoded to 9.\nCURRENTLY NOT SUPPORTED"
}
]
},
"regress": {
"parameters": "depvar indepvarlist [, options]",
"shortDescription": "Displays linear regression for the variables.",
"description": "The command regress fits a model of dependent variable on the independent variables using linear regression.",
"syntax": "regress depvar indepvarlist [, options]",
"examples": [
{
"example": "regress income2004 income2003",
"description": "Displays linear regression model for income2004 based on income2003 with default confidence interval level set at 95%."
},
{
"example": "ci income2004 income2003 , level(90)",
"description": "Displays linear regression model for income2004 based on income2003 with confidence interval level set at 90%."
}
],
"options" : [
{
"name" : "noconstant",
"shortDescription" : "Suppress constant term",
"description" : "Suppresses the constant term (the y intercept) in the model"
},
{
"name" : "level(#)",
"shortDescription" : "Set confidence level; default is level(95)",
"description" : "Specifies the confidence level, as a percentage, for confidence intervals. The default is set at 95% and can be set to desired via this."
}
]
},
"summarize": {
"parameters": "varlist [if]",
"shortDescription": "List summary statistics for variables.",
"description": "The command summarize displays univariant summary statistics of the status variables. If no varlist is specified then summary statistics for all variables in current dataset are displayed. When a condition is specified the summary is displayed only if it is met.",
"syntax": "summarize varlist [if]",
"examples": [
{
"example": "summarize age income",
"description": "Display summary statistics for two variables"
},
{
"example": "summarize age income if age > 45",
"description": "Display summary statistics for two variables with a conditional expression"
}
]
},
"tabulate": {
"parameters": "varname1 [varname2] [if] [, options]",
"shortDescription": "Generate tables of frequencies with one or more variables.",
"description": "The command tabulate displays univariant summary statistics of the status variables. When a condition is specified the subset of the cases that match the condition are displayed.",
"syntax": "tabulate varname1 [varname2] [if] [, options]",
"examples": [
{
"example": "tabulate gender age",
"description": "Two-way tabulation"
},
{
<