Commit 12b7bdeb authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

List works with merged events.

parent ced9b314
......@@ -76,10 +76,10 @@ def get_value(row, tablename, fieldname, keyname='', **kwargs):
when tablename and fieldname are defined
- C{row[tablename][fieldname][keyname]} for JSON type field
- C{kwargs[tablename]} when fieldname and keyname are not defined
- empty string
- None when the field address does not exist in the row
"""
undefined = ""
undefined = None
# force value
if tablename and (not fieldname) and (tablename in kwargs):
......@@ -96,8 +96,8 @@ def get_value(row, tablename, fieldname, keyname='', **kwargs):
else:
return undefined
# deal with the keyname
# it has been design for JSON-type field containing a dictionary
# deal with the keyname
# it has been design for JSON-type field containing a dictionary
if not keyname:
return value
......@@ -495,6 +495,56 @@ class List(BaseReport):
column.dataIndex = column.dbfield.replace('.', '')
def _cast_to_xtype(self, column, xtype):
"""Cast the type of a dataframe column to the column xtype.
The type of the column determine by the pandas might be wrong.
This append when value are undefined or missing.
This is fine in most of the case but not wiht computed column.
In that scase the eval computation crashed.
This method avoid this problem.
@type column: str
@param column: the index of the column in the DataFrame
@type xtype: str
@param xtype: the xtype of the grid column.
Possible values are 'booleancolumn, datecolumn, gridcolumn
and numbercolumn.
"""
df = self.df
if df[column].dtype == 'object' and xtype != None:
if xtype in ('datecolumn', 'gridcolumn'):
return
elif xtype == 'booleancolumn':
df[column] = df[column].astype('bool')
elif xtype == 'numbercolumn':
df[column] = df[column].astype('float64')
def _convert(self, value):
"""Encode date and timedelta with a define format.
It will then exploit in the grid.
"""
# encode date
if isinstance(value, date):
value = value.strftime("%Y-%m-%d")
# encode time delta
elif isinstance(value, timedelta):
value = value.total_seconds()
return value
def _do_metric(self):
"""Interface the database with the DataFrame structure.
This method handle the "year" database field.
......@@ -502,23 +552,33 @@ class List(BaseReport):
"""
columns = self._columns
# extract columns associated to database fields
maps, index, xtypes = [], [], []
for column in columns:
if column.dbfield:
maps.append(column.map)
index.append(column.dataIndex)
xtypes.append(column.xtype)
# extract data from the database
maps = [el.map for el in columns if el.dbfield]
index = [el.dataIndex for el in columns if el.dbfield]
data = self._do_data(maps)
# protection
if not data:
index = [el.dataIndex for el in columns if el.dataIndex]
self.df = pd.DataFrame(columns=index)
return
# fill the DataFrame
df = pd.DataFrame(data, columns=index)
# make the data frame persistent
self.df = df
# cast dataframe column type to grid column xtype
map(self._cast_to_xtype, index, xtypes)
# add the computed column
# add computed columns
for el in columns:
if el.eval:
df[el.dataIndex] = df.eval(el.eval)
......@@ -528,26 +588,7 @@ class List(BaseReport):
index = [el.dataIndex for el in columns if el.dataIndex]
df = df[index]
# make the data frame persistent
self.df = df
def _convert(self, value):
"""Encode date and timedelta with a define format.
It will then exploit in the grid.
"""
# encode date
if isinstance(value, date):
value = value.strftime("%Y-%m-%d")
# encode time delta
elif isinstance(value, timedelta):
value = value.total_seconds()
return value
def _set_store_data(self):
""" Generate the C{Ext.data.Store.data} property.
It is a list of dictionaries. Each of them contains the data
......
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