Overview
The Sequence class provides methods for creating, retrieving, and updating sequences. Sequences represent temporal orderings of ESS instances for a specific twin or aggregate.
Methods
create(data: SequenceInsert)
Create a new sequence for a twin or aggregate.
The sequence data to create Show SequenceInsert properties
The module identifier for this sequence
The ESS database ID that this sequence references
The status of this sequence entry (e.g., “n” for new, “e” for existing)
Optional context metadata
Returns a tuple of (SequenceResponse | Error, status_code) Show SequenceResponse properties
The database ID of the created sequence
The ESS database ID referenced by this sequence
Optional context metadata
Example:
from avenieca.api.model import SequenceInsert
sequence = SequenceInsert(
module_id = "air_conditioner" ,
instance_id = 10 ,
status = "e" ,
context = None
)
res, status = eca.sequence.create( data = sequence)
if status == 201 :
print ( f "Created sequence with ID: { res.id } " )
get_all(module_id: str)
Get all sequences for a specific module.
The module identifier to retrieve sequences for
Returns a tuple of (List[SequenceResponse] | Error, status_code)
Example:
res, status = eca.sequence.get_all( module_id = "air_conditioner" )
if status == 200 :
for seq in res:
print ( f "Sequence ID: { seq.id } , Instance: { seq.instance_id } " )
get_one(module_id: str, db_id: int)
Get a specific sequence by its database ID.
The database ID of the sequence
Returns a tuple of (SequenceResponse | Error, status_code)
Example:
res, status = eca.sequence.get_one(
module_id = "air_conditioner" ,
db_id = 4
)
if status == 200 :
print ( f "Instance ID: { res.instance_id } , Status: { res.status } " )
update(module_id: str, db_id: int, data: SequenceInsert)
Update an existing sequence.
The database ID of the sequence to update
The updated sequence data
Returns a tuple of (SequenceResponse | Error, status_code)
Example:
from avenieca.api.model import SequenceInsert
sequence = SequenceInsert(
module_id = "air_conditioner" ,
instance_id = 10 ,
status = "sk" , # Update status to 'sk'
context = "Updated context"
)
res, status = eca.sequence.update(
module_id = "air_conditioner" ,
db_id = 4 ,
data = sequence
)
if status == 200 :
print ( f "Updated sequence: { res.id } " )
Complete Example
import os
from avenieca.api.eca import ECA
from avenieca.api.model import Config, ESSInsert, SequenceInsert
# Initialize client
config = Config(
uri = "http://localhost:2580/v1" ,
username = os.getenv( "USERNAME" ),
password = os.getenv( "PASSWORD" )
)
eca = ECA(config)
# Create an ESS first
ess = ESSInsert(
module_id = "aggregate001" ,
state = [ 25.0 , 70.0 , 10.0 ],
valence = 10.0 ,
score = 5
)
ess_res, ess_status = eca.ess.create( data = ess)
# Create a sequence referencing the ESS
sequence = SequenceInsert(
module_id = "aggregate001" ,
instance_id = ess_res.id, # Reference the created ESS
status = "e"
)
seq_res, seq_status = eca.sequence.create( data = sequence)
print ( f "Created sequence { seq_res.id } for ESS { ess_res.id } " )
# Get all sequences for the module
all_sequences, status = eca.sequence.get_all( module_id = "aggregate001" )
for seq in all_sequences:
print ( f "Sequence: { seq.id } , Instance: { seq.instance_id } " )