Skip to content

Commit 4270f32

Browse files
committed
update rework
1 parent 8576852 commit 4270f32

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

python/query_records.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,27 @@ def __init__(self, app_client_id, app_client_secret, **kwargs):
3636
def start(self):
3737
"""
3838
To open websocket and process authorizing step.
39-
After get authorize_done The program will query_records
39+
After get authorize_done The program will query records
4040
Returns
4141
-------
4242
None
4343
"""
4444
self.c.open()
4545

46-
def query_records(self):
46+
def query_records(self, license_id, application_id):
4747
"""
4848
To query records
4949
Parameters
5050
----------
5151
orderBy : array of object, required : Specify how to sort the records.
5252
query: object, required: An object to filter the records.
5353
If you set an empty object, it will return all records created by your application
54-
If you want get records created by other applications, you need set licenseId as parameter of query object
54+
If you want get records created by other application, you need set licenseId and applicationId as parameter of query object
5555
More detail at https://emotiv.gitbook.io/cortex-api/records/queryrecords
5656
Returns
5757
-------
5858
"""
5959

60-
license_id = '' #Set this parameter to filter the records by their license.
61-
application_id = "", # filter by applicationId but must set licenseId as well. for example: com.emotiv.emotivpro
6260
query_obj = {}
6361
if license_id != '':
6462
query_obj["licenseId"] = license_id
@@ -85,14 +83,15 @@ def request_download_records(self, record_ids):
8583
"""
8684
self.c.request_download_records(record_ids)
8785

88-
def export_record(self, record_ids):
86+
def export_record(self, record_ids, license_ids):
8987
"""
9088
To export records
9189
By default, you can only export the records that were created by your application.
9290
If you want to export a record that was created by another applications
93-
then you must provide the license id of those applications in the parameter licenseIds.
91+
then you must provide the license ids of those applications in the parameter licenseIds.
9492
Parameters
9593
record_ids: list, required: list of wanted export record ids
94+
license_ids: list, no required: list of license id of other applications
9695
----------
9796
More detail at https://emotiv.gitbook.io/cortex-api/records/exportrecord
9897
Returns
@@ -101,21 +100,16 @@ def export_record(self, record_ids):
101100
"""
102101
folder = '' # your place to export, you should have write permission, for example: 'C:\\Users\\NTT\\Desktop'
103102
stream_types = ['EEG', 'MOTION', 'PM', 'BP']
104-
export_format = 'CSV'
103+
export_format = 'CSV' # support 'CSV' or 'EDF'
105104
version = 'V2'
106-
107-
# license_ids: If set empty list, which means that you can only export the records created by your application.
108-
# You can provide the license ID of other applications in order to export the records created by these applications.
109-
license_ids = []
110-
111105
self.c.export_record(folder, stream_types, export_format, record_ids, version, licenseIds=license_ids)
112106

113107

114108
# callbacks functions
115109
def on_authorize_done(self, *args, **kwargs):
116110
print('on_authorize_done')
117111
# query records
118-
self.query_records()
112+
self.query_records(self.license_id, self.application_id)
119113

120114
# callbacks functions
121115
def on_query_records_done(self, *args, **kwargs):
@@ -125,21 +119,27 @@ def on_query_records_done(self, *args, **kwargs):
125119
# print(data)
126120
not_downloaded_record_Ids = []
127121
export_record_Ids = []
122+
license_ids = []
128123
for item in data:
129124
uuid = item['uuid']
130125
sync_status = item["syncStatus"]["status"]
131126
application_id = item["applicationId"]
127+
license_id = item["licenseId"]
132128
print("recordId {0}, applicationId {1}, sync status {2}".format(uuid, application_id, sync_status))
133129
if (sync_status == "notDownloaded") :
134130
not_downloaded_record_Ids.append(uuid)
135131
elif (sync_status == "neverUploaded") or (sync_status == "downloaded"):
136132
export_record_Ids.append(uuid)
133+
if license_id not in license_ids:
134+
license_ids.append(license_id)
137135

138136
# download records has not downloaded to local machine
139137
if len(not_downloaded_record_Ids) > 0:
140138
self.request_download_records(not_downloaded_record_Ids)
141-
elif len(export_record_Ids) > 0: # or export records are in local machine
142-
self.export_record(export_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)
143143

144144
def on_export_record_done(self, *args, **kwargs):
145145
print('on_export_record_done: the successful record exporting as below:')
@@ -186,6 +186,14 @@ def main():
186186

187187
# Don't need to create session in this case
188188
r = Records(your_app_client_id, your_app_client_secret, auto_create_session= False)
189+
190+
# As default, the Program will query records of your application.
191+
# In the case, you want to query records created from other application (such as EmotivPRO).
192+
# You need set license_id and application_id of the application
193+
# If set license_id without application_id. It will return records created from all applications use the license_id
194+
# If set both license_id and application_id. It will return records from the application has the application_id
195+
r.license_id = ''
196+
r.application_id = ''
189197

190198
r.start()
191199

0 commit comments

Comments
 (0)