Datasets
Definiton
Datasets
allows the user to attach a file to any entities within the platform. This article illustrates leveraging the dataset features with Ion Software Development Kit (Ion SDK )
- report generation guide: Covers how to use Datasets with the Function manager
Payload
{
"asset": asset,// EdisonGenericComponent
"dataFrame": example_df,// DataFrame
"dataSetDescription":"Example dataset ",// String
"datasetName":"Demo",// String
"fileType": "csv",// String
"fileName":"Demo dataset"// String
}
Upload dataset to assets
It is only possible to upload Pandas DataFrame as of now, more file format will be supported in the near future. Dataframes are converted to CSV when uploaded to the platform
This example demonstrates attaching a dataset -example_df
to an existing asset - KB_Demo_1
with uploadDatasetToAsset
method.
The uploadDatasetToAsset
method takes in the following arguments,
The ensuing code uploads the dataset to an asset
#Altergo parameters to connect with Client
ALTERGO_FACTORY_API= 'https://altergo.io/' #Default Factory API
ALTERGO_IOT_API= 'https://iot.altergo.io/' #Default IOT API
apiKey = "Your API KEY" #API key of the client
model_name='KB Demo' #Blueprint from which assset is made
serial_number='KB Demo_1'#Unique serial number to identify asset
API keys are user bound
from altergo_sdk.models.v2 import Asset
altergoApiKey = apiKey
_client = {
"apiKey": altergoApiKey,
"factory_api": ALTERGO_FACTORY_API,
"iot_api":ALTERGO_IOT_API
}
altergoApi = Client(**_client)
# Creating an example dataframe to upload as a dataset
example_df= pd.DataFrame({"Voltage":[3.6 + 0.01 * np.random.rand() for _ in range(1, 11)],"Current":[28 + 0.01 * np.random.rand() for i in range(1, 11)]})
# Getting asset
asset=altergoApi.getAsset('KB_Demo_1')
# Arguments
fields = {
'asset': asset,
'dataFrame': example_df,
'dataSetDescription':'Example dataset ',
'datasetName':'Demo',
'fileType': 'csv',
'fileName':'Demo dataset'
}
#Uploading dataset to assset
altergoApi.uploadDatasetToAsset(**fields)
Upload dataset to activity
It is only possible to upload Pandas DataFrame as of now, more file format will be supported in the near future. Dataframes are converted to CSV when uploaded to the platform
This example illustrates attaching the dataset -example_df
to an activity- KB_Activity
using uploadDatasetToActivity
method.
The uploadDatasetToActivity
method takes in the following arguments,
activity
(Activity): The activity that needs to be updateddataFrame
(DataFrame): Pandas dataframedataSetDescription
(str): Description of the dataset (optional)dataSetName
(str): Name of the dataset (optional)fileType
(str): Format of the filefileName
(str): Name of the file (optional)
The following codes attach datasets to an activity
# Getting activity
activities=altergoApi.getActivitiesByName('KB_Activity')
for activity in activities:
if activity.name=='KB_Activity':
activity=activity
fields= {
'activity': activity,
'dataFrame': df,
'dataSetDescription':'Statistical report of sensor data',
'datasetName':'Trail',
'fileType': 'csv',
'fileName':'Trail data-Report'
}
# Uploading dataset to assset
altergoApi.uploadDatasetToActivity(**fields)