This page documents the specific JavaScript variables, helper functions, and built-in classes that are available in JavaScript action boxes.
| Variable | Description |
|---|---|
nPinIn |
Number of input pins. |
nPinOut |
Number of output pins. |
isVariableNPinIn |
true/false – Indicates if the action box supports a variable number of input pins. |
isVariableNPinOut |
true/false – Indicates if the action box supports a variable number of output pins. |
installDir |
Full path to the installation directory. |
| Function | Description |
|---|---|
getTrace() |
Returns the current trace configuration (trace level + trace filter). |
setTraceLevel(level) |
Sets the trace verbosity level. |
setTrace(filter) |
Sets a trace filter string (used to limit what is traced). |
getActionName(actionId) |
Returns the action name for the given action ID. |
getActionId(actionName) |
Returns the action ID for the given action name. |
getActionVersion(actionId) |
Returns the version of an action (by action ID). |
getActionInfo(actionId) |
Returns a string describing the action (by action ID). |
rowToArray(rowObject) |
Converts a Row into a JavaScript array containing all column values. |
printRow(rowObject) |
Prints the row content into the log window. |
clearLog() |
Clears the BRAND log window. |
| Function | Description |
|---|---|
getPinName(pinId) |
Returns the pin name for a given pin ID. |
getPinId(pinName) |
Returns the pin ID for a given pin name. |
getPinType(pinId) |
Returns the pin type (input/output). |
getPinDim(pinId) |
Returns the dimension settings of a pin. |
setPinDim(pinId, pinDim) |
Sets the dimension settings of a pin. |
getPinSize(pinId) |
Returns the number of columns of a pin. |
setPinSize(pinId, pinSize) |
Sets the number of columns of a pin. |
| Function | Description |
|---|---|
getPinColumnName(pinId, colId) |
Returns the column name for column colId on pin pinId. |
setPinColumnName(pinId, colId, colName) |
Sets the column name for column colId on pin pinId. |
addPinColumnName(pinId, colName) |
Adds a new column name on the pin and returns its column index (implementation-dependent). |
removePinColumnName(pinId, colName) |
Removes a column by name from the pin definition. |
getPinColumnId(pinId, colName) |
Returns the column index of colName on the given pin. |
These helpers are used to keep or drop columns from a column list (typically used by action boxes that dynamically reshape data).
| Function | Description |
|---|---|
dropAllColumns(columnList) |
Drops all columns from the provided column list. |
dropColumn(columnList, colId) |
Drops one column by column index from the list. |
keepColumn(columnList, colId) |
Keeps only the specified column(s) inside the list. |
| Function | Description |
|---|---|
rowSetAllColumns(rowObject, value) |
Sets all columns in rowObject to the provided string value. |
| Function | Description |
|---|---|
rowWriteConstant(rowObject, outputPinIndex, value) |
Writes a row to the given output pin, filling columns with the constant value (implementation-dependent behavior may combine with existing row content). |
rowWriteNull(rowObject, outputPinIndex) |
Writes a NULL row to the given output pin. |
| Function | Description |
|---|---|
getCurrentRow(inputPinIndex) |
Returns the current Row from the given input pin index. |
rowDeepCopy(rowObject) |
Creates a deep copy of a row (safe to modify without changing the original). |
rowGetIndexOfColumn(rowObject, colName) |
Returns the column index in the row for the given column name. |
dirList(directory, file_filter, sort_mode, dir_filter)Returns an array of objects. Each element contains information about a file or directory.
sort_mode and dir_filter are optional.
Default values when omitted:
sort_mode = DirSort_ByName + DirSort_IgnoreCasedir_filter = DirFilter_AllEntriesExample (prints the absolute path to the first file found in the current directory):
var d = dirList("./", "*.brand");
print(d[0].absolutePath + "/" + d[0].fileName);
Fields in each returned element
absolutePath – path only (does not include the filename)fileNamecreated – JavaScript Date objectmodified – JavaScript Date objectisDirisFileisHiddenisReadableisWritableisExecutablesort_mode flags| Constant | Value | Description |
|---|---|---|
DirSort_ByName |
0x00 |
Sort by name. |
DirSort_ByTime |
0x01 |
Sort by time (modification time). |
DirSort_BySize |
0x02 |
Sort by file size. |
DirSort_ByExtension |
0x80 |
Sort by file type (extension). |
DirSort_DoNotSort |
0x03 |
Do not sort. |
DirSort_DirsFirst |
0x04 |
Put directories first, then files. |
DirSort_DirsLast |
0x20 |
Put files first, then directories. |
DirSort_Reversed |
0x08 |
Reverse the sort order. |
DirSort_IgnoreCase |
0x10 |
Sort case-insensitively. |
DirSort_LocaleAware |
0x40 |
Sort using current locale rules. |
dir_filter flags| Constant | Value | Description |
|---|---|---|
DirFilter_Dirs |
0x001 |
List directories that match filters. |
DirFilter_AllDirs |
0x400 |
List all directories (don’t apply filters to directory names). |
DirFilter_Files |
0x002 |
List files. |
DirFilter_Drives |
0x004 |
List disk drives (ignored under Unix). |
DirFilter_NoSymLinks |
0x008 |
Do not list symbolic links (ignored if not supported). |
DirFilter_NoDotAndDotDot |
0x1000 |
Do not list . and ... |
DirFilter_NoDot |
0x2000 |
Do not list .. |
DirFilter_NoDotDot |
0x4000 |
Do not list ... |
DirFilter_AllEntries |
Dirs \| Files \| Drives |
Lists directories, files, drives and symlinks (unless restricted). |
DirFilter_Readable |
0x010 |
Only list readable entries (must be combined with Dirs or Files). |
DirFilter_Writable |
0x020 |
Only list writable entries (must be combined with Dirs or Files). |
DirFilter_Executable |
0x040 |
Only list executable entries (must be combined with Dirs or Files). |
DirFilter_Modified |
0x080 |
Only list files modified recently (ignored on Unix). |
DirFilter_Hidden |
0x100 |
List hidden files (on Unix: starts with .). |
DirFilter_System |
0x200 |
List system files (Unix: includes FIFOs/sockets/devices; Windows: includes .lnk). |
DirFilter_CaseSensitive |
0x800 |
Make filtering case-sensitive. |
fileBinaryLoad(fileName, startOffset, length)Returns an object that contains the binary content of the file fileName.
startOffset and length are optional
Defaults:
startOffset = 0length = full sizefileSave(fileName, fileContent, encoding)Saves fileContent into the text file fileName.
encoding is optionalencoding = 0Encoding values:
encoding = 0: UTF-16 (with BOM)encoding = 1: UTF-8 (with BOM)encoding = 2: UTF-8 (without BOM)encoding = 3: local system-wide 8-bit encoding (without BOM)mkDir(path)Creates a new directory (including parent directories).
Returns true if successful.
fileExist(filename)Tests if a file or directory exists.
Return value:
0: no file or directory exists1: a file exists2: a directory existsfileMove(source, destination, alsoMoveDirs)Moves a file or directory.
alsoMoveDirs optional, default falsealsoMoveDirs = truetrue if successfulfileCopy(source, destination, alsoCopyDirs)Copies a file or directory.
alsoCopyDirs optional, default falsealsoCopyDirs = truetrue if successfulfileDelete(filename, forceDelete)Deletes a file or directory.
forceDelete optional, default falseforceDelete = truetrue if successfulfileLoad(filename, encoding)Returns a string containing the file content.
If encoding is omitted, BRAND assumes the file is in the local system-wide encoding
Otherwise:
encoding = 0: UTF-16encoding = 1: UTF-8If the file contains a BOM, the BOM encoding is used automatically.
| Function | Description |
|---|---|
getEnv(name) |
Returns the value of the specified DOS environment variable. |
urlEncode(string) |
Encodes a string so it can be used inside a URL parameter. (LIB: MathParser) |
jsonEncode(string) |
Encodes a string so it can be used inside a JSON file. (LIB: MathParser) |
xmlEncode(string) |
Encodes a string so it can be used inside an XML file. (LIB: MathParser) |
sleep(ms) |
Waits for ms milliseconds. |
isNumber(x, strict) |
Tests whether x can be converted to a number. strict optional (default true). |
toNumber(x) |
Converts x to a Number using BRAND advanced routines (accepts NaN, NULL, Inf, -Inf and ignores trailing junk). |
isLinux() |
Returns true if BRAND runs inside Wine on Linux (registry-based detection). |
commandLineToArray(s) |
Converts command-line parameter string into a JS array (Windows CMD parsing rules). |
print(string) |
Prints a string into the BRAND log window. |
exit(exitcode) |
Aborts graph execution immediately and stops the whole BRAND process. exitcode optional (default 0). Use with extreme caution. |
trim(string) |
Trims whitespace from start and end ('\t' '\n' '\v' '\f' '\r' ' '). |
DateUTC() |
Returns the current DateTime in UTC. |
getTimeOfDay(datetime) |
Returns the time part of the JavaScript Date object datetime. |
getDayMonthYear(datetime) |
Returns the date part of the JavaScript Date object datetime. |
weekNumber(datetime) |
Returns ISO 8601 week number (1–53), or 0 if invalid. |
nDaysInMonth(datetime) |
Returns number of days in month for a Date object. |
nDaysInMonth(month) |
Returns number of days in month (1–12). |
nDaysInMonth(month, year) |
Returns number of days in month (with year). |
dateAdd(datetime, y, M, d) |
Adds a duration (years, months, days) to a date. |
dateDiffInDay(datetime1, datetime2) |
Number of days between two dates. |
dateDiffInMonth(datetime1, datetime2) |
Number of months between two dates. |
dateDiffInYear(datetime1, datetime2) |
Number of years between two dates. |
nearUniqueRandomID() |
Generates a near-unique random number based on time + process ID (useful as a unique key). |
simpleGlobalOptimizer(nameObjectiveFunction, minX, maxX, nIterationMax)Finds x* (global minimum) for a JavaScript objective function in the range [minX, maxX].
nameObjectiveFunction is the name (string) of the JS function to minimizefunction f(x) { return <a_function_of_x>; }
Return value: an object with 2 fields:
xOptyOptsimpleLocalOptimizer(nameObjectiveFunction, minX, maxX, startX, startStepX, finalStepX)Finds x* (local minimum) for a JavaScript objective function in the range [minX, maxX].
startX (ideally near the minimum)startStepX, then decreases step size as it approaches the minimumfinalStepXReturn value: an object with 4 fields:
xOptyOptnIterinfoRow(number_of_columns)Creates a new Row with the given number of columns.
You can write this row to an output pin.
PredictiveModel(filename, rowObject)Creates a new BRAND predictive model based on a model file (*.ModelXML) given as first parameter.
rowObject (same column positions).SegmentationModel(filename, rowObject)Creates a new BRAND segmentation model based on a segmentation model file (*.SModelXML).
rowObject (same column positions).DateTool(formatString)Creates a DateTool object that can:
ETTool(unit, referenceDate)Creates an ETTool object to manipulate Elapsed Times.
Unit values
| Constant | Value |
|---|---|
ETUnit_second |
0x00 |
ETUnit_minute |
0x01 |
ETUnit_hour |
0x02 |
ETUnit_day |
0x03 |
ETUnit_week |
0x04 |
referenceDate format: yyyyMMdd hh:mm:ss
SQLite(DBFile, openMode, timeOutInMs) (LIB: DBConnectors)Creates a SQLite object to manipulate SQLite databases.
DBFile is a full path (avoid relative paths like ./)openMode values:| Constant | Value |
|---|---|
SQLite_ReadOnly |
0x01 |
SQLite_ReadWrite |
0x02 |
SQLite_ReadWriteCreate |
0x06 |
timeOutInMs optional. Default: 10000timeOutInMs ms before failing.ProcessRunner(nRetry, randomWaitBeforeRun)Creates a ProcessRunner used to run external executables.
nRetry optional (default 5)randomWaitBeforeRun optional (default 1000 ms)Behavior notes:
0 and randomWaitBeforeRun msSendMail(smtpServer, fromAddress, encryption, portServer, connectionTimeOut) (LIB: EMailSMS)Creates a SendMail object to send emails.
Defaults when omitted:
encryption = SendMail_SSL
portServer defaults by encryption:
SendMail_NoEncryption → port 25SendMail_SSL → port 465SendMail_StartTLS → port 587connectionTimeOut = 5000 ms
Encryption values:
| Constant | Value | Description |
|---|---|---|
SendMail_NoEncryption |
0x00 |
No encryption. |
SendMail_SSL |
0x01 |
SSL encryption. |
SendMail_StartTLS |
0x02 |
StartTLS encryption. |
Graph(file, login, password)Creates an object representing a BRAND graph. This object lets you modify:
login and password are optional (only needed if the graph is encrypted).
Row class| Variable | Description |
|---|---|
nColumn |
Number of columns in the row. |
isNull |
true/false – whether this row is a NULL row. |
| Method | Description |
|---|---|
col(columnIndex) |
Returns the content of the column at columnIndex. |
setColumn(columnIndex, value) |
Sets the content of the column at columnIndex. |
write(outputPinIndex) |
Writes this row to the specified output pin index. |
DateTool class| Method | Description |
|---|---|
parse(dateAsString) |
Returns a JavaScript Date object parsed from the provided string. |
print(myDate) |
Returns a formatted date string from a JavaScript Date object. |
ETTool class| Method | Description |
|---|---|
add(dateAsET, y, M, d) |
Adds a duration (years, months, days) to an elapsed time. |
diffInMonth(ET1, ET2) |
Number of months between ET1 and ET2. |
diffInYear(ET1, ET2) |
Number of years between ET1 and ET2. |
toDate(ET) |
Returns a JavaScript Date object representing the elapsed time. |
fromDate(dateAsString) |
Returns an elapsed time computed from a JavaScript Date object. |
toString(ET, dateFormat) |
Returns a formatted date string representing the elapsed time. |
fromString(dateAsString, dateFormat) |
Returns an elapsed time computed from the given string. |
ProcessRunner classlistJobs()Returns an array of objects, each with:
processdefaultDirargsrun(ncpu, abortCondition, randomWaitbeforeRun)Runs all executables currently in the list created using addJob().
ncpu is used)ncpu default = 1 (sequential). If ncpu > 1, BRAND runs processes in parallel up to ncpu at a time.abortCondition values:
| Constant | Value | Description |
|---|---|---|
PR_NeverAbort |
0 |
Never abort (no retry). |
PR_NeverAbortButRetry |
1 |
Never abort but retry while the run FAILED. (default) |
PR_AbortIfFail |
2 |
Abort if still FAILED after some retry. |
PR_AbortIfWarning |
3 |
Abort if still WARNING after some retry. |
Return value:
0 if no errors/warnings were detectedrun BRAND(graphFile, allParametersAsString, currentDir, randomWaitBeforeRun)run BRAND(graphFile, arrayOfParameters, currentDir, randomWaitBeforeRun)Runs a .brand graph file (specialized version of runImmediate()).
Small example:
var p = new ProcessRunner();
p.runBRAND("aggregate_products.brand", "-DfileIndex=1 -Dobservation=2000");
Array-based syntax is more complex but allows passing parameters that include characters that are difficult in a single string (quotes, etc.).
addJob(processAndParameters, currentDir, nRetry)addJob(process, arrayOfParameters, currentDir, nRetry)Adds an executable to the internal list. That list is executed when run() is called.
currentDir and nRetry are optionalnRetry is the value set at ProcessRunner creation (default 5)addJob(graphFile, allParametersAsString, currentDir, nRetry)addJob(graphFile, arrayOfParameters, currentDir, nRetry)Adds a .brand graph file to the internal list executed by run().
runImmediate(processAndParameters, currentDir, randomWaitBeforeRun)runImmediate(process, arrayOfParameters, currentDir, randomWaitBeforeRun)Runs an external executable immediately (does not add it to the list).
Example (downloading a page using curl):
var p = new ProcessRunner();
var res = p.runImmediate("\"" + Dir + "/../curl/curl\" -k -o index.html https://www.google.com");
if (res == 0) print("download successful");
else throw "Error download";
runImmediateExtended(processAndParameters, currentDir, textEncoding, dataToWrite)runImmediateExtended(process, arrayOfParameters, currentDir, textEncoding, dataToWrite)Same as runImmediate() but returns an object:
errorLevel – return codeoutput – stdout + stderr textdataToWrite defines what is passed to stdin (string or a binary object from fileBinaryLoad()).
textEncoding controls decoding of the output text:
0: local system-wide encoding (usually ISO-8859-1)1: UTF-82: UTF-163: Latin14: IBM850runDetached(processAndParameters)runDetached(process, arrayOfParameters)Starts a new process and detaches from it (BRAND does not wait for termination).
Returns true on success, false otherwise.
setVerbose(b)Controls verbosity. You can reduce verbosity with:
p.setVerbose(false);
KeepBests class| Variable | Description |
|---|---|
N |
Number of (key,value) pairs stored in the object. |
| Method | Description |
|---|---|
add(key, value) |
Adds a pair. If capacity is full, discards the pair with the lowest key. |
getKey(index) |
Returns the key at index. Index 0 is the greatest key. |
getValue(index) |
Returns the value at index. Index 0 corresponds to the greatest key. |
reset() |
Empties the object. |
SendMail class (LIB: EMailSMS)| Method | Description |
|---|---|
setLoginPassword(login, password) |
Sets SMTP authentication credentials. |
isConnected() |
Returns true if connected to the SMTP server. |
send(toAddress, subject, messageBody, ccAddress, bccAddress, isHTML) |
Sends one email (connects first if required). ccAddress, bccAddress, isHTML are optional ("", "", false). Supports multiple emails separated by commas. Optional display names must be written as Name <email@domain>. |
close() |
Closes SMTP connection and frees resources. |
SQLite class (LIB: DBConnectors)| Method | Description |
|---|---|
close() |
Releases locks and closes the database. |
lastError() |
Returns the last SQLite error description. |
execute(stmt) |
Executes SQL statement. If no rows: success returns 101, failure returns null. If rows returned: only first row is returned (array if multiple columns, scalar if one column). |
isOpen() |
Returns whether the database is currently open. |
PredictiveModel class| Variable | Description |
|---|---|
targetType |
'T' for binary target, 'C' for continuous target. |
AUCTest, AUCFull |
Quality measures for binary models only. |
AUCTopTest, AUCTopFull |
Quality measures for binary models only. |
RSquareTest, RSquareFull |
Quality measures for continuous models only. |
MAETest, MAEFull |
Quality measures for continuous models only. |
RMSETest, RMSEFull |
Quality measures for continuous models only. |
| Method | Description |
|---|---|
eval(rowObject) |
Computes a prediction from the given row. Returns a floating-point value. |
SegmentationModel class| Variable | Description |
|---|---|
segmentNames |
Array of strings with the segment names. |
| Method | Description |
|---|---|
eval(rowObject) |
Returns the segment index as an integer. |
evalWithdist(rowObject) |
Returns an object: { idx, segment, dist } where dist is the distance from the segment center. |
Graph class| Method | Description |
|---|---|
setTempDirLoc(i) |
Sets temp directory location: 0 global OS temp, 1 BRAND temp, 2 graph-specific temp. |
setTempDir(dir) |
Sets a specific temporary directory path. |
setEncoding(s) |
Sets encoding: "utf8" or "utf16". |
setEncryption(b) |
Enables/disables encryption (true/false). |
| Method | Description |
|---|---|
addUser(login) |
Adds a user. |
removeUser(login) |
Removes a user. |
setUserPassword(login, password) |
Sets user password. |
hasUserPassword(login) |
Returns true/false. |
setUserAdmin(b) |
Sets admin flag (true/false). |
setUserExpirationDate(date) |
Sets expiration date, format yyyyMMdd. |
setUserEditGP(b) |
Sets permission to edit global parameters. |
setUserEditGraph(b) |
Sets permission to edit the graph. |
setUserReadDB(b) |
Sets DB read permission. |
setUserWriteDB(b) |
Sets DB write permission. |
| Method | Description |
|---|---|
setODBClogin(connectionName, login) |
Sets ODBC login for the given connection. |
setODBCPassword(connectionName, password) |
Sets ODBC password for the given connection. |
setGP(name, value) |
Sets a global parameter (creates it if missing). |
getUsers() |
Returns an array of users with fields like login, isAdmin, canEditGP, canEditGraph, canReadDB, canWriteDB, expirationDate. |
getODBC() |
Returns an array describing ODBC connections (fields typically include name, link, login, password). |
getGP() |
Returns an array of global parameters (fields: name, value, comment). |
getFiles() |
Returns an object { input, output } describing input/output files used in the graph (each element includes action and filename). |
| Method | Description |
|---|---|
isOk() |
Status check (self-explanatory). |
hasChanged() |
Returns whether the graph was modified. |
save(filename) |
Saves the graph. filename optional (defaults to the opened filename). |
saveForVersioning(filename, resetUsers) |
Saves for versioning. Both optional; default resetUsers = true. |