neurosity-sdk-python icon indicating copy to clipboard operation
neurosity-sdk-python copied to clipboard

kinesis feature not printing any output

Open eliquinox opened this issue 2 years ago • 3 comments

I have trained a kinesis leftArm via dev console and wanted to access it via the python API. My script:

from neurosity import NeurositySDK
from dotenv import load_dotenv
import os
import time

load_dotenv("my.env")

device_id = os.getenv("NEUROSITY_DEVICE_ID")
neurosity = NeurositySDK({
    "device_id": device_id
})

neurosity.login({
    "email": os.getenv("NEUROSITY_EMAIL"),
    "password": os.getenv("NEUROSITY_PASSWORD")
})

info = neurosity.get_info()

def callback(data):
    print(data)

unsubscribe = neurosity.kinesis("leftArm", callback)

time.sleep(20)
unsubscribe()
print("Done with example.py")

When I run the script, however, I get no output. Not sure where the problem is.

eliquinox avatar Sep 21 '23 22:09 eliquinox

Does your kinesis model work in the developer console? image

AshishSardana avatar Apr 07 '24 20:04 AshishSardana

Hi @eliquinox 👋 ,

To obtain the prediction, please use the kinesis_predictions function. Below is the example code:

from neurosity import NeurositySDK
from dotenv import load_dotenv
import os
import time

# Load environment variables from a .env file
load_dotenv("my.env")

# Initialize Neurosity SDK with device ID
device_id = os.getenv("NEUROSITY_DEVICE_ID")
neurosity = NeurositySDK({"device_id": device_id})

# Log in to Neurosity
neurosity.login({
    "email": os.getenv("NEUROSITY_EMAIL"),
    "password": os.getenv("NEUROSITY_PASSWORD")
})

# Fetch device information
info = neurosity.get_info()

# Callback function to process the data
def callback(data):
    print(data)

# Subscribe to kinesis events for the left arm
unsubscribe = neurosity.kinesis("leftArm", callback)

# Wait for 20 seconds to collect data
time.sleep(20)

# Unsubscribe and clean up
unsubscribe()
print("Finished execution of example.py")

Here are the results from running the above script:

{"label": "push", "metric": "kinesis", "probability": 0.01727728877348198, "timestamp": 1713891598118, "type": "training"}
{"label": "push", "metric": "kinesis", "probability": 0.013549573655196736, "timestamp": 1713891598243, "type": "training"}
{"label": "push", "metric": "kinesis", "probability": 0.01411070240397368, "timestamp": 1713891598368, "type": "training"}
{"label": "push", "metric": "kinesis", "probability": 0.01187809103675398, "timestamp": 1713891598493, "type": "training"}

Please let me know if this works for you!

PDT: If there is no response, it could be due to an incorrect naming of the trained action.

AdonaiVera avatar Apr 23 '24 17:04 AdonaiVera

In case someone else is also confused, exactly like @AdonaiVera said:

unsubscribe = neurosity.kinesis_predictions("leftArm", callback)

instead of

unsubscribe = neurosity.kinesis("leftArm", callback)

uzaymacar avatar Sep 18 '24 15:09 uzaymacar