Working with calculations
Maximo® Monitor provides a range of standard functions, which can be selected and applied to your data as metrics from a function catalog.
If you want to apply different calculations to your data, you can create custom functions. To add a layer of complexity, you can also apply metric calculations to the data that is derived as a result of an earlier metric calculation. Maximo Monitor runs a function pipeline to enable this form of calculation-stacking.
In Maximo Monitor 8.10 and later, streaming data metrics support custom functions only for ONNX models.
In Maximo Monitor 8.9, streaming data metrics do not support custom functions.
Using pandas
Before you write any custom expressions and functions, familiarize yourself with data structures, operations, and syntax in pandas. Pandas is built on NumPy. Many of the functions in Maximo Monitor incorporate NumPy arrays. The pandas library provides data structures, such as DataFrames and series, for the manipulation of numeric and time series data. Pandas also provides several predefined methods that you can use in your expressions and functions. For more information, see the pandas documentation..
Using IoT Functions
A set of built-in, sample, and base functions are available in a companion package, IoT Functions, in GitHub. You can derive your custom functions from the functions in this package. Explore the package before you add custom functions. Use the branch that corresponds to your Maximo Monitor version.
Adding calculations
You can write custom code and add it to your calculations in Maximo Monitor. Custom code is provided in the following forms:
- Expressions: A single line of code that performs a calculation that is expressed in valid
pandas syntax. Expressions can be pasted into the
PythonExpressionbuilt-in function through the UI. See Using expressions for more information. - Simple functions: A function declaration block that involves multiple lines of code. The function performs a calculation and is expressed in pandas. Simple functions are single-argument calculations and produce a single output. For more information, see Using simple functions.
- Custom functions: A function declaration block that involves multiple lines of code. The function performs a calculation and is expressed in pandas. Custom functions are multiple-argument calculations and can produce multiple outputs. Custom functions are stored externally in GitHub Enterprise and registered with Maximo Monitor. For more information, see Working with custom functions.
A set of built-in functions are provided in a function catalog to use in your metrics.
Scheduling metrics
The function pipeline is scheduled to run every 5 minutes. You can schedule when to run batch data metrics as part of this pipeline.
You can also run streaming data metrics as part of this pipeline, but you cannot configure schedules for streaming data metrics. Streaming data metrics receive and process data in near real-time. After you create a streaming data metric, it can take up to a minute to start the pipeline. You cannot combine streaming and batch data metrics in the pipeline.
For more information, see Timing of calculations.
Applying grains
You can apply a grain or level to some of your metrics to get a summary view of your data. You
can apply a time grain such as daily, weekly, monthly. For example, by using the
mean function, you can define a metric that aggregates the average distance
traveled for Robot A per hour.
You can also
use some custom timeframes, such as shifts. Using some of the built-in functions such as
ShiftCalendar, you can configure the start and end hours for shifts in your own
environment.
You can also choose to summarize an output by a specific dimension of the device type. For example, you can calculate the average distance traveled for Robot A and view the results per manufacturer.
For each device type and hierarchy node, the daily grain is available by default. You can make more grain options available through the Manage granularity dialog.
Using constants
Some of your batch data metrics might use constants. The same constant values might apply to multiple batch data metrics across device types. With Maximo Monitor, you can define a constant and set a value that is available to all your batch data metrics.
You can override the values that are used for a constant for individual device types. Later, if required, you can revert to use the global default values for a device type.
Constants can be of type boolean, literal, float, integer, number, a JSON object, or timestamp. The data type is specified as a Python data type during the registration process and is converted as follows:
-
booltoBOOLEAN -
strtoLITERAL -
floattoNUMBER -
inttoNUMBER -
dicttoJSON -
dt.datetimetoTIMESTAMP -
NonetoNone
Reference a constant in an expression or metric from Maximo Monitor or in a custom function using a prepopulated dictionary. In the following example, alpha and beta have constant values that are defined.
df['pressure'] * c['alpha'] + c['beta'] Before you can set the global or local value of a constant, you must create
and register each constant from your Python environment by using the def
register_constants(self, constants) method, where constants is an array of
constants to be registered. Similarly, to unregister a constant, use the def
unregister_constants(self, constant_names) method, where constant_names is
a list of constant names to be unregistered.
For an example of how to register, unregister, configure, and use a constant, see Tutorial: Adding a constant.
Streaming data metrics do not use constants.