neurosity / neurosity-sdk-python

[BETA] The Official Neurosity Python SDK 🤯
MIT License
50 stars 20 forks source link

kinesis feature not printing any output #13

Open eliquinox opened 1 year ago

eliquinox commented 1 year ago

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.

AshishSardana commented 7 months ago

Does your kinesis model work in the developer console?

image
AdonaiVera commented 6 months ago

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.

uzaymacar commented 1 month ago

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

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

instead of

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