Skip to content

Commit f1f0a2e

Browse files
authored
Merge pull request #239 from Emotiv/develop
2 parents 58cc2ce + de77fd0 commit f1f0a2e

File tree

14 files changed

+602
-226
lines changed

14 files changed

+602
-226
lines changed

cpp-qt/cortexclient/Config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
1818
#include <QJsonObject>
1919

2020
/*
21-
* To get a client id and a client secret, you must connect to your Emotiv
22-
* account on emotiv.com and create a Cortex app.
23-
* https://www.emotiv.com/my-account/cortex-apps/
21+
* Enter your application Client ID and Client Secret below.
22+
* You can obtain these credentials after registering your App ID with the Cortex SDK for development.
23+
* For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
2424
*/
2525
static const QString ClientId = "The client id of your Cortex app goes here";
2626
static const QString ClientSecret = "The client secret of your Cortex app goes here";

csharp/CortexAccess/Config.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
static class Config
44
{
55
/*
6-
* To get a client id and a client secret, you must connect to your Emotiv
7-
* account on emotiv.com and create a Cortex app.
8-
* https://www.emotiv.com/my-account/cortex-apps/
6+
* Enter your application Client ID and Client Secret below.
7+
* You can obtain these credentials after registering your App ID with the Cortex SDK for development.
8+
* For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
99
*/
1010
public static string AppClientId = "put_your_application_client_id_here";
1111
public static string AppClientSecret = "put_your_application_client_secret_here";

python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ Before running the examples, please ensure you have completed the following step
2121
3. **Obtain an EMOTIV Headset or Create a Virtual Device**:
2222
- Purchase a headset from the [EMOTIV online store](https://www.emotiv.com/), **or**
2323
- Use a virtual headset in the EMOTIV Launcher by following [these instructions](https://emotiv.gitbook.io/emotiv-launcher/devices-setting-up-virtual-brainwear-r/creating-a-virtual-brainwear-device).
24-
4. **Get Client ID & Secret**: Log in to your Emotiv account at [emotiv.com](https://www.emotiv.com/my-account/cortex-apps/) and create a Cortex app. [Register here](https://id.emotivcloud.com/eoidc/account/registration/) if you don't have an account.
25-
5. **Authorize Examples**: The first time you run these examples, you may need to grant permission for your application to work with Emotiv Cortex.
24+
4. **Create your Cortex App**: Once you register your Cortex App ID, you will receive a Client ID and Client Secret, which serve as unique identifiers for your software application. For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
2625

2726
---
2827

@@ -46,6 +45,7 @@ Demonstrates how to:
4645
- Create a new record
4746
- Stop a record
4847
- Export recorded data to CSV or EDF
48+
- Query records and request to download record data
4949
See: [Records](https://emotiv.gitbook.io/cortex-api/records)
5050

5151
### 4. `marker.py` — Inject Markers

python/cortex.py

Lines changed: 337 additions & 186 deletions
Large diffs are not rendered by default.

python/facial_expression_train.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ def on_inform_error(self, *args, **kwargs):
258258

259259
def main():
260260

261-
# Please fill your application clientId and clientSecret before running script
262-
your_app_client_id = ''
263-
your_app_client_secret = ''
261+
# Enter your application Client ID and Client Secret below.
262+
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
263+
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
264+
your_app_client_id = 'put_your_app_client_id_here'
265+
your_app_client_secret = 'put_your_app_client_secret_here'
264266

265267
# Init Train
266268
t=Train(your_app_client_id, your_app_client_secret)

python/live_advance.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,11 @@ def on_inform_error(self, *args, **kwargs):
275275

276276
def main():
277277

278-
# Please fill your application clientId and clientSecret before running script
279-
your_app_client_id = ''
280-
your_app_client_secret = ''
278+
# Enter your application Client ID and Client Secret below.
279+
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
280+
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
281+
your_app_client_id = 'put_your_app_client_id_here'
282+
your_app_client_secret = 'put_your_app_client_secret_here'
281283

282284
# Init live advance
283285
l = LiveAdvance(your_app_client_id, your_app_client_secret)

python/marker.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def on_warn_record_post_processing_done(self, *args, **kwargs):
174174
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
175175
# - Connect your headset with dongle or bluetooth. You can see the headset via Emotiv Launcher
176176
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
177-
# - In the case you borrow license from others, you need to add license = "xxx-yyy-zzz" as init parameter
178177
# - Check the on_create_session_done() to see a record is created.
179178
# RESULT
180179
# - record data then inject marker each 3 seconds
@@ -184,9 +183,11 @@ def on_warn_record_post_processing_done(self, *args, **kwargs):
184183

185184
def main():
186185

187-
# Please fill your application clientId and clientSecret before running script
188-
your_app_client_id = ''
189-
your_app_client_secret = ''
186+
# Enter your application Client ID and Client Secret below.
187+
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
188+
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
189+
your_app_client_id = 'put_your_app_client_id_here'
190+
your_app_client_secret = 'put_your_app_client_secret_here'
190191

191192
m = Marker(your_app_client_id, your_app_client_secret)
192193

python/mental_command_train.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,11 @@ def on_inform_error(self, *args, **kwargs):
269269

270270
def main():
271271

272-
# Please fill your application clientId and clientSecret before running script
273-
your_app_client_id = ''
274-
your_app_client_secret = ''
272+
# Enter your application Client ID and Client Secret below.
273+
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
274+
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
275+
your_app_client_id = 'put_your_app_client_id_here'
276+
your_app_client_secret = 'put_your_app_client_secret_here'
275277

276278
# Init Train
277279
t=Train(your_app_client_id, your_app_client_secret)

python/query_records.py

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
from cortex import Cortex
2+
3+
class Records():
4+
"""
5+
A class to query records, request to download undownloaded records, and export local records
6+
7+
Attributes
8+
----------
9+
c : Cortex
10+
Cortex communicate with Emotiv Cortex Service
11+
12+
Methods
13+
-------
14+
start():
15+
start authorize process.
16+
query_records():
17+
To query records owned by the current user
18+
request_download_records()
19+
To request to download records if they are not at local machine
20+
export_record()
21+
To export records to CSV/ EDF files
22+
"""
23+
def __init__(self, app_client_id, app_client_secret, **kwargs):
24+
"""
25+
Constructs cortex client and bind a function to query records, request to download and export records
26+
If you do not want to log request and response message , set debug_mode = False. The default is True
27+
"""
28+
print("Query Records __init__")
29+
self.c = Cortex(app_client_id, app_client_secret, debug_mode=True, **kwargs)
30+
self.c.bind(authorize_done=self.on_authorize_done)
31+
self.c.bind(query_records_done=self.on_query_records_done)
32+
self.c.bind(export_record_done=self.on_export_record_done)
33+
self.c.bind(request_download_records_done=self.on_request_download_records_done)
34+
self.c.bind(inform_error=self.on_inform_error)
35+
36+
def start(self):
37+
"""
38+
To open websocket and process authorizing step.
39+
After get authorize_done The program will query records
40+
Returns
41+
-------
42+
None
43+
"""
44+
self.c.open()
45+
46+
def query_records(self, license_id, application_id):
47+
"""
48+
To query records
49+
Parameters
50+
----------
51+
orderBy : array of object, required : Specify how to sort the records.
52+
query: object, required: An object to filter the records.
53+
If you set an empty object, it will return all records created by your application
54+
If you want get records created by other application, you need set licenseId and applicationId as parameter of query object
55+
More detail at https://emotiv.gitbook.io/cortex-api/records/queryrecords
56+
Returns
57+
-------
58+
"""
59+
60+
query_obj = {}
61+
if license_id != '':
62+
query_obj["licenseId"] = license_id
63+
if application_id != '':
64+
query_obj["applicationId"] = application_id
65+
66+
query_params = {
67+
"orderBy": [{ "startDatetime": "DESC" }],
68+
"query": query_obj,
69+
"includeSyncStatusInfo":True
70+
}
71+
self.c.query_records(query_params)
72+
73+
def request_download_records(self, record_ids):
74+
"""
75+
To request to download records
76+
Parameters
77+
----------
78+
record_ids : list, required: list of wanted record ids
79+
More detail at https://emotiv.gitbook.io/cortex-api/records/requesttodownloadrecorddata
80+
Returns
81+
-------
82+
None
83+
"""
84+
self.c.request_download_records(record_ids)
85+
86+
def export_record(self, record_ids, license_ids):
87+
"""
88+
To export records
89+
By default, you can only export the records that were created by your application.
90+
If you want to export a record that was created by another applications
91+
then you must provide the license ids of those applications in the parameter licenseIds.
92+
Parameters
93+
record_ids: list, required: list of wanted export record ids
94+
license_ids: list, no required: list of license id of other applications
95+
----------
96+
More detail at https://emotiv.gitbook.io/cortex-api/records/exportrecord
97+
Returns
98+
-------
99+
None
100+
"""
101+
folder = '' # your place to export, you should have write permission, for example: 'C:\\Users\\NTT\\Desktop'
102+
stream_types = ['EEG', 'MOTION', 'PM', 'BP']
103+
export_format = 'CSV' # support 'CSV' or 'EDF'
104+
version = 'V2'
105+
self.c.export_record(folder, stream_types, export_format, record_ids, version, licenseIds=license_ids)
106+
107+
108+
# callbacks functions
109+
def on_authorize_done(self, *args, **kwargs):
110+
print('on_authorize_done')
111+
# query records
112+
self.query_records(self.license_id, self.application_id)
113+
114+
# callbacks functions
115+
def on_query_records_done(self, *args, **kwargs):
116+
data = kwargs.get('data')
117+
count = kwargs.get('count')
118+
print('on_query_records_done: total records are {0}'.format(count))
119+
# print(data)
120+
not_downloaded_record_Ids = []
121+
export_record_Ids = []
122+
license_ids = []
123+
for item in data:
124+
uuid = item['uuid']
125+
sync_status = item["syncStatus"]["status"]
126+
application_id = item["applicationId"]
127+
license_id = item["licenseId"]
128+
print("recordId {0}, applicationId {1}, sync status {2}".format(uuid, application_id, sync_status))
129+
if (sync_status == "notDownloaded") :
130+
not_downloaded_record_Ids.append(uuid)
131+
elif (sync_status == "neverUploaded") or (sync_status == "downloaded"):
132+
export_record_Ids.append(uuid)
133+
if license_id not in license_ids:
134+
license_ids.append(license_id)
135+
136+
# download records has not downloaded to local machine
137+
if len(not_downloaded_record_Ids) > 0:
138+
self.request_download_records(not_downloaded_record_Ids)
139+
140+
# Open comment below to export records
141+
# if len(export_record_Ids) > 0: # or export records are in local machine
142+
# self.export_record(export_record_Ids, license_ids)
143+
144+
def on_export_record_done(self, *args, **kwargs):
145+
print('on_export_record_done: the successful record exporting as below:')
146+
data = kwargs.get('data')
147+
print(data)
148+
self.c.close()
149+
150+
def on_request_download_records_done(self, *args, **kwargs):
151+
data = kwargs.get('data')
152+
success_records = []
153+
for item in data['success']:
154+
record_Id = item['recordId']
155+
print('The record '+ record_Id + ' is downloaded successfully.')
156+
success_records.append(record_Id)
157+
158+
for item in data['failure']:
159+
record_Id = item['recordId']
160+
failed_msg = item['message']
161+
print('The record '+ record_Id + ' is downloaded unsuccessfully. Because: ' + failed_msg)
162+
163+
self.c.close()
164+
165+
def on_inform_error(self, *args, **kwargs):
166+
error_data = kwargs.get('error_data')
167+
print(error_data)
168+
169+
# -----------------------------------------------------------
170+
#
171+
# GETTING STARTED
172+
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
173+
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
174+
# RESULT
175+
# - on_query_records_done: will show all records filtered by query condition in query_record
176+
# - on_export_record_done: will show the successful exported record
177+
# - on_request_download_records_done: will show all success and failure download case
178+
#
179+
# -----------------------------------------------------------
180+
181+
def main():
182+
183+
# Enter your application Client ID and Client Secret below.
184+
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
185+
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
186+
your_app_client_id = 'put_your_app_client_id_here'
187+
your_app_client_secret = 'put_your_app_client_secret_here'
188+
189+
# Don't need to create session in this case
190+
r = Records(your_app_client_id, your_app_client_secret, auto_create_session= False)
191+
192+
# As default, the Program will query records of your application.
193+
# In the case, you want to query records created from other application (such as EmotivPRO).
194+
# You need set license_id and application_id of the application
195+
# If set license_id without application_id. It will return records created from all applications use the license_id
196+
# If set both license_id and application_id. It will return records from the application has the application_id
197+
r.license_id = ''
198+
r.application_id = ''
199+
200+
r.start()
201+
202+
if __name__ =='__main__':
203+
main()
204+
205+
# -----------------------------------------------------------

python/record.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def on_inform_error(self, *args, **kwargs):
134134
# - Please reference to https://emotiv.gitbook.io/cortex-api/ first.
135135
# - Connect your headset with dongle or bluetooth. You can see the headset via Emotiv Launcher
136136
# - Please make sure the your_app_client_id and your_app_client_secret are set before starting running.
137-
# - In the case you borrow license from others, you need to add license = "xxx-yyy-zzz" as init parameter
138137
# - Check the on_create_session_done() to see how to create a record.
139138
# - Check the on_warn_cortex_stop_all_sub() to see how to export record
140139
# RESULT
@@ -147,9 +146,11 @@ def on_inform_error(self, *args, **kwargs):
147146

148147
def main():
149148

150-
# Please fill your application clientId and clientSecret before running script
151-
your_app_client_id = ''
152-
your_app_client_secret = ''
149+
# Enter your application Client ID and Client Secret below.
150+
# You can obtain these credentials after registering your App ID with the Cortex SDK for development.
151+
# For instructions, visit: https://emotiv.gitbook.io/cortex-api#create-a-cortex-app
152+
your_app_client_id = 'put_your_app_client_id_here'
153+
your_app_client_secret = 'put_your_app_client_secret_here'
153154

154155
r = Record(your_app_client_id, your_app_client_secret)
155156

0 commit comments

Comments
 (0)