The ECAResponse class provides methods for retrieving stored prediction responses. When predictions are made with store_response=True, they are saved and can be retrieved later using this API.
from datetime import datetime# Get all responses for analysisresponses, status = eca.response.get_all()if status == 200: # Filter by module ac_responses = [ r for r in responses if r.twin_module_id == "air_conditioner" ] print(f"Air conditioner predictions: {len(ac_responses)}") # Analyze percept patterns percept_patterns = {} for resp in ac_responses: pattern = tuple(resp.percept_ess_ids) if pattern in percept_patterns: percept_patterns[pattern] += 1 else: percept_patterns[pattern] = 1 print("\nMost common percept patterns:") for pattern, count in sorted( percept_patterns.items(), key=lambda x: x[1], reverse=True )[:5]: print(f" {pattern}: {count} times") # Get predictions by date for resp in ac_responses[-5:]: print(f"\n{resp.created_at}:") print(f" From: {resp.percept_names}") print(f" To: {resp.response_names}")
The Response API works hand-in-hand with the Cortex API:
from avenieca.api.model import NextStateRequest# Make prediction WITHOUT storingrequest = NextStateRequest( module_id="air_conditioner", n=1, store_response=False # Don't store)res, status = eca.cortex.predictions(data=request)print("Prediction made, not stored")# Make prediction WITH storingrequest_stored = NextStateRequest( module_id="air_conditioner", n=1, store_response=True # Store this one)res, status = eca.cortex.predictions(data=request_stored)print("Prediction made and stored")# Retrieve the stored predictionall_responses, status = eca.response.get_all()latest = all_responses[-1]print(f"Latest stored response ID: {latest.id}")