11.6. Appendix F: Anatella-specific JavaScript extensions

<< Click to Display Table of Contents >>

Navigation:  11. Appendix >

11.6. Appendix F: Anatella-specific JavaScript extensions

 

In the previous Appendix (Appendix E), we saw all the standard constants, functions, and objects provided by any standard JavaScript/ECMAScript compliant language.

 

Anatella includes a special set of functions and objects that allows you to easily manipulate row data, row meta-data, input pins & output pins.  These functions and objects are:

 

 

Global Anatella variables

nPinIn

The number of input pin of the Action.

nPinOut

The number of output pin of the Action.

isVariableNPinIn

Is the number of input pin of the Action variable?

isVariableNPinOut

Is the number of output pin of the Action variable?

anatellaDir

The directory where the “anatella.exe” file is installed.

This is usually “c:\program files\TIMi\bin”.

tempDir

The directory where the temporary HD Cache files are created.

This is usually “c:\Users\my_name\AppData\Local\Temp”.

currentDir

The directory where the current .anatella file is located.

currentFile

The complete filepath (dir+name) of the current .anatella file.

actionID

A number that uniquely identifies this action inside the Anatella graph

 
 

Commonly–used Anatella functions of the global object

getCurrentRow(inputPinIndex)

Returns a “row object” that represents the ‘current’ row on the given input pin

getNextRow(inputPinIndex)

Extracts a new row from the given input pin and return it as a new “row object”

setOutputRowSize(outputPinIndex,

                                  number_of_columns)

Defines the number of columns on the given output pin

writeEOL(outputPinIndex)

Write the “End-Of-Line” marker on the given output pin

rowDeepCopy(rowObject)

Creates a deep copy of the given Row Object. See section 5.2.5 for more information on the proper usage of this function

rowGetIndexOfColumn(rowObject,                                             string)

Returns the column index inside the given row whose name is given as second parameter.

 

 

Anatella global-functions related to writing on the output pin

rowWriteConstant(rowObject,

                                   outputPinIndex,

                                   string)

Replace the content of all columns of the row object with the given string and write the modified row on the given output pin.  The rowObject given as first parameter is not modified.

rowWriteNull(rowObject,

                          outputPinIndex)

Replace the content of all columns of the row object with NULL values and write the modified row on the given output pin.  The rowObject given as first parameter is not modified. This function works even if the “isNull” property of the rowObject given as first parameter is true.

 

 

Anatella global-functions related to column selection on the output pin

dropAllColumns(outputPinIndex)

All the columns written on the given output pin will be dropped. The output pin will emit a “void” table.

keepAllColumns(outputPinIndex)

All the columns written on the given output pin will be “passed” to the next Action.

dropColumn(outputPinIndex,

                       columnIndex)

The given column index on the given output pin won’t be passed to the next Action.

keepColumn(outputPinIndex,

                        columnIndex)

The given column index on the given output pin will be passed to the next Action.

 

 

Variables of the Anatella Row class

nColumn

The number of columns contained inside this row object.

isNull

Boolean value that is used to signal the end-of-input-table condition on a specific input pin when using the “getNextRow()” function.

 

 

Methods of the Anatella Row class

write(outputPinIndex)

Write the row on the given output pin

col(columnIndex)

Returns a string that is the content of the column with the index “columnIndex” inside the “this” row object.

setColumn(columnIndex,string)

Set the content of a given column inside the “this” row object.

 
 

Anatella global-functions related to row content management

rowSetAllColumns(rowObject,

                                  string)

The content of all the columns of the given row Object is set to the given string.

 
 

Anatella global-functions related to meta-data management

rowGetColumnName(rowObject,

                                   columnIndex)

Return the required column name

rowSetColumnName(rowObject,

                                   columnIndex,

                                   String)

Set the column name of a specific column

rowGetMetaType(rowObject,

                               columnIndex)

Return the meta-type of the given column. This meta-type is character:

‘A’: column is Alpha-numeric

‘0’: column is numeric

‘D’: column is a date

‘B’: column is a boolean

‘I’: column is an image

‘S’: column is a sound

‘U’: unknown meta-type

‘E’: the columnIndex is erroneous

rowSetMetaType(rowObject,

                               columnIndex,

                               string)

Set the meta-type of the given column

rowGetDateFormat(rowObject,

                                    columnIndex)

Get the date format of the given column

rowSetDateFormat(rowObject,

                                   columnIndex,

                                  string)

Set the date format of the given column

rowGetSortColumnIdx(rowObject,

                                        sortPriority)

 

Return the indexes of the columns on which the table is sorted.

For example, if the table is sorted on two columns, then “rowGetSortColumnIdx(r,0)” and “rowGetSortColumnIdx(r,1)” are returning the required indexes. On the same example, a call to the “rowGetSortColumnIdx(r,2)” returns  -1.  

                                   

rowGetSortType(rowObject,

                              sortPriority)

Returns the sort type of the table. This sort type is a character:

a)‘A’: Alphabetical order (A..Za..z)

b)‘Z’: Inverse Alphabetical order (z..aZ..A)

c)‘a’: Alphabetical order - case insensitive(Aa..Zz)

d)‘z’: Inverse Alphabetical order - case insensitive(Zz..Aa)

e)‘0’: Numerical order increasing (0..9)

f)‘9’: Numerical order decreasing (9..0)

g)‘I’: Date (chronological order)

h)‘D’: Date (inverse chronological order)

i)‘E’: error: undefined

 

 

Anatella global-functions related to debugging

rowToArray(rowObject)

Return an array of strings that matches the content of the given row object.

rowToObject(rowObject)

Return a pure JavaScript Object that has as many properties as the number of column of the given row object. The properties names of the returned pure JavaScript Object are base on the column names of the given row Object. The properties are initialized based on the content of the columns of the given row Object.

printRow (rowObject)

Print the given row object inside the JavaScript debug console.

clearLog()

Clear the Log window (this does not affect the trace files)

 

 

Anatella global-functions related to Files

dirList(directory,

           file_filter,

           sort_mode,

           dir_filter)

Return an array of objects. Each element of the array contains information about a different file or directory. The parameters sort_mode and dir_filter are optional. If omitted, Anatella will use:

  sort_mode= DirSort_ByName+DirSort_IgnoreCase

    dir_filter= DirFilter_AllEntries.

 

For example: This will print inside the log window the complete file path to the first .anatella file located inside the current directory:

      AN76E5~1_img414

 

The fields of the different elements of the returned array are:

absolutePath”: self-explanatory (this does not contain the filename: only the path).

fileName": self-explanatory.

created”: the creation date (as a JavaScript date Object).

“modified”: the last modification date (as a JavaScript date Object).

“isDir”: self-explanatory.

“isFile”: self-explanatory.

“isHidden”: self-explanatory.

“isReadable”: self-explanatory.

“isWritable”: self-explanatory.

“isExecutable”: self-explanatory.

 

The sort_mode parameter is a combination of the following 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_ByExtention

0x80

Sort by file type (extension).

DirSort_DoNotSort

0x03

Do not sort.

DirSort_DirsFirst

0x04

Put the directories first, then the files.

DirSort_DirsLast

0x20

Put the files first, then the directories.

DirSort_Reversed

0x08

Reverse the sort order.

DirSort_IgnoreCase

0x10

Sort case-insensitively.

DirSort_LocaleAware

0x40

Sort items appropriately using the current locale settings.

 

The dir_filter parameter is a combination of the following flags:

 

Constant

Value

Description

DirFilter_Dirs

0x001

List directories that match the filters.

DirFilter_AllDirs

0x400

List all directories; i.e. don't apply the 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 by operating systems that don't support symbolic links).

DirFilter_NoDotAndDotDot

0x1000

Do not list the special entries "." and "..".

DirFilter_NoDot

0x2000

Do not list the special entry ".".

DirFilter_NoDotDot

0x4000

Do not list the special entry "..".

DirFilter_AllEntries

Dirs | Files | Drives

List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System).

DirFilter_Readable

0x010

List files for which the application has read access. The Readable value needs to be combined with Dirs or Files.

DirFilter_Writable

0x020

List files for which the application has write access. The Writable value needs to be combined with Dirs or Files.

DirFilter_Executable

0x040

List files for which the application has execute access. The Executable value needs to be combined with Dirs or Files.

DirFilter_Modified

0x080

Only list files that have been modified (ignored on Unix).

DirFilter_Hidden

0x100

List hidden files (on Unix, files starting with a ".").

DirFilter_System

0x200

List system files (on Unix, FIFOs, sockets and device files are included; on Windows, .lnk files are included)

DirFilter_CaseSensitive

0x800

The filter should be case sensitive.

 

fileExist(filename)

Test if a file or a directory exists.

Returns an integer number:

“0”: no file or directory with the given name exists.

“1”: a file with the given name exists.

“2”: a directory with the given name exists.

fileMove (source,

                 destination,

                 alsoMoveDirs)

Move some file or directories. The parameter alsoMoveDirs is optional. If omitted, Anatella wil use alsoMoveDirs=false.

If you intend to move a directory (instead of a file), you must set alsoMoveDirs=true.

Returns true if successful.

fileCopy(source,

               destination

               alsoCopyDirs)

Copy some file or directories. The parameter alsoCopyDirs is optional. If omitted, Anatella wil use alsoCopyDirs=false.

If you intend to copy a directory (instead of a file), you must set alsoCopyDirs=true.

Returns true if successful.

fileDelete(filename,

                  forceDelete)

Delete some file or directory. The parameter forceDelete is optional. If omitted, Anatella wil use forceDelete =false.

If you intend to delete a directory or a read-only file, you must set forceDelete=true.

Returns true if successful.

fileLoad(filename,

               encoding)

Returns a string with the content of the file filename.

If the optional parameter encoding is omitted, the text encoding inside the file is assumed to be the local system-wide encoding, otherwise:

encoding=0: text is in utf-16

encoding=1: text is in utf-8

If the file contains a BOM, the text-encoding specified inside the BOM is always used.

fileBinaryLoad(fileName,

     startOffset,

     length)

Returns an object that contains the binary content of the file filename.

The parameters startOffset and length are optional. If there are omitted, Anatella will use startOffset=0 and length=the size of the loaded file.

fileSave(fileName,

                fileContent,

                encoding)

               

Save the string fileContent inside the text file filename.

The text-encoding of the saved file is given inside the optional encoding parameter (when the encoding parameter is omitted, Anatella assumes: encoding=0):

encoding=0: file is in utf-16 (with BOM)

encoding=1: file is in utf-8 (with BOM)

encoding=2: file is in utf-8 (without BOM)

encoding=3: file is in local system-wide 8-bit encoding (without BOM)

mkDir(path)

Create a new directory.

This will create all parent directories necessary to create the directory.

Returns true if successful.

 

Anatella global-functions : Other

print(string)

Print the string inside the Antella log window.

exit(exitcode)

Abort immediately the graph execution and stop the whole Anatella process. If Anatella was busy writing to a file, the file can be truncated because of the abrupt “abort”. The parameter exitcode is optional (default value is 0). Use only this function with extreme cautions: It’s equivalent to a click on the AN76E5~1_img52 button in the top-right corner of the Anatella window.

trim(string)

Returns a string that has whitespace removed from the start and the end.

Whitespace characters include the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

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 the week number (1 to 53) from the JavaScript date object “datetime”.

Returns 0 if the date is invalid.

In accordance with ISO 8601, weeks start on Monday and the first Thursday of a year is always in week 1 of that year. Most years have 52 weeks, but some have 53.

nDaysInMonth(datetime)

nDaysInMonth(month)

nDaysInMonth(month,year)

Returns the number of days in month. (1<=month<=12)

dateAdd(datetime,y,M,d)

Add a duration (in year, month and days) to a date

dateDiffInDay(datetime1,

                         datetime2)

Number of days between datetime1 and datetime2

dateDiffInMonth(datetime1,

                              datetime2)

Number of months between datetime1 and datetime2

dateDiffInYear(datetime1,

                          datetime2)

Number of years between datetime1 and datetime2

nearUniqueRandomID()

Generate a random number based on the current date, current time, current milliseconds and the current processuss ID. This number can be used as a primary key to uniquely identify the current processus and time.

getEnv(string)

Return the value of the specified DOS environment variable

urlEncode(string)

Encode a string so that it can be used inside a parameter inside an url

LIB: MathParser

jsonEncode(string)

Encode a string so that it can be used inside a JSON file

LIB: MathParser

xmlEncode(string)

Encode a string so that it can be used inside a XML file

LIB: MathParser

sleep(number)

The Anatella process waits for “number” milliseconds.

clearLog()

Clear the log Anatella Window

isNumber(x,strict)

Test is x is a string that can be converted to a number

The second paremeter “strict” is optional: The default value is True.

toNumber(x)

Convert the string x to a Number using Anatella advanced routines (that accepts NaN, NULL, Inf, -Inf and any extraneous characters after the number).

isLinux()

Returns true if Anatella is running inside Wine inside Linux.

The test is actually based on the presence/abscence of the registry key:

     HKEY_CURRENT_USER\Software\Wine

 

 

Anatella constructor (new) functions

Row(number_of_columns)

Creates a new Row Object with the given number of columns. You can use the newly created Row Object to write to any output pin.

PredictiveModel (filename,

                               rowObject)

Creates a new TIMi Predictive Model based on the TIMi model file (*.ModelXML) given as first parameter. The model can only be applied on row objects similar to the row object given as second parameter to this constructor (by similar, we mean the column positions are the same).

SegmentationModel(

   filename, rowObject)

Creates a new Stardust Segmentation Model based on the Satrdust segmentation model file (*.SModelXML) given as first parameter. The model can only be applied on row objects similar to the row object given as second parameter to this constructor (by similar, we mean the column positions are the same).

 

DateTool(Format string)

This creates a DateTool object that can be used to produce

a)JavaScript Date objects from strings containing formatted dates.

b)Strings from JavaScript date objects.

The syntax of the format string is explained in section 5.1.3.

 

Here is an example of usage:
 

    AN76E5~1_img416

 

This prints in the console:

     20120305

     10/07/04 00:00:00

 

ETTool(Unit,ReferenceDate)

This creates an ETTool object that can be used to manipulate “Elapsed Times”

The “Unit” parameter can have the following value:

 

  Constant

Value

ETUnit_second

0x00

ETUnit_minute

0x01

ETUnit_hour

0x02

ETUnit_day

0x03

ETUnit_week

0x04

 

The “ReferenceDate” parameter is a date given in the “yyyyMMdd hh:mm:ss” format.

 

SQLite(DBFile, openMode,  

            timeOutInMs)

LIB: DBConnectors

 

This create a SQLite object that can be used to manipulate “SQLite databases”.

 

The “DBFile” parameter is the complete path to the SQLite database (don’t use relative paths “:/”).

 

The “openMode” parameter can have the following value:

 

  Constant

Value

SQLite_ReadOnly

0x01

SQLite_ReadWrite

0x02

SQLite_ReadWriteCreate

0x06

 

The “timeOutInMs” parameter is optional: If omitted, Anatella will use “timeOutInMs”=10000. When you try to write to a locked table, the SQLite engine will wait, for at most “timeOutInMs” milliseconds, until the database/table unlocks (to be able to execute your command). After the timeout, if the database/table is still locked, the execution of your SQL command fails.

 

ProcessRunner(nRetry,

       randomWaitBeforeRun)

This creates a ProcessRunner object that is used to run external executables from Anatella.

 

The 2 parameters nRetry and randomWaitBeforeRun and are optional: If omitted, Anatella will use nRetry=5 and randomWaitBeforeRun=1000.

 

These 2 parameters are useful when launching the execution of a large list of different executables (using the “run()” method):
 

When an executable from the list fails, Anatella can, either: abort, ignore or re-try (i.e. “re-try”=re-execute the same executable once again). The number of re-try is defined as the nRetry parameter.
 

Before running any executable from the list, Anatella waits for a random number of milliseconds. The duration of the “wait” is in-between 0 milliseconds and randomWaitBeforeRun milliseconds.

 

There are 2 different ways of using a ProcessRunner object: you can, either:
 

Create a list of executable to run and thereafter run the list:

a)use the methods “addJob()” or “addAnatellaJob()” to add a executables to the list.

(optionally: you can use the method “listJobs()” to view the list)

b)use the method “run()” to start the execution of all the executables inside the list.
 

Run directly an executable using the methods “runImmediate()” or “runAnatella()”  (without going through the process of creating a list first).

 

When you click the AN76E5~1_img129 STOP button, Anatella automatically aborts all the child processes that were running.

Here are some examples:

 

Example 1.

 

      AN76E5~1_img418

 

Or, alternatively:

 

      AN76E5~1_img419

 

This runs the 2 Anatella-graphs '"aggregate_products.anatella" and "aggregate_customers.anatella" sequentially (i.e. one after the other). The value of Graph-Global-Parameter named "fileIndex" is set to "1". See section 4.7. for more information about the parameters that you can use when running Anatella from the command-line.

 

 

Example 2.

 

AN76E5~1_img420

 

Or, alternatively:

 

clip0423AN76E5~1_img421

 

This runs the 2 same Anatella-graphs as in the previous example.  However, this time, the 2 graphs are running simultaneously (i.e. in parallel). This allows us to easily use all the several CPUs available in modern computers.

 

 

Example 3.

 

    AN76E5~1_img422

 

Or, alternatively:

 

    AN76E5~1_img423

 

This runs 100 times the anatella-graph "sort_one_day.anatella" with different values of the Graph-Global-Parameter named "dayIndex". The objective is to sort 100 files (and each of these files contains one day of data). Each run of the “sort_one_day.anatella" graph will sort exactly one day: the day that is defined using the "dayIndex" variable.

 

Anatella will run in parallel 8 data-transformation-graphs (because we wrote: “p.run(8)”). As soon as one of the 8 running Anatella-Graphs is finished, Anatella directly launch the next Anatella-Graph, so that there are always 8 graphs running at the same time. This allows us to use all the several CPUs available in modern computers at maximum efficiency.

 

Before sorting one day (i.e. before adding one specific day to the list of jobs to run), it might be a good idea to use the function “fileExist()” to check if there already exists a file that contains the result of the sort (in such a situation, no need to sort the data because the resulting sorted file is already there!).

 

KeepBests(number of pairs)

An object that stores a limited number of (key,value) pairs:
 

Keys are floating point numbers (i.e. double)

Values are integers.
 

This objects only stores the (key,value) pairs with the highest key values.

All the pairs that have a “small key” are discarded.

 

For example:

 

          AN76E5~1_img424

 

SendMail(smtpServer,

fromAddress, encryption,

portServer,

connectionTimeOut)

LIB: EMailSMS

 

Use this Javascript class to send emails.

 

The parameters encryption, portServer and connectionTimeOut are optional:

If omitted, Anatella will use these default values:
 

encryption= SendMail_SSL

portServer:

oif encryption is “SendMail_NoEncryption”, PortServer=25

oif encryption is “SendMail_SSL”,                    PortServer=465

oif encryption is “SendMail_StartTLS”,           PortServer=587

connectionTimeOut=5000 milliseconds

 

The encryption parameter is one the following flags:

 

  Constant

Value

Description

SendMail_NoEncryption

0x00

No encryption.

SendMail_SSL

0x01

Mails are encrypted using SSL.

SendMail_StartTLS

0x02

Mails are sent using the encrypted StartTLS protocol.

 

Here is an example of usage:
 

      AN76E5~1_img425
 

AnatellaGraph(file,login,

    password)

This create an object that represents an Anatella Graph. This object allows you to modify all the options of the Anatella Graph (i.e. all the security options, the “Working directory for cache files” option, the character encoding option).

 

The “login” and “password” parameters are optional: They are only required if your Anatella graph is encrypted.
 

For example:
 

              AN76E5~1_img426

 

The above example:

1.Open an Anatella Graph named “:/testIn.anatella”

2.Add a new user named “user1”

3.The “user1” is not an admin and he can’t edit the graph (he can only run it)

4.The “user1” is an authorized user up to Januray 1st, 2016.

5.Set the Graph as encrypted.

6.Save the new Graph as “:/testOut.anatella”
 

 

 

Variables of the PredictiveModel class

targetType

targetType is either ‘T’ (for binary target) or ‘C’ (for continuous target)

AUCTest, AUCFull

AUCtopTest, AUCtopFull

Different measures of the quality of the Binary predictive model.

These measures are only available for Binary predictive models.

RSquareTest, RSquareFull

MAETest, MAEFull

RMSETest, RMSEFull

Different measures of the quality of the Continuous predictive model.

These measures are only available for Continuous predictive models.

 

 

Methods of the PredictiveModel class

eval(rowObject)

Uses the TIM predictive model to compute a prediction based on the content of the given row. This method returns a floating point.

 

 

Variable of the SegmentationModel class

segmentNames

This is an array-of-strings. It contains the different segment names.

 

 

Methods of the SegmentationModel class

eval(rowObject)

This returns an integer number that is the number (the index) of the segment.

Here is an example how to obtain the name of the segment:

    AN76E5~1_img427

evalWidthdist(rowObject)

This returns an object that contains the following fields:

  idx: the number (the index) of the segment.

  segment: the name of the segment.

  dist: the distance between the current rowObject and the segment center.

 

 

Methods of the DateTool class

parse(dateAsString)

Uses the DateTool object to return a JavaScript Date object constructed from the string given as parameter.

print(myDate)

Uses the DateTool object to return a string from the JavaScript date object given as parameter.

 

 

Methods of the ETTool class

add(dateAsET,y,M,d)

add a duration (in year, month and 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 given ET

fromDate(dateAsString)

returns an Elapsed Time computed from a Javascript date object

toString(ET,dateFormat)

Returns a dateAsString  that represents the given ET

fromString(dateAsString,dateFormat)

returns an Elapsed Time computed from the given string

 

 

Methods of the ProcessRunner class

runImmediate(

    processAndParameters,

    currentDir,

     randomWaitBeforeRun)

 

runImmediate(

    process,

    arrayOfParameters,

    currentDir,

    randomWaitBeforeRun)

Run an external executable.

 

Here is an example that downloads the homepage from Google using curl:

AN76E5~1_img428

 

Or, alternatively (this is better):

 

    AN76E5~1_img429

 

The second syntax (based on an array of parameters) is more complex to use but it allows you to pass any command-line switches to the launched process (i.e. even the command-line switches that includes forbidden characters such as the “quote” or the “ampersand” character are allowed using this syntax).

 

The last two parameters (currentDir and randomWaitBeforeRun) are optional.

 

The process parameter contains the command-line used to run the process: i.e. The full path to the executable, optionnaly followed by command-line switches (such as “–DfileIndex=3 –DObsDate=20120629”).

 

The currentDir parameter defines the current Directory used to run the process. The default value of the currentDir parameter is “:/”.

 

 

The randomWaitBeforeRun parameter defines the maximum number of milliseconds that Anatella must wait before running the process. The default value of the randomWaitBeforeRun parameter is the value given at the creation of the ProcessRunner Object.

 

When a program terminates, it always returns back to MSWindows a number. This number is named the “error level” of the program. By convention, an “error level” that is non-zero indicates that there was an error during the execution of the program. Anatella extends slightly the convention: see section 4.7. for more information about this subject. The “runImmediate()” method returns the “error level” of the program it executed.

 

runImmediateExtended(

    processAndParameters,

    currentDir,

    textEncoding,

    dataToWrite)

 

runImmediateExtended (

    process,

    arrayOfParameters,

    currentDir,

    textEncoding,

    dataToWrite)

 

This is basically the same method as the “runImmediate()” method described here above. The difference between “runImmediateExtended()” and “runImmediate ()” exists only in the return value:
 

The “runImmediate()” method simply returns the “error level” of the program it executed.

The “runImmediateExtended()” method returns an object with two fields:

oerrorLevel”: the “error level” of the executed program.

ooutput”: the content of the text displayed inside the console during the program execution (all stdout+stderr). By default, the text encoding is the global-OS-text encoding. The last parameter “textEncoding” allows you to change the encoding.

 

Only the first parameter is mandatory.

 

The currentDir parameter is optional: It defines the current directory used to run the process. The default value of the currentDir parameter is “:/”.

 

The currentDir parameter defines the current Directory used to run the process. The default value of the currentDir parameter is “:/”.

 

The dataToWrite parameter defines the data that will be passed to the stdin of the launched process. The dataToWrite parameter can be a string or a binary object obtained using the “fileBinaryLoad()” function.

 

The textEncoding parameter defines the encoding of the characters obtained from running the process (when the encoding parameter is omitted, Anatella assumes: encoding=0):
 

encoding=0: The characters are in the local system-wide encoding (This is usually ISO-8859-1)

encoding=1: characters are in UTF8

encoding=2: characters are in UTF16

encoding=3: characters are in Latin1

encoding=3: characters are in IBM850 encoding

 

runDetached(

    processAndParameters)

 

runDetached(

    process,

    arrayOfParameters,

    currentDir)

Starts the new process with the given arguments, and detaches from it (i.e. Anatella won’t wait until the termination of the new process). If Anatella exits, the detached process will continue to live.

 

Return true on success (i.e. a new process was launched) and false otherwise.

 

The currentDir parameter is optional: It defines the current directory used to run the process. The default value of the currentDir parameter is “:/”.

 

runAnatella(

    anatellaGraphFile,

    AllParametersAsAString,

    currentDir,

     randomWaitBeforeRun)

 

runAnatella (

    anatellaGraphFile,

    arrayOfParameters,

    currentDir,

    randomWaitBeforeRun)

Runs a .anatella data-transformation-graph file.

 

This is a specialized version of the “runImmediate()” method that allows to run .anatella files with a simpler syntax.

 

Here is a small example:

 

    AN76E5~1_img430

 

Or, alternatively (this is better):

 

    AN76E5~1_img431

 

The second syntax (based on an array of parameters) is more complex to use but it allows you to pass any command-line switches to the launched process (i.e. even the command-line switches that includes forbidden characters such as the “quote” character are allowed using this syntax).

 

addJob (

    processAndParameters,

    currentDir,

    nRetry)

 

addJob (

    process,

    arrayOfParameters,

    currentDir,

    nRetry)

Add an executable to the list of executable that will be launched when calling the “run()” method of the ProcessRunner Object.

 

The second syntax (based on an array of parameters) is more complex to use but it allows you to pass any command-line switches to the launched process (i.e. even the command-line switches that includes forbidden characters such as the “quote” character are allowed using this syntax).

 

The 2 last parameters (currentDir and nRetry) are optional.

 

The currentDir parameter has the same purpose and meaning as for the “runImmediate()” method, hereabove.

 

When the executable defined by the current process parameter fails, Anatella can, either: abort, ignore or re-try (i.e. “re-try”=re-execute the same executable once again). The number of re-try is defined as the nRetry parameter. The default value of the nRetry parameter is the value given at the creation of the ProcessRunner Object (that is, by default, 5).

 

addAnatellaJob(

    anatellaGraphFile,

    AllParametersAsAString,

    currentDir,

     nRetry)

 

addAnatella Job(

    anatellaGraphFile,

    arrayOfParameters,

    currentDir,

    nRetry)

Add a .anatella file to the list of processes that will be launched when calling the “run()” method of the ProcessRunner Object.

 

This is a specialized version of the “addJob()” method that allows to queue .anatella files for execution with a simpler syntax.

 

 

listJobs()

Returns an array of objects. Each object has the following fields:

process : Self-explanatory.

defaultDir: Self-explanatory.

args: Self-explanatory.

 

run(ncpu,

      abortCondition,

    randomWaitbeforeRun)

This runs all the executables that are inside the list created using the “addJob()” method.

 

All parameters are optional. Usually, only the first parameter is used.

 

Anatella will run in parallel ncpu executable (from the current list of executable to run). As soon as one of the ncpu running process is finished, Anatella directly launch the next process, so that there are always ncpu processes running at the same time. This allows us to use all the several CPUs available in modern computers at maximum efficiency. The default value for the ncpu parameter is “1” (when ncpu=1, Anatella runs sequentially all the processes in the list in the order they were placed inside the list).

 

The abortCondition parameter can have the following values:

 

Constant

Value

Description

PR_NeverAbort

0

Never abort (No retry)

PR_NeverAbortButRetry

1

Never abort but does retry while the run FAILED

PR_AbortIfFail

2

Abort if the run still FAILED after some retry

PR_AbortIfWarning

3

Abort if the run had still a WARNING after some retry

 

To detect a FAILURE or a WARNING during a graph execution, Anatella uses the “error level” of the process: See section 4.7. to know more about “error levels”. The default value for the abortCondition parameter is “PR_NeverAbortButRetry”.

 

Typical usage of the abortCondition=“PR_AbortIfFail” option is executing a FTP file transfer (e.g. using cUrl). Such type of task can easily fail. Failure is detected and Anatella re-attempt a new FTP file transfer. The maximum number of attempt is specified using the parameter “nRetry” of the job (defined using the “addJob()” method of the ProcessRunner object).

 

The randomWaitbeforeRun parameter has the same purpose and meaning as for the “runImmediate()” method, hereabove.

 

The “run()” method returns the “error level” of the program with the largest “error level” (in absolute value) amongst all the programs it executed. The return value is zero if no errors or warnings were detected.

setVerbose(b)

Self-explanatory. The parameter “b” is true/false.

You can reduce verbosity writing “p.setVerbose(false);

 
 

Variables of the KeepBests class

N

The number of (key,value) pairs to store inside the KeepBests Object.

 

 

Methods of the KeepBests class

add(key,value)

Add a new (key,value) pair inside the KeepBests Object.

If the object already contains the maximum number of pairs, the pair with the lowest key is discarded.

getKey(index)

Gets the key stored inside the (key,value) pair of given index.

The index zero returns the greatest key.

getValue(index)

Gets the value stored inside the (key,value) pair of given index.

The index zero returns the values associated with the greatest key.

reset()

Empties out the object.

 
 

Methods of the SendMail class (LIB: EMailSMS)

setLoginPassword (login,password)

Self-explanatory

isConnected()

Returns true if this instance of the SendMail Object is now connected to the SMTP server. Once the initial connection has been established, all further emails are sent at very high speed.

send(toAddress,subject,

messageBody,ccAddress,

bccAddress,isHTML)

Sends one email (and establish a connection to the SMTP server first, if required).

 

The parameters ccAddress, bccAddress and isHTML are optional.

If omitted, these default values are used:

ccAddress=””

bccAddress=””

isHTML=false

 

All address parameters (i.e. toAdresss, ccAddress and bccAddress) have the following properties:

They can contains several e-mails, separated by comma’s.

Each e-mail can optionally have a “name” that precedes it: When using “names” the actual email must follow and be enclosed inside < and >.

 

For example: John Smith <JSmith@gmail.com>

 

The messageBody parameter usually contains simple text (this is the default behaviour). It can also contains HTML code (when the parameter isHTML=true).

close()

Close the connection to the SMTP server and free all related resources.

 
 

Methods of the SQLite class (LIB: DBConnectors)

isOpen()

Self-explanatory.

close()

When you don’t need the “SQLite” object anymore, you must always call the “close()” method to remove any lock on the SQLite dabase file, as-soon-as-possible, to allow other processes to access the database.

lastError()

Returns the last SQLite Error.

Please, refer to this page:

https://www.sqlite.org/c3ref/c_abort.html

… to have more information about the error.

execute(stmt)

Execute the given SQL statement using the SQLite engine.

 

The returned value depends on the nature of the statement:

If the statement returns no rows:

oIf the execution succeeded: The return value is 101.

oIf the execution failed: The return value is null. Use “lastError()” to get a more precise description of the error.

If the statement returns one or more rows, only the first row is returned inside the Javascript environment.

oIf the returned row contains many columns, you’ll receive an array with the content of the columns.

oIf the returned row contains only one column, you’ll receive a simple variable with the content of the column.

 

Here is an example of usage:

    AN76E5~1_img432

 

The above Javascript code test if the table “Profiles” contains the ID=42. Before checking for the ID, we check that:

the database file exists (i.e. the file “:/Profiles.sqlite” must exist).

the table “Profiles” exists.

 
 

Methods of the AnatellaGraph class

isOk()

Self-explanatory.

hasChanged()

Self-explanatory.

save(filename)

The parameter “filename” is optional. If omitted, Anatella uses the filename used to open the graph.

saveForVersioning(filename,

                                 resetUsers)

Both parameters are optional.

If the “filename” parameter is omitted, Anatella uses the filename used to open the graph.

If the “resetUsers” parameter is omitted, Anatella uses “resetUsers”=True

setEncryption(b)

The parameter “b” is true/false.

setEncoding(s)

The parameter “s” can be “utf8” or “utf16”.

setTempDir(dir)

Self-explanatory.

setTempDirLoc(i)

Set the Temporary Directory location:

   i=0 : global OS temp dir

   i=1 : Anatella-specific temp dir

   i=2 : Graph-specific temp dir

addUser(login)

Self-explanatory.

removeUser(login)

Self-explanatory.

setUserPassword(login,password)

Self-explanatory.

hasUserPassword(login)

Self-explanatory. Returns true/false.

setUserAdmin(b)

Self-explanatory. The parameter “b” is true/false.

setUserExpirationDate(date)

Self-explanatory. The parameter “date” is a string with the format “yyyyMMdd”.

setUserEditGP(b)

Self-explanatory. The parameter “b” is true/false.

setUserEditGraph(b)

Self-explanatory. The parameter “b” is true/false.

setUserReadDB(b)

Self-explanatory. The parameter “b” is true/false.

setUserWriteDB(b)

Self-explanatory. The parameter “b” is true/false.

setODBCLogin(connection

                              name,login)

Self-explanatory.

setODBCPassword(connection

                                     name,login)

Self-explanatory.

setGP(global parameter name,

          value)

Self-explanatory.

Create a new Global Parameter if none is found with the given name.

getUsers()

Returns an array describing the users of the Anatella graph.

Each element of the array is an object with the fields “login”,“isAdmin”, “canEditGP”, “canEditGraph”, “canReadDB”, “canWriteDB”, “expirationDate”

getODBC()

Returns an array describing the ODBC connection used in the Anatella graph. Each element of the array is an object with the fields “name”, “link”, “login”, “password”

getGP()

Returns an array describing the Global Parameters of the Anatella graph.

Each element of the array is an object with the fields “name”, “value”, “comment”

getFiles()

Returns an object with 2 fields: “input” and “output”. These two fields (“input” and “output”) are arrays describing the input and ouput files used in the Anatella graph. Each element of these array is an object with the fields “action” and “filename”.

 

 

Anatella global-functions related to Mathematical Optimization

simpleGlobalOptimizer

   (nameObjectiveFunction,

    minX, maxX,

    nIterationMax)

 

Find x*, the exact value of x (between minX and maxX) for which the ObjectiveFunction is minimum (it returns a minimum value).

 

The prototype of the ObjectiveFunction is something like:

function f(x) {  return <a_function_of_x> ; }

 

The parameter “nameObjectiveFunction” is a string that contains the name of the Javascript objective function to minimize.

 

The algorithm searches for a global minimum in-between minX and maxX. It terminates when the number of iterations reaches “nIterationMax”.

 

Return an object with 2 fields: xOpt and yOpt.

simpleLocalOptimizer

   (nameObjectiveFunction,

    minX, maxX,

    startX,

    startStepX, finalStepX)

 

Find x*, the exact value of x (between minX and maxX) for which the ObjectiveFunction is minimum (it returns a minimum value).

 

The prototype of the ObjectiveFunction is something like:

function f(x) {  return <a_function_of_x> ; }

 

The parameter “nameObjectiveFunction” is a string that contains the name of the objective function to minimize.

 

The algorithm searches for a local minimum in-between minX and maxX. It starts from the position “startX” (ideally, “startX” should be near x*, otherwise there is a larger risk of finding a local minimum instead of a global minimum) and does “steps” of size “startStepX”. When approaching x*, the step sizes are decreasing. The algorithm stops when the step size is smaller than “finalStepX”.

 

Return an object with 4 fields: xOpt, yOpt, nIter, info.