Custom Modules

For more advanced analysis, users can save files of standardized code, utils, and modules in their Sisense for Cloud Data Teams Git repository to import and use in their in-app chart editor. Custom modules are a necessity to users that value code quality, repeatability, and scalability across their organization. 

Note: Custom modules are available on sites with both the Git Integration and the Python/R Integration. Site Administrators can contact their Account Managers for additional information.

Creating Custom Modules

Custom modules help teams maintain consistent analysis, smooth out workflows, and define business logic that can be reused easily. These modules are saved in a directory in the user’s Sisense for Cloud Data Teams Git repository in a directory called custom_modules.

Getting Started:
  • Create a new directory called custom_modules in the periscope/master branch if one does not already exist.
  • Custom_modules will be at the same level of the dashboard, views, and snippet directories.
  • Add files into this directory and push to the remote periscope/master branch.
Notes on custom modules
  • The total size of all custom modules is currently limited to 1MB.
  • All files in the custom_modules directory will be available to all users that have SQL edit access in Sisense for Cloud Data Teams. 
  • Custom modules cannot be used across different spaces. 
  • API calls are not supported in these files.

Using Custom Modules

After uploading files to the custom_modules directory in the git repository, users will be able to import their files in the code environment of any chart or view editor. 

Note: Sisense for Cloud Data Teams officially supports .r and .py modules, but other file types may be unofficially supported.

R

  • In R call periscope.source(‘mylib’), where mylib is the name of the module. 

Python

  • In Python call import mylib, where mylib is the name of the module.
  • For other files (e.g. images or models) use periscope.open(myfile), where myfile is the name of the file.

Importing other files like images or models is currently only supported for Python.
For example:

with periscope.open(‘state_pop.csv’) as file:
    df = pd.read_csv(file)
    print(df)

Loading in a Trained Model

With custom modules, analysts can load in a pre-trained model to the Sisense for Cloud Data Teams python environment by adding the .sav file to the custom_modules directory.

The user will need to first pickle their trained model as an .sav file. This can be done by adding these two lines of code to the bottom of the original training script. The script used to train the model and generate the .sav file does not have to be in the custom_modules directory.

import pickle
filename = 'finalized_model.sav'
pickle.dump(model, open(filename, 'wb'))

Once the .sav file is added to the custom_modules directory it can be imported into the Sisense for Cloud Data Teams python environment by using the periscope.open() function and the _Unpickler(). Users will need to add import pickle at the top of their python editor in order to load their model.

Below is an example of importing the .sav file and using the model in Sisense for Cloud Data Teams.

<a href="#top">Back to top</a>