Commit c1c03ab2 authored by Eirik Alvær's avatar Eirik Alvær
Browse files

updated help texts

parent 322d3386
...@@ -3,102 +3,171 @@ ...@@ -3,102 +3,171 @@
function CommandExecutor() { function CommandExecutor() {
"use strict"; "use strict";
var helpTexts = { var helpTexts = {
'help': { "correlate": {
'description': 'Prints help for one of these commands:', "parameters": "varlist [if]",
'syntax': '[help-topic]', "shortDescription": "Generates a correlation matrix.",
'examples': [ "description": "The correlate command displays the correlation matrix for a group of variables. The varlist is mandatory. ",
"syntax": "correlate varlist [if]",
"examples": [
{ {
'example': 'help tabulate', "example": "correlate gender age income",
'description': 'Provides help about the tabulate function' "description": "Three-way correlation matrix"
}, },
{ {
'example': 'help correlate', "example": "correlate age income if gender == 'male'",
'description': 'Provides help about the correlate function' "description": "Two-way correlation matrix with conditional expression "
} }
], ]
'relatedcommands': ["describe", "topics", "tabulate", "correlate", "help", "drop", "summarize"]
}, },
'topics': { "describe": {
'description': 'lists topics and variables within each topic', "parameters": "[varlist]",
'syntax': '[topic-name]', "shortDescription": "Lists variables from the current dataset.",
'examples': [ "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': 'topics', "example": "describe",
'description': 'List all topics in the data collection' "description": "List all variables and variable metadata in the current dataset"
}, },
{ {
'example': 'topics \'employment\'', "example": "describe gender age income",
'description': 'List sub-topics and variables for a specified topic' "description": "List variable properties for three variables"
} }
] ]
}, },
'describe': { "drop": {
'description': 'lists variables and variable properties from the current dataset', "parameters": "[varlist] [if]",
'syntax': '[varlist]', "shortDescription": "Removes variables or observations from the current dataset.",
'examples': [ "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': 'describe', "example": "drop gender",
'description': 'List all variables and variable properties in the current dataset' "description": "Remove variable “gender” from the current dataset."
}, },
{ {
'example': 'describe gender age income', "example": "drop if age < 5",
'description': 'List variable properties for three variables' "description": "Remove observations where variable age has value less than 5."
} }
] ]
}, },
'variables': { "generate": {
'description': 'lists variables and variable properties from the data collection', "parameters": "newvar = expression [if ...]",
'syntax': '[varlist]', "shortDescription": "Creates new variable as per the expression defined. CURRENTLY NOT SUPPORTED",
'examples': [ "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': 'variables', "example": "generate fakeVar = age + 5",
'description': 'List all variables and variable properties in the data collection' "description": "Create a variable called "fakeVar". The value for each case will be the value of variable age plus five."
}, },
{ {
'example': 'variables gender age income', "example": "generate fakeVar = age + 5 if gender = 0",
'description': 'List variable properties for three variables' "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."
} }
] ]
}, },
'tabulate': { "import": {
'description': 'generate tables of frequencies with one or more variables', "parameters": "registervar timestamp [as] [newvar]",
'syntax': 'varname1 [varname2] [if] [, options]', "shortDescription": "Creates a new status variable from the register variable.",
'examples': [ "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': 'tabulate gender age', "example": "import UTVALG_WLONN '2011-11-11'",
'description': 'Two-way tabulation' "description": "A new status variable with default name is created from the register variable UTVALG_WLONN with timestamp ‘2011-11-11’"
}, },
{ {
'example': 'tabulate gender age, summarize(income)', "example": "import F_REHAB_INNV_GRAD '2011-11-11' as rehab2011",
'description': 'Two-way tabulation with included summary statistics for income' "description": "A new status variable with rehab2011 as name is created from the register variable F_REHAB_INNV_GRAD with timestamp ‘2011-11-11’"
}
]
},
"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"
} }
] ]
}, },
'correlate': { "summarize": {
'description': 'generate a correlation matrix', "parameters": "varlist [if]",
'syntax': '[varlist] [if]', "shortDescription": "List summary statistics for variables.",
'examples': [ "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': 'correlate gender age income', "example": "summarize age income",
'description': 'Three-way correlation matrix' "description": "Display summary statistics for two variables"
}, },
{ {
'example': 'correlate age income if gender == \'male\'', "example": "summarize age income if age > 45",
'description': 'Two-way correlation matrix with conditional expression' "description": "Display summary statistics for two variables with a conditional expression"
} }
] ]
}, },
'summarize': { "tabulate": {
'description': 'list summary statistics for variables', "parameters": "varname1 [varname2] [if]",
'syntax': '[varlist] [if]', "shortDescription": "Generate tables of frequencies with one or more variables.",
'examples': [ "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]",
"examples": [
{ {
'example': 'summarize age income', "example": "tabulate gender age",
'description': 'List summary statistics for two variables' "description": "Two-way tabulation"
}, },
{ {
'example': 'summarize age income if age > 45', "example": "tabulate gender age if age > 5",
'description': 'List summary statistics for two variables with a conditional expression' "description": "Two-way tabulation with a conditional expression."
}
]
},
"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."
} }
] ]
} }
...@@ -126,6 +195,14 @@ function CommandExecutor() { ...@@ -126,6 +195,14 @@ function CommandExecutor() {
}); });
}; };
function addHelpCommands(helpText) {
helpCommands = helpTexts.keys();
helpCommands.sort();
helpCommands.forEach(function (helpCommand) {
helpText.description += " " + helpCommand;
})
}
return { return {
//Eww! This method should not be exported, but it has to be done to //Eww! This method should not be exported, but it has to be done to
//enable mocking for the tests //enable mocking for the tests
...@@ -145,6 +222,9 @@ function CommandExecutor() { ...@@ -145,6 +222,9 @@ function CommandExecutor() {
switch (parserObject.type) { switch (parserObject.type) {
case "help": case "help":
helpText = helpTexts[parserObject.helpTopic || "help"]; helpText = helpTexts[parserObject.helpTopic || "help"];
if (!parserObject.helpTopic) {
addHelpCommands(helpText);
}
intermediateResult = new Promise(function (resolve) { intermediateResult = new Promise(function (resolve) {
resolve(helpText ? resolve(helpText ?
{result: helpText} : {result: helpText} :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment