Commit 5bc0c5c8 authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_ingestion: processed metadata in data descriptors

parent 2b3c5251
import os
import mne
import json
from DateTime import DateTime
from Products.ERP5Type.Log import log
from mne.report import Report
from mne import read_evokeds
def getHTMLReport(file_name, raw):
try:
pattern = file_name + "_raw.fif"
report_file = file_name + 'report.html'
report = Report(verbose=True)
report.parse_folder(data_path="./", pattern=[pattern])
report.save(report_file, overwrite=True, open_browser=False)
with open(report_file, 'r') as report:
content = report.read()
os.remove(report_file)
return content
except Exception as e:
return str(e)
def getJSONMetadata(raw_info):
info = { 'filename': 'FILENAME', #raw_info['filename'],
......@@ -12,17 +29,20 @@ def getJSONMetadata(raw_info):
return json.dumps(info)
def processRawData(data_stream, data_array, data_descriptor):
file_name = "temporal_file_%s" % DateTime().strftime('%Y%m%d-%H%M%S')
try:
data_stream_content = data_stream.getData()
raw_file = "ernoise_raw.fif"
raw_file = file_name + "_raw.fif"
with open(raw_file, 'wb') as fif_file:
fif_file.write(data_stream_content)
raw = mne.io.read_raw_fif(raw_file, preload=True)
json_metadata = getJSONMetadata(raw.info)
html_report = getHTMLReport(file_name, raw)
data_descriptor.setTextContent(json_metadata)
log("Data Descriptor metadata: " + str(data_descriptor.getTextContent()))
data_descriptor.setTextContent(html_report)
#log("Data Descriptor metadata: " + str(data_descriptor.getTextContent()))
data_array.setArray(raw._data)
log("Data Array array: " + str(data_array.getArray()))
#log("Data Array array: " + str(data_array.getArray()))
os.remove(raw_file)
return "Raw data processed."
except Exception, e:
......
......@@ -51,7 +51,10 @@
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
<tuple>
<string>W: 5, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string>
<string>W: 7, 0: Unused read_evokeds imported from mne (unused-import)</string>
</tuple>
</value>
</item>
<item>
......
from Products.ERP5Type.Log import log
from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
kw_dict = {"portal_type": "Data Descriptor"}
content = None
for document in portal_catalog(**kw_dict):
if document.reference == reference:
found = True
content = document.getTextContent()
if content is not None:
return content
else:
return "No metadata available for this type of file yet"
if content is None:
return "Data descriptor not found"
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>reference</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>getDescriptorHTMLContent</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment