Details of the Script Editor
Versions
The Python service is currently running Python 3.9.2 (2021-02-19) The R service is currently running R 4.0.2 (2020-06-23)
Performance
The Senseforce Python service uses native python integration which makes it extremely reliable and highly performant. Up to 64 scripts can run concurrently. Any additional request above that number is being queued for later execution. Every executed script has its own thread with its own timeout set to 30 min.
In case you experience performance degradation please contact your Senseforce agent.
Data Input
Row Limit
For performance reasons, there is a limit of 5.000.000 rows per dataset that can be imported to the script editor. If you need more rows consider aggregating them prior to your script.
Data Types
When selecting a dataset for input the data type of the columns may change after importing. In the following, we will list the transformation to the data types which are available in R/Python.
Type of dataset column | Data Type R | Data Type Python |
Text | factor | str |
Timestamp | numeric | str |
Double | numeric | float |
Integer | numeric | int |
Long | numeric | int |
Boolean | logical | bool |
Time | numeric | str |
Note, the Thing column is always a text column so it will be imported to the script editor as a factor vector if you are using R and not as a character vector.
Note, the Timestamp values are UNIX timestamps in milliseconds. Packages for handling timestamp usually expect a UNIX timestamp in seconds. If you are using such a package divide your timestamp by 1000.
Note, Numpy data types (Data types — NumPy v2.1 Manual ) are automatically converted to native Python data types.
Exceptions: numpy.float128 and numpy.complex256 are going to be converted to String.
'numpy.bool_' --> 'bool' 'numpy.int8' --> 'int' 'numpy.uint8' --> 'int' 'numpy.int16' --> 'int' 'numpy.uint16' --> 'int' 'numpy.int32' --> 'int' 'numpy.uint32' --> 'int' 'numpy.int64' --> 'int' 'numpy.uint64' --> 'int' 'numpy.longlong' --> 'int' 'numpy.ulonglong' --> 'int' 'numpy.float16' --> 'float' 'numpy.float16' --> 'float' 'numpy.float32' --> 'float' 'numpy.float64' --> 'float' 'numpy.float128' --> 'numpy.float128' 'numpy.complex64' --> 'complex' 'numpy.complex128' --> 'complex' 'numpy.complex256' --> 'numpy.complex256'
Disabled operations in Python
The following commands are not allowed for security reasons:
open()
to_csv()
__import__()
exec()
eval()
Importing External Models or Data Frames
By importing .rds or .pickle files to your script you can use R or Python objects in the script.
Clicking Import Dataset or Model in the Data tab will open a window where you can drop a .rds or .pickle file (or search for one with the explorer). Confirm the import after the file was uploaded. The file can be accessed by clicking next to the Imported variable. Now you should see next to your imported file - click the to add the code to your script necessary to access the object stored in the file. Accessing the attributes of the object you imported now should work in the same way as if you would do it in any other coding environment.
Data Output
Data Types
Available data types are,
String
Long
Double
Timestamp
Integer
Boolean
With the result data type you define how the widget should interpret your results. So if you want time to be displayed in a dynamic format depending on the viewed time frame make your result a timestamp (unix timestamp in milliseconds). If you want a fixed time format you can transform them into a string and define them as such. If you want to use your values as a value for the y-axis they need to be numerical (long, integer or double). If you use factors (which represent strings) in R make sure to transform them to a character vector when assigning them to your result variable.
Sorting
If you plan to use your results in a widget that only takes one value, like the single text widget, bar, or gauge chart, make sure the value you want to display is the first (or only) one in your results.
If the result is supposed to be used in a multi-chart using the auto-generated series feature and text on the x-axis the widget might display the data, not in the way you want it to. For more details please check the section about the widget editor.
Unit and Decimals
You can specify the unit of your result. Later you can use the unit to be displayed in your chart (e.g. in the legend). Decimals are only relevant for displaying results of type double. You can define how many digits are shown in the charts and widgets.
Comments in the Code
In R, you can use # to mark a line as a comment (or the end of a line).
In Python, you can use # (when the new Python Service is released to your tenant), or you can use single or triple " to mark a line as a comment sometimes.
Printing out variables in Python
You can print out a variable content, and check the result in the “Response Tab” of the browser.
Do not forget to delete or comment out all the print() statements after debugging otherwise your code won’t return a valid JSON.