Commit 7f813071 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Klaus Wölfel

add array preview listbox to Data Array View

The listbox shows lines for all indexes in the first dimension of the ndarray and up to 100 columns for the second dimension.
parent 61f518e3
...@@ -88,6 +88,14 @@ class DataArray(BigFile): ...@@ -88,6 +88,14 @@ class DataArray(BigFile):
""" """
return self.getArray()[start:end] return self.getArray()[start:end]
def getArrayIndex(self, index):
"""
Implement array indexing in its most simple list alike form.
Any other advanced indexing techniques currently possible by getting
array reference directly.
"""
return self.getArray()[index]
security.declareProtected(Permissions.AccessContentsInformation, 'getSize') security.declareProtected(Permissions.AccessContentsInformation, 'getSize')
def getSize(self): def getSize(self):
""" """
...@@ -95,6 +103,13 @@ class DataArray(BigFile): ...@@ -95,6 +103,13 @@ class DataArray(BigFile):
""" """
return self.getArray().nbytes return self.getArray().nbytes
security.declareProtected(Permissions.AccessContentsInformation, 'getArrayShape')
def getArrayShape(self):
"""
Get numpy array shape-
"""
return self.getArray().shape
security.declareProtected(Permissions.View, 'index_html') security.declareProtected(Permissions.View, 'index_html')
def index_html(self, REQUEST, RESPONSE, format=_MARKER, inline=_MARKER, **kw): def index_html(self, REQUEST, RESPONSE, format=_MARKER, inline=_MARKER, **kw):
""" """
......
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W: 99, 42: Redefining built-in \'format\' (redefined-builtin)</string> <string>W:114, 42: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:116, 4: Redefining built-in \'range\' (redefined-builtin)</string> <string>W:131, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:143, 10: No exception type(s) specified (bare-except)</string> <string>W:158, 10: No exception type(s) specified (bare-except)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
<?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>_body</string> </key>
<value> <string># return columns from shape of axis 1 of ndarray\n
# never return more than the first 100 columns\n
array = context.getArray()\n
\n
if array is None:\n
return []\n
\n
else:\n
return [(\'index\', \'Index\')] + [(str(i), str(i)) for i in range(min(context.getArrayShape()[1], 100))]\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>DataArray_getArrayColumnList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from Products.ERP5Type.Document import newTempBase\n
\n
if context.getArray() is None:\n
return []\n
\n
class SequenceSliceMap():\n
def __init__(self, sequence_slice, usual_slice_length, total_length):\n
self.sequence_slice = sequence_slice\n
self.length = usual_slice_length\n
self.total_length = total_length\n
\n
def __repr__(self):\n
return repr(list(self))\n
\n
def __len__(self):\n
return self.total_length\n
\n
def __getitem__(self, index):\n
return self.sequence_slice[index % self.length]\n
\n
def createTempBase(nr, row):\n
column_iterator = enumerate([col for col in context.DataArray_getArrayColumnList() if col[0] != \'index\'])\n
return newTempBase(context.getPortalObject(),\n
str(id(row)),\n
index = nr,\n
**{col[0]: str(row[i]) for i, col in column_iterator})\n
\n
\n
length = context.getArrayShape()[0]\n
\n
# never access more than 1000 lines at once\n
list_lines = min(list_lines, limit, 1000)\n
list_end = list_start + list_lines\n
\n
if list_end > length:\n
list_end = length\n
list_start = list_end - (list_end % list_lines)\n
\n
if list_start == list_end:\n
array_slice = [context.getArrayIndex(list_start)]\n
else:\n
array_slice = context.getArraySlice(list_start, list_end)\n
\n
temp_base_list = [createTempBase(nr + list_start, row) for nr, row in enumerate(array_slice)]\n
\n
# return lazy sequence of temp objects\n
return SequenceSliceMap(temp_base_list, list_lines, length)\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>list_start=0, list_lines=15, limit=1000, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>DataArray_getArrayRowList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -53,7 +53,9 @@ ...@@ -53,7 +53,9 @@
<item> <item>
<key> <string>bottom</string> </key> <key> <string>bottom</string> </key>
<value> <value>
<list/> <list>
<string>listbox</string>
</list>
</value> </value>
</item> </item>
<item> <item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>columns</string>
<string>list_method</string>
<string>title</string>
<string>url_columns</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>columns</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>list_method</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>url_columns</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>columns</string> </key>
<value>
<list>
<tuple>
<string>title</string>
<string>title</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_view_mode_listbox</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>list_method</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Preview</string> </value>
</item>
<item>
<key> <string>url_columns</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.DataArray_getArrayColumnList()</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(col[0], None) for col in here.DataArray_getArrayColumnList()]</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="Method" module="Products.Formulator.MethodField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>method_name</string> </key>
<value> <string>DataArray_getArrayRowList</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