Use aggregated statistics in analysis sets
A step by step guide to use our API to use aggregated statistics in context of analysis sets.
Analysis sets allow you to gather raw data for various quality or EHS processes. While this raw data can be analyzed and reported within the platform, there are instances where aggregated statistics are more useful. For example, when creating Certificates of Analysis, you may need to report average values instead of individual measurements.
In scenarios requiring data aggregation within analysis sets, our API comes into play. This article explains how to utilize our API to access aggregated statistics within your analysis sets.
Statistics API endpoint
The API provides a dedicated endpoint that can generate statistics based on a specific dataset. Detailed documentation on this functionality is available on our developer portal.
Utilizing this endpoint within a workflow allows us to fetch the statistics and apply aggregated data directly to our results for further analysis and reporting.
Step-by-step
This solution involves the following components:
- An analysis set containing raw data
- An analysis set where aggregated statistics are stored and processed. This set can be the same as the one mentioned in point #1
- A workflow with a webhook call that triggers the getStatistics endpoint
- A text field in the analysis set mentioned in point #2 to store the JSON response value from the endpoint
- An expression in the analysis set mentioned in point #2 that extracts individual values from the endpoint's response. These values can be stored in the same set or transferred to another set using a workflow with Result Transfer.
Example
This section will guide you through a step-by-step example of populating an analysis set with aggregated batch data. The average values can for instance be utilized for CoA reporting purposes.
Step 1: Analysis set with raw data
This analysis contains multiple results per batch number. Each result has a value for pH.
Step 2: Analysis set that collects aggregated data
This analysis set displays the average pH values for each batch. This data will be utilized to generate a Certificate of Analysis (CoA) that highlights the average values for a specific batch. To facilitate this process, we have included a text field for storing the API response value, which will be utilized in conjunction with the expression engine for further data processing.
Step 3: Workflow that retrieves aggregated statistics via a call to our API
When a new result is added with a specific batch number, we utilize the getStatistics API endpoint to fetch the average pH value for all results corresponding to that batch number.
Pro Tip: Make use of the developer portal for creating and testing your getStatistics request.
The request for this example scenario is:
https://[tenant].alisqi.com/api/getStatistics?setId=[setid]&fields=ph_&filter={"batchnumber_":[{"value":"{batchnumber_}"}]}&access_token=[token]The
{batchnumber}
variable refers to the specific batch number entered by the user when adding a new result in the Aggregate analysis set. When the workflow runs, this variable will be substituted with the actual batch number provided by the user.Step 4: Store API response value in a text field
In the workflow's webhook setup, we designate the response field as "API response value." This field will capture the raw JSON response from the API, enabling the expression engine to extract the necessary information from it.
Once the workflow is triggered and the webhook communicates with the API, the response is received as a JSON encoded string within the API response value field.
The subsequent step involves creating an expression to specifically extract the average pH value from this JSON data.
Step 5: Process the API response value with an expression
By utilizing the expression engine, we can extract specific values from the API response. The pH field is transformed into a calculated numeric field through this process. The expression is set up to decode the JSON value from the API Response field and retrieve the average value of the pH field.
In cases where a value cannot be obtained, it defaults to NULL
. This automated process fills the pH field with the average pH value related to the batch number, which is what we needed in generating the batch level Certificates of Analysis (CoA).
These 5 steps allow you to use all the aggregated statistics provided by our getStatistics or getSpecEvaluation endpoints.
Call any API
This method can be used to access any external API, enabling you to fetch data from various external services and analyze it within the context of your analysis sets and results.