Commit 9a014435 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Coherent processing of datetime using ISO 8601.

parent 12b7bdeb
......@@ -501,10 +501,11 @@ class List(BaseReport):
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 is fine in most of the case but not with computed column.
In that case the eval computation crashed.
This method avoid this problem.
This method avoid this problem. It also convert properly
datetime column allowing computation with them.
@type column: str
@param column: the index of the column in the DataFrame
......@@ -519,32 +520,19 @@ class List(BaseReport):
if df[column].dtype == 'object' and xtype != None:
if xtype in ('datecolumn', 'gridcolumn'):
if xtype == 'gridcolumn':
return
elif xtype == 'booleancolumn':
df[column] = df[column].astype('bool')
elif xtype == 'datecolumn':
df[column] = pd.to_datetime(df[column])
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.
......@@ -571,7 +559,7 @@ class List(BaseReport):
# fill the DataFrame
df = pd.DataFrame(data, columns=index)
# make the data frame persistent
self.df = df
......@@ -596,10 +584,13 @@ class List(BaseReport):
the key is the name of the C{Ext.data.Field}.
"""
store = self._store
for row in self.df.T.to_dict().itervalues():
store.data.append(row)
# extract the list of records as a JSON-string
# at this stage date/time are converted as an ISO8601 string
data = self.df.to_json(orient='records', date_format='iso')
# convert the JSON-string into a list
self._store.data = json.loads(data)
def _set_store_fields(self):
""" Generate the C{Ext.data.Store.fields} property.
......@@ -641,24 +632,16 @@ class List(BaseReport):
if dbfield.type in ('string', 'text', 'json'):
cfg.type = 'string'
elif dbfield.type == 'date':
elif dbfield.type in ('date', 'datetime', 'time'):
cfg.type = 'date'
cfg.dateFormat = 'Y-m-d'
elif dbfield.type == 'datetime':
cfg.type = 'date'
cfg.dateFormat = 'Y-m-d H:i:s'
cfg.dateFormat = 'c'
elif dbfield.type == 'double':
cfg.type = 'float'
elif dbfield.type == 'integer':
cfg.type = 'int'
elif dbfield.type == 'time':
cfg.type = 'date'
cfg.dateFormat = 'H:i:s'
store.fields.append(cfg)
......
/**
* Convert a duration in second into a string.
* Convert a duration in nanosecond into a string.
*
* @param {Number} value
* The duration in seconds
* The duration in nanoseconds
*
* @return {String}
* The duration express as the number of year + the number of months e.g. "3y + 09m"
......@@ -12,22 +12,36 @@ function reprDuration(value) {
"use strict";
var nmonths = 0,
nyears = 0,
year = 365 * 24 * 3600,
month = year / 12;
var duration = value / 1.E9,
month,
nd,
nm,
ny,
rep,
year;
nyears = Math.floor(value / year);
// duration of year and month in seconds
year = 365 * 24 * 3600;
month = year / 12;
nmonths = Math.floor((value - nyears * year) / month);
nmonths = Ext.String.leftPad(nmonths.toString(), 2, '0');
// number of years and months
ny = Math.floor(duration / year);
nm = Math.floor((duration - ny * year) / month);
if (nyears > 0) {
return Ext.String.format("{0}y + {1}m", nyears, nmonths);
// format the number of month
nm = Ext.String.leftPad(nm.toString(), 2, '0');
} else if (nmonths > 0) {
return Ext.String.format("{0}m", nmonths);
// format the response
if (ny > 0) {
rep = Ext.String.format("{0}y + {1}m", ny, nm);
} else if (nm > 0) {
rep = Ext.String.format("{0}m", nm);
} else {
nd = duration / (24 * 3600);
rep = Ext.String.leftPad(nd.toString(), 2, '0');
}
return "";
return rep;
}
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