Skip to main content

Activities

Definiton

Activities allows the user to track down operations/processes the asset had gone through. This article showcases how to leverage Ion Software Development Kit(Ion SDK) to perform CRUD operations on Activites

Payload

{
"name": activity.name,// String
"description": activity.description,// String
"location": activity.location,// String
"metadata": metadata,// ActivityMetadata
"tags": tagNames,// Tag
"assets": assetsSns,// EdisonGenericComponent
"startDate": int(activity.startDate) ,// Intiger
"endDate": int(activity.endDate),// Intiger
}

Class

class Activity:
"""
A class to handle ``Activity``.

Args:
id (int, optional): ``Activity`` ID. Defaults to ``None``.
name (str, optional): Name of the ``Activity``. Defaults to ``None``.
description (str, optional): Description of the ``Activity``. Defaults to ``None``.
location (str, optional): Location of the ``Activity``. Defaults to ``None``.
tags (list of ``Tag``, optional): List of ``Tag``s associated with the ``Activity``. Defaults to ``None``.
assets (list of ``Asset``, optional): List of ``Asset``s associated with the ``Activity``. Defaults to ``None``.
startDate (``Datetime``, optional): ``Datetime`` start date for the ``Activity``. Defaults to ``None``.
endDate (``Datetime``, optional): ``Datetime`` end date for the ``Activity``. Defaults to ``None``.
"""

id: Optional[int] = None
name: Optional[str] = None
description: Optional[str] = None
location: Optional[str] = None
metadata: Optional[List[ActivityMetadata]] = None
tags: Optional[List[Tag]] = None
assets: Optional[List[EdisonGenericComponent]] = None
startDate: Optional[float] = None
endDate: Optional[float] = None
info
  • Tutorial 1 : Description

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
info

API keys are user bound

from altergo_sdk.models.v2 import Activity
altergoApiKey = apiKey
_client = {
"apiKey": altergoApiKey,
"factory_api": ALTERGO_FACTORY_API,
"iot_api":ALTERGO_IOT_API
}
altergoApi = Client(**_client)

Create

The createActivity method of ION SDK enables the user to create activites from a python environment This example demonstrates the creation of an activity called KB_Activity

#Create Activity object

activityToCreate = Activity()# create an instance of activity class
activityToCreate.name = 'KB_Activity' # name of the activity
activityToCreate.description = "This is a demo activity for KB" # Discription
activityToCreate.location = "Main office"
activityToCreate.startDate = startDate #activity start date
activityToCreate.endDate = endDate #activity end data
activityToCreate.assets = []#list of asset activity needs to be linked
activityToCreate.metadata=[]#list of meta data
activityToCreate.tags = []

info

Altergo allows the user to link Assets, Tags and Metadata with an activity.

# create activity
altergoApi.createActivity(activityToCreate)

Get activity

The user can bring an existing activity in the Altergo platform to a python environment. To facilitate this feature, ION SDK provides three different methods - getActivitiesByName, getActivityById and getAllActivities

getActivitiesByName perceive the name of the activity as an argument and returns the list of all activities having that particular name.

altergoApi.getActivitiesByName('KB_Activity') 

Since the activity name can be similar for different activities, For the user to target a specific activity, Ion SDK provides the getActivityById method.getActivityById takes in Altergo ID (int) of activity as an argument and returns the corresponding activity.

altergoApi.getActivityById(3)

The user can bring all the activities defined on the Altergo platform to a python environment using the getAllActivities method. getAllActivities takes no arguments and returns a list of all the activities.

altergoApi.getAllActivities()

Edit

The user can leverage of editActivity method in ION SDK to change the parameters of an existing activity. The editActivity requires an activity object as an argument and returns the edited activity. In this article the KB_Activity (activity) is edited to modify the description of the activity and to link with KB_Demo_1 (asset)

# Get the asset to be edited
asset=altergoApi.getAsset('KB Demo_1')
from datetime import date

startDate = date(2022, 12, 25)
endDate=date(2023, 1, 14)
#Get the activity to be editted
editObj=altergoApi.getActivityById(19)
#Edits
editObj.name = 'KB_Activity' # name of the activity
editObj.description = "This is an editted activity " # Editted discription
editObj.location = "Main office"
editObj.startDate = startDate #activity start date
editObj.endDate = endDate #activity end data
editObj.assets = [asset]# Linking asset
editObj.metadata=[]#list of meta data
editObj.tags = []
# edit activity
altergoApi.editActivity(editObj)

Delete

The user can remove an activity defined on the Altergo platform with the removeActivity method of Ion SDK. removeActivity takes in an Activity object to be removed as the argument.

#Get the activity to be removed
removeObj=altergoApi.getActivityById(19)
#Remove activity
altergoApi.removeActivity(removeObj)

Upload dataset to activity

The user can attach datasets with activities using uploadDatasetToActivity method