Assets
Definiton
An asset is an instantiation of a blueprint. Countless assets can be created from a blueprint previously defined on the Altergo platform. A complete roadmap to create and delete an asset is illustrated here.
- Data download and ingestion: Covers how to use upload and download data to and from Asset Sensors with the SDK
Python Class
class Asset:
"""
Assets are the main entities of the Altergo platform.
They are instanciated from blueprints.
They are defined by their parameters and properties and ca store data on sensors
Attributes:
id (str): The id of the asset
asset_id (int): LEGACY asset id
serial_number (str): The serial number of the asset
blueprint (Blueprint): The blueprint of the asset
tags (List[Tag]): The tags of the asset
company (Company): The company of the asset
created_by (str): The user who created the asset
activities (List[Activity]): The activities of the asset
states (List[AssetState]): The states of the asset
properties (List[Any]): The properties of the asset
alert_temp (List[Any]): The alert temp of the asset
created_at (datetime): The creation date of the asset
updated_at (datetime): The last update date of the asset
dashboard (str): The dashboard of the asset
asset_statistics (AssetStatistics): The statistics of the asset
df (DataFrame): The dataframe of the asset
dfList (List[DataFrame]): The list of dataframes of the asset
"""
id: Optional[str] = None
asset_id: Optional[int] = None #LEGACY #TODO Delete
serial_number: Optional[str] = None
blueprint: Optional[Blueprint] = None
tags: Optional[List[Tag]] = None
company: Optional[Company] = None
created_by: Optional[str] = None
activities: Optional[List[Activity]] = None
states: Optional[List[AssetState]] = None
properties: Optional[List[Any]] = None
alert_temp: Optional[List[Any]] = None
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
dashboard: Optional[str] = None
asset_statistics: Optional[AssetStatistics] = None
df: Optional[DataFrame] = None
dfList: Optional[List[DataFrame]] = None
Setup
#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)
Create
The SDK provides the user with the ability to instantiate assets of blueprints by createAssetBySerial method. This method requieres a unique serial number and blueprint name as arguments to create an asset.
newAsset = Asset()
myNewAsset.serial_number = "SN_001" # Example serial number, should be unique
myNewAsset.blueprint = myBlueprint # should be an object of type Blueprint()
createdAsset = altergoApi.createAsset(newAsset=myNewAsset)
Get
The user can get an asset from Altergo with all its attributes using the getAssetBySerialNumber(serialNumber (str))
method
AssetSNToRetrieve = "SN_001"
retrievedAsset = altergoApi.getAssetBySerialNumber(serialNumber = AssetSNToRetrieve)
Update
AssetSNToUpdate = "SN_001"
assetToUpdate = altergoApi.getAssetBySerialNumber(serialNumber = AssetSNToRetrieve)
assetToUpdate.name = "Temp"
updatedAsset = updateAsset(updatedAsset = assetToUpdate)
Delete
The user can delete an asset from Altergo platform by deleteAsset()
method. It takes an Asset()
as parameter and returns a server response code as confirmation
assetToDelete = altergoApi.getAssetBySerialNumber(serialNumber = "SN_002")
response = altergoApi.deleteAsset(existingAsset=assetToDelete)
The deleteAssetBySerial method deletes assets PERMANENTLY !