Skip to content

Calculation Transformations

Calculations Setup

The CALCSETUP flow is used to create a Calculation Transformations model. This model is a vessel for the custom python code that processes signal data to generate output signals.

Request Parameters

Input Signal Set

This is a collection of input signals. It requires a list of signal IDs and their corresponding names, as shown in the sample payload. You must also provide a name for the group, which will be saved in the system to identify this specific combination of input signals. The input to your python function will be a dictionary with key names of the signal names in your input group.

Output Signal Set

This is where you define a list of signal names and value types of the output signals.

Statistic

Specifies the aggregation method—Max, Mean, or Min—used when data is downsampled. If the data level is the same as or finer than the original data, the function receives values that reflect the raw data (i.e., unaggregated).

Evaluation Window

Defines the time window used to gather input signal data for the Python function. For example, a value of PT3M indicates that each assessment will use a 3-minute window of input signal data, which is passed to the function as the input dictionary. See Calculation Transformation Overview for more details.

Request Payload

{
   "flowType": "CALCSETUP",
   "name": "CALCSETUP flow with 2 inputs and 2 outputs",
   "spec": {
       "name": "MainInputs",
       "inputSignalset": {
           "name": "Input_Signals",
           "valueType": "Numeric",
           "signals": [
               {
                   "signal": "123456789123456789",
                   "name": "signalA"
               },
               {
                   "signal": "123456789123456789",
                   "name": "signalB"
               }
           ]
       },
       "outputSignalset": {
           "name": "Output_Signals",
           "signals": [
               {
                   "valueType": "Numeric",
                   "name": "outputSignalA"
               },
               {
                   "valueType": "Numeric",
                   "name": "outputSignalB"
               }
           ]
       },
       "modelDetails": {
           "statistic": "mean",
           "script": "def calculate (signal_data): return {outputSignalA, outputSignalB}", 
           # A string of a python function that takes in a dictionary of input signals, and outputs a dictionary of the output signals
           "valueType": "Numeric",
           "evaluationWindow": "PT3S"
       }
   }
}

cURL request

$ curl --location --request POST 'https://app3.falkonry.ai/api/1.2/accounts/xxxxxxxxxxxxxxx/flows' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '<Insert Json payload here>'

Python

import requests 
import json

URL = 'https://app3.falkonry.ai/api/1.2/accounts/xxxxxxxxxxxxxxx/flows'
TOKEN = '<token>' 
HEADERS = {'Authorization': f'Bearer {TOKEN}', 'Content-Type': 'application/json'} 
PAYLOAD = <Insert Json payload here>

response = requests.post(URL, headers=HEADERS, data=json.dumps(PAYLOAD)) 
print(response.json())

Note

When a CALCSETUP flow is posted, it creates a model that defines how input signal data is processed through the function to produce output signal values. The model is assigned an ID and an assessment ID, both of which can be used to run a CALCEVAL Flow. You can retrieve this information by sending a GET request to the CALCSETUP flow using its flow ID, which can be done using an API request or using your browser network tools on the CALCSETUP flow in the activities monitor.

Calculations Evaluation

The CALCEVAL flow is used to evaluate a Calculation transform model over a specified historical time range. It generates output for the defined output signals based on the provided input signals.

Request Parameters

  • timeRange : It requires startTime and endTime parameters in ISO 8601 format, which define the evaluation time range.
  • assessment : This is the assessment ID of the model created during the Calc Setup Flow. This can be identified in the flow output details.
  • model : This is the model ID of the model created during the Calc Setup Flow. This can be identified in the flow output details.

Request Payload

{
   "flowType": "CALCEVAL",
   "name": "eval ",
   "assessment": "123456789123456789",
   "spec": {
       "timeRange": {
           "startTime": "2024-07-23T00:00:00.000000000Z",
           "endTime":   "2024-10-09T00:00:00.000000000Z"
       },
       "model": "123456789123456789"
   }
}

cURL request

$ curl --location --request POST 'https://app3.falkonry.ai/api/1.2/accounts/xxxxxxxxxxxxxxx/flows' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '<Insert Json payload here>'

Python

import requests 
import json

URL = 'https://app3.falkonry.ai/api/1.2/accounts/xxxxxxxxxxxxxxx/flows'
TOKEN = '<token>' 
HEADERS = {'Authorization': f'Bearer {TOKEN}', 'Content-Type': 'application/json'} 
PAYLOAD = <Insert Json payload here>

response = requests.post(URL, headers=HEADERS, data=json.dumps(PAYLOAD)) 
print(response.json())