In this article:

Integration with Python

Integration with Java

Integration with R

Integration with LPSolve

Integration with TRAMO and SEATS

Connecting External Modules to Foresight Analytics Platform

Integration with Python

Integration with the Python programming language enables the user to extend Foresight Analytics Platform capabilities in the following tools: Modeling and ForecastingTime Series AnalysisReports. The Python functions are applied in the uniform expression editor.

NOTE. Integration with Python from 3.5 to 3.12 is supported. To see if newer versions are supported, an additional investigation is required. The bitness of Python and Foresight Analytics Platform must match.
Astra Linux already has preinstalled version of Python 3.7 that is why it must be used. If, for some reason, this version is missing, add a symbolic link to a library by executing the following command: sudo ln -s /usr/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.so /opt/foresight/fp10.x-biserver/bin/

Steps for Python integration differ depending on the operating system in use.

For Python integration on Linux OS prebuild Python source files.

Python Build from Source Files in Linux OS

See below an example of Python source files build of 3.6.9 version in Astra Linux OS.

Execute the following operations:

  1. Download the archive with source files of Python 3.6.9:

wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz

  1. Unpack the file from the archive:

tar xvf Python-3.6.9.tgz
cd Python-3.6.9

  1. Add the configure file delivered with Python source files, parameters --enable-shared to generate dynamic library used by the platform and --prefix specifying Python installation folder:

./configure --enable-shared --prefix=/opt/python

  1. Compile Python source code, using altinstall:

sudo make altinstall

NOTE. The make altinstall command is used to prevent Python binary file from replacement, which is by default located at: S/usr/bin/python, where S is the path to the Python installation folder.

Compilation result must be the following:

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

Integration with Python in Linux OS

See below the example of Python 3.6.9 integration in Astra Linux OS. Make sure that Python source files build is ready.

For Python integration in Astra Linux OS:

  1. Check that source files are correctly built and a new Python version is installed.

If the default version was not overwritten in the system, check the current Python version using the command:

python3.6 --version

  1. Execute one of the operations if the command was not found:

    • Add a path to the Python installation folder in the Path system variable:

echo export PATH=$PATH:/opt/python/bin >> ~/.bashrc
source ~/.bashrc

    • Determine a path to Python libpython3.*m.so library, which was created using the --enable-shared parameter in Step 3:

echo export LD_LIBRARY_PATH="/opt/python/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc

On the first Python use, the platform will look for the library from the list:

libpython3.9.so, libpython3.8.so, libpython3.7m.so, libpython3.6m.so, libpython3.5m.so

The platform will use the first found library before the restart. Restart the BI server:

sudo systemctl restart apache2-fp10.x

For Python integration in Windows OS:

  1. Download Python distribution file.

  2. Install Python on the same computer where the Foresight Analytics Platform desktop application is installed. If Python is supposed to be used in the web application, install Python on the computer where BI server is located.

    • Select the Add Python <Version> to PATH checkbox in the Python installer to add a path to the Python installation folder in the Path system variable.

If Python is installed via package, for example, Anaconda, also select the Add...to PATH checkbox during the installation. Therefore, Foresight Analytics Platform is integrated with Python. All executed scripts must be located in the folder with installed Foresight Analytics Platform.

To specify an additional folder with scripts:

  • Create the PythonPath string parameter in the registry and set up the required path to the additional scripts folder. The parameter is created in the registry key: [HKEY_CURRENT_USER\SOFTWARE\Foresight\Foresight Analytics Platform\10.0\DevEnv\Python].

  • Use the IPythonUtils.AddFolderToPythonPath method.

If several Python versions are installed in Linux OS, execute the following operations:

  1. Add a symbolic link to the required library, for example:

ln -s /opt/python/lib/libpython3.9.so /opt/foresight/fp10.x-biserver/bin/

  1. In Windows OS in the registry key [HKEY_CURRENT_USER\SOFTWARE\Foresight\Foresight Analytics Platform\10.0\DevEnv\Python] create the PythonLib string parameter and as its value specify name of the required version of Python library, for example, libpython3.9.so. Save settings to the file with the *.reg extension to the folder /opt/foresight/fp10.x-biserver/bin.

NOTE. The [HKEY_CURRENT_USER] registry key can be replaced with [HKEY_LOCAL_MACHINE] if the path to the Python library is specified for all users and not only for the current user.

If the pip package management system was used to install Python, install the Python using the sudo pip3 command if search for Python libraries failed. If sudo is not used, Python is installed to the /home/user/.local/bin user folder, in which BI server cannot find Python libraries.

If several versions of Python were installed, and a specific version must be used, in Windows OS in the registry key [HKEY_CURRENT_USER\SOFTWARE\Foresight\Foresight Analytics Platform\10.0\DevEnv\Python] create the PythonLib string parameter and as its value specify name of the required version of Python library, for example, python39.dll.

For details about creating Python modules, where codes of macros in the Python language are stored, see the Creating Python Modules section.

Integration with Java

Integration with the Java language enables the user to extend Foresight Analytics Platform capabilities in the following tools: Modeling and ForecastingTime Series AnalysisReports. In the specified tools the Java functions are applied in the uniform expression editor.

Installing Java in Linux OS

If the Java language is already installed in Linux environment, steps 1-8 can be skipped. To install the Java language:

  1. Execute the commands in the terminal:

sudo mkdir /usr/lib/jvm
cd /usr/lib/jvm

  1. Download the .gz package from: https://www.oracle.com/java/technologies/downloads/#java8.

  1. Execute the command:

sudo tar -xvzf ~/Downloads/jdk-8u<Ver>-linux-x64.tar.gz

NOTE. The path to the .gz file may be different. Specify the path where the package was saved.

  1. Open the file with variables for edit:

sudo gedit /etc/environment

  1. Add the following strings to the end of the file:

J2SDKDIR="/usr/lib/jvm/jdk1.8.0_<Ver>"

J2REDIR="/usr/lib/jvm/jdk1.8.0_<Ver>/jre"

JAVA_HOME="/usr/lib/jvm/jdk1.8.0_<Ver>"

DERBY_HOME="/usr/lib/jvm/jdk1.8.0_<Ver>/db"

  1. If the file does not have the PATH variable, add the following value:

PATH="/usr/lib/jvm/jdk1.8.0_<Ver>/bin:/usr/lib/jvm/jdk1.8.0_<Ver>/db/bin:/usr/lib/jvm/jdk1.8.0_<Ver>/jre/bin:$PATH"

If the file has the variable, add the value to the list:

/usr/local/games:/usr/lib/jvm/jdk1.8.0_<Ver>/bin:/usr/lib/jvm/jdk1.8.0_<Ver>/db/bin:/usr/lib/jvm/jdk1.8.0_<Ver>/jre/bin

  1. Execute the following in the terminal:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_<Ver>/bin/java" 0

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_<Ver>/bin/javac" 0

sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_<Ver>/bin/java

sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_<Ver>/bin/javac

  1. Restart the terminal. To check the installed version, execute the command:

java -version

Integration with Java in Linux OS

  1. Add a symbolic link:

sudo ln -s /usr/lib/jvm/jdk1.8.0_<Ver>/jre/lib/amd64/server/libjvm.so /opt/foresight/fp10.x-biserver/bin/libjvm.so

  1. In Windows OS in the registry key [HKEY_CURRENT_USER\SOFTWARE\Foresight\Foresight Analytics Platform\10.0\DevEnv\Java] create the Java subsection, in which create the Options string parameter. This parameter will be used to specify additional options used on creating and working with a Java machine. Specify values in the Options parameter via comma. Save settings to the file with the *.reg extension to the folder /opt/foresight/fp10.x-biserver/bin/registry.

  2. Open the obtained *.reg file in the Linux environment and set values for the Options parameter:

"Options"="-Djava.home=/usr/lib/jvm/jdk1.8.0_<Ver>/jre"

  1. If the "Check Value of CLASSPATH" error occurred at the runtime, add the value "-Dfile.encoding=UTF-8" via a comma to the Options parameter.

  2. One can also specify in the Options parameter the paths to the files with custom classes (archives with custom classes). Separate paths with a semicolon, for example, "-Djava.class.path=/opt/foresight/fp10.x-biserver/:/usr/local".

NOTE. In the above specified commands <Ver> - Java language version.

For integration with the Java language install the following software:

  • Java SE Runtime Environment (JRE).

  • Java SE Development Kit (JDK).

NOTE. The installed Java must have version 8 or later. Bitness of Java and Foresight Analytics Platform must match.

After the installation is complete, execute the operations:

  1. Add the path to the folder with the jvm.dll library in the folder with installed JRE (for example, C:\Program Files\Java\jre1.8.0_<Ver>\bin\server\) to the Path system variable.

  2. In the registry key [HKEY_CURRENT_USER\SOFTWARE\Foresight\Foresight Analytics Platform\10.0\DevEnv] create the Java subsection, in which create the Options string parameter. This parameter will be used to specify additional options used on creating and working with a Java machine. Specify values in the Options parameter separating them with commas.

  3. In the Options parameter set the path to the installed JDK (path to the jre subdirectory in the folder with installed JDK), for example, "-Djava.home=c:/Program Files/Java/jdk1.8.0_<Ver>/jre/".

  4. One can also specify in the Options parameter the paths to the files with custom classes (archives with custom classes). Separate paths with a semicolon, for example, "-Djava.class.path=D:/Work/Java/;D:/Test/".

For details about creating Java modules, where codes of modules in the Java language are stored, see the Creating Java Modules section.

NOTE. In the above specified commands <Ver> - Java language version.

Integration with R

Connection to R allows for extending Foresight Analytics Platform capabilities in the following tools: Modeling and ForecastingTime Series Analysis and in the uniform expression editor.

To connect R:

  1. Install R on the local computer and the application server, if theTask Scheduler tool is used to start modeling problem calculation.

Steps for R installation differ depending on the operating system in use.

To install R in Astra Linux:

  1. Set up proxy server for the Bash command shell.

  2. Set up proxy server for the Apt-Get program that is used to install, update and uninstall software packages in Debian-based Linux OS distributions.

  3. Connect to the external Debian repository to download the R package files. To do this, open the /etc/apt/sources.list file for edit and add the following command to it:

deb http://ftp.ru.debian.org/debian/ stretch main

  1. Check package signatures from the repository. To do this, download GPG key for Debian repository and install it using the command:

sudo apt-key add <key file>

  1. Update package lists in the connected repository using the command:

sudo apt-get update

  1. Install R using the command:

sudo apt-get install r-base

NOTE. For details about R installation see R documentation.

  1. Install the Rserve package for the interaction of Foresight Analytics Platform with R using the commands:

sudo apt-get install r-cran-rserve

NOTE. For details about Rserve package installation see Rserve documentation.

  1. Start R.

  2. Connect the Rserve package using the command:

library(Rserve)

  1. Start the Rserve package using the command:

Rserve()

  1. Install the required R packages using the command:

install.packages("<package name>")

The list of required packages is given in the Which Foresight Analytics Platform Methods can be Calculated Using R? section.

  1. Register the Rserve package as a service:

    1. Create the rserve.service file in the /etc/systemd/system directory:

[Unit]
Description=Rserve

[Service]
Environment="ARG=--save --RS-encoding latin1"
Environment="R_HOME=/usr/lib/R"
ExecStart=/usr/lib/R/site-library/Rserve/libs//Rserve $ARG
Type=forking

[Install]
WantedBy=default.target

Where:

      • Environment with the ARG value. The argument for starting RServe with the use of latin1 encoding to provide correct query handling on calculation of formulas containing R methods.

      • Environment with the R_HOME value. Path to the folder with installed R.

      • ExecStart. Path to the RServe package.

      • WantedBy. The default.target output file contained in the /etc/systemd/system directory.

    1. Start Rserve:

systemctl daemon-reload
systemctl start rserve

NOTE. Registration of the Rserve package as a service is optional but it is recommended for automatic startup of R on startup of Foresight Analytics Platform.

After executing the operations, R will be installed on Astra Linux.

To install R in Windows OS:

  1. Load R installer.

  2. Install R.

NOTE. For details about R installation see R documentation.

  1. Add the path to the S\bin folder in the Path system variable, where S is the R installation folder.

  2. Start R and install the RServe package to interact with Foresight Analytics Platform with the R package using the command:

install.packages("RServe");

After executing the operation, during Rserve package installation the dialog box opens to select the server, from which package files will be loaded. If the package is installed successfully, the corresponding message is displayed.

NOTE. For details about RServe package installation see RServe documentation.

  1. Copy the Rserve.dll, Rserve.exe, Rserve_d.exe files:

    • For 32-bit systems: from S\library\Rserve\libs\i386 to S\bin\i386.

    • For 64-bit systems: from S\library\Rserve\libs\x64 to S\bin\x64.

Where S is the R installation folder.

  1. Select the Packages > Install Package(s) main menu item and install the required R packages. If the packages have already been downloaded to the computer, they can be installed by selecting the Packages > Install Packages from Local Files main menu item. For details about packages required for R methods calculation see the Which Foresight Analytics Platform Methods can be Calculated Using R? section.

After executing the operations, R will be installed in Windows OS.

  1. In Foresight Analytics Platform specify the path, where R is installed or the server, where R is deployed.

NOTE. This step is required if R is installed on the workstation different from the workstation, where Foresight Analytics Platform is installed. If the R package is installed on the same workstation where Foresight Analytics Platform is installed, the path to the R directory will be already specified.

    1. Select the Tools > Parameters item in the main menu of:

      • The object navigator in the desktop application.

      • The Time Series Analysis tool in the desktop application.

      • The Modeling and Forecasting tool in the web application. The item is available if a model is opened in the working area.

The Parameters dialog box opens.

    1. Go to the External Modules tab and specify the path where R is installed, for example:

      • For Linux OS: /usr/lib/R/site-library/Rserve/libs/.

      • For Windows OS: C:\Program Files\R\R-3.0.3\.

Therefore, Foresight Analytics Platform is integrated with R.

Integration with LPSolve

Connection to LPSolve allows for extending Foresight Analytics Platform capabilities:

To use the LPSolve solver in Linux OS:

  1. Download and unpack the liblpsolve55.so library. The library can be downloaded from one of the following websites:

Place the library in the /opt/foresight/fp10.x-biserver/bin/ folder.

  1. Perform the library checksum according to the GOST P 34.11-2012 algorithm with the hash length 256 bits and create the LpSplveHash file. To perform the checksum of the liblpsolve55.so library and create the file, one can use OpenSSL:

openssl dgst -engine gost -md_gost12_256 /opt/foresight/fp10.x-biserver/bin/liblpsolve55.so > /opt/foresight/fp10.x-biserver/bin/LpSolveHash

If OpenSSL is used, make sure that the encryption library by the GOST P 34.11-2012 algorithm is installed:

    • For Debian-based distributions: libgost-astra.

    • For RedHat-based distributions and ALT Linux: openssl-gost-engine.

  1. Open the file /opt/foresight/fp10.x-biserver/bin/LpSolveHash for edit and delete the string:

md_gost12_256(/opt/foresight/fp10.x-biserver/bin/liblpsolve55.so)=

The file should have only checksum value.

  1. Make sure that www-data is set as an owner of the added files: liblpsolve55.so and LpSplveHash:

sudo chown -R www-data:www-data /opt/foresight/fp10.x-biserver/bin/LpSolveHash

sudo chown -R www-data:www-data /opt/foresight/fp10.x-biserver/bin/liblpsolve55.so

  1. Restart the BI server:

sudo systemctl restart apache2-fp10.x

To use the LPSolve solver in Windows OS:

  1. Download and unpack the lpsolve55.dll library. The library can be downloaded from one of the websites:

  2. Specify the path to the lpsolve55.dll library:
    1. Select the Tools > Parameters item in the main menu of:

      • The object navigator in the desktop application.

      • The Time Series Analysis tool in the desktop application.

    1. Go to the External Modules tab and specify the path where the library is located. For example:

    1. Click the OK button.

After executing the operations the path to the lpsolve55.dll library is specified.

  1. Perform the library checksum according to the GOST P 34.11-2012 algorithm with the hash length 256 bits. To perform checksum of the lpsolve55.dll library, one can use the cpverify.exe utility from CryptoPro:

cpverify.exe -mk -alg GR3411_2012_256 <full path to library>

  1. Save checksum result to a file or the LpSolveHash file without extension:

    • If it is planned to use a custom file, create the EtalonHashPath string parameter and set full path to the file in the registry key [HKEY_CURRENT_USER\SOFTWARE\Foresight\Foresight Analytics Platform\10.0\Debug] on BI server if the web application is used, or on local computers of all users if the desktop application is used.

    • If it is planned to use the LpSolveHash file without extension, place it in the folder with installed Foresight Analytics Platform.

Therefore, Foresight Analytics Platform is integrated with LPSolve.

Integration with TRAMO and SEATS

When working with the TRAMO and SEATS statistical methods in Linux OS one should execute additional setup. In Windows OS one does not need to execute additional setup.

To execute additional setup in Linux OS:

  1. Make sure that the glibc library 2.29 or later is installed.

  2. Download .tar.gz archive at: https://sourceforge.net/projects/gretl/files/tramo/tramo-seats-linux-64.tar.gz/download.

  3. Unpack the archive using the command:

tar -zxvf tramo-seats-linux-64.tar.gz

  1. Open the unpacked opt folder using the command:

cd opt

  1. Move the tramo folder to the opt folder using the command:

sudo cp -r tramo /opt

  1. Create a link to the TRAMO program:

sudo ln -s /opt/tramo/bin/tramo /usr/bin/tramo

  1. Create a link to the SEATS program:

sudo ln -s /opt/tramo/bin/seats /usr/bin/seats

After executing the specified operations the TRAMO and SEATS statistical methods become available in Linux OS.

See also:

Which Foresight Analytics Platform Methods can be Calculated Using R?