Skip to main content

Report Generation

Function manager basic example

Here, the user can find a basic example that goes over the capabilities of the function manager feature of the Altergo platform.

Create function

Functions are python notebooks executing desired tasks for the user. In this example, a function called Report Functiongenerating statistical reports for sensor data is created and the generated reports are attached to the corresponding asset using the Dataset feature of the Altergo platform.

The following codes constitute the python notebook for Report Function

ALTERGO_FACTORY_API= 'https://altergo.io/' #Default Factory API
ALTERGO_IOT_API= 'https://iot.altergo.io/' #Default IOT API
api_key = "" #API key of the client

sensor_list=['Voltage','Current','SoC']# list of sensors

serial_number='' #Unique serial number to identify asset


caution

The user needs to insert all the input parameters in the first cell itself

!pip install git+https://bitbucket.org/freemens/ion_sdk.git@assembly --upgrade
import ion_sdk.edison_api.edison_api as eapi
import pandas as pd
edApi = eapi.Client(api_key, ALTERGO_FACTORY_API, ALTERGO_IOT_API)#Connect to the Altergo Client
asset=edApi.getAsset(serial_number)#importing asset to python environment
#specifying start and end date
startDate = eapi.edisonDate(2021,1,4,0,0,0)
endDate = eapi.edisonDate(2021,1,6,0,0,0)
edApi.getAssetDataFrame([asset],sensor_list,startDate,endDate) # importing data attached to the asset
df=asset.df
report=df.describe() #Creating a statistical report 
report=pd.DataFrame(report) # converting report to dataframe
#preprocessing the report
report['']=report.index
first_column = report.pop('')
report.insert(0, '', first_column)
fields = {
'asset': asset,
'dataFrame': report,
'dataSetDescription':'Statistical report of sensor data',
'datasetName':'Report',
'fileType': 'csv',
'fileName':'Sensor data-Report'
}
#Attaching dataset to the asset
edApi.uploadDatasetToAsset(**fields)

These codes as a python notebook (.ipynb) with the file name Create dataset.ipynb is integrated with the platform by the File upload method to create Report Function ![created function.jpg](/migration/images/created function.jpg)

Create program

The programs executes the function. For this example, a program called Report Program is defined to run the Report Function. While creating a program the user needs to type in the required input parameters of the function. The input parameters for this example is the serial_numberof the asset.These values are inputted to Functions: parameters in json format

{
"serial_number":"KB Demo_1"
}

![program inputs.jpg](/migration/images/program inputs.jpg)

Created Report Program ![created program.jpg](/migration/images/created program.jpg)

The program is now ready to run. Executing the program will create a statistical sensor report for the asset KB Demo_1 and this report gets attached to the asset as a dataset called Report and with file name Sensor data-Report in csv format. ![Program run status.jpg](/migration/images/Program run status (1).jpg)

Create automation

Automations feature in the function manager can pre-schedule the execution of a program. In this example, automation called Report Automationis defined to run the Report Program at a fixed time. Following are the steps involved

  1. Triger Type is set as At a scheduled time.
  2. Using corn expression '30 03 01 Jan,Apr,Jul,Oct * ' the Report Automation is set to trigger at 05:30 AM , on day one of the months January, April ,August and December.

![Automation time.jpg](/migration/images/Automation time (2).jpg)

info

Time in GMT

  1. The action to be done for Report Automation is set as Execute A Program
  2. The Script to run is set as Report Programe

![Automation action.jpg](/migration/images/Automation action (1).jpg)

When the time reaches 05:30 AM on day one of January,April ,August and December.

  • Report Automation get triggred
  • Executes Report Program (Report Function. runs)
  • Creates a dataset with the statistical report for the asset (KB Demo_1 ) sensor data and attaches it to the same asset.