Data Logic
One of the most frequently used types of custom logic is that for processing and manipulating data. The Platform allows users to easily select from an available set of custom logic functions to use when connecting to data.
Data Logic functions, when selected, are called after the Platform fetches the raw data from a source and converts it to a standard, object-based (JSON) format. The converted data is passed to the selected logic function, and the Platform expects the modified dataset, still in JSON format, to be returned from the logic function.
Make a copy of the data passed into the logic function by the Platform, modify that object in your logic, and return it at the end of the function. Alternatively, you can modify the original object in-place to ensure that you return the right object.
Below are the requirements for all custom Data Logic functions (in JavaScript; refer to the Flaremap Development Kit Technical Reference for Python logic function requirements).
Data Logic Function Requirements
| Definition Location: All Data Logic functions must be defined in the Logic.Data object. |
|---|
| Function Identifier: Each Data Logic function identifier must be unique among all property identifiers in the Logic.Data object. |
| Parameters: (1) Required The first parameter must receive the converted dataset that is fetched and passed to the function by the Platform. (2...n) Optional Any parameters beyond the first parameter are optional and custom to the defined function. |
| Return: The function must return the processed data in JSON format. This must be the only return value (e.g.: an array containing the data in one of its indices is not valid). Even if the function does not modify the dataset itself (for example, it processes data for other tools in the app but doesn’t change the actual dataset), it must still return the dataset, as the Platform expects to receive data back from all Data Logic functions. |
Example Data Logic Function Definition
Logic.Data['exampleFunction'] = (data,optionalParam='default') => {
for(let row in data) {
data[row]["sum_of_samples"] = data[row]["sample_a"] + data[row]["sample_b"];
}
return data;
};