Browse Source

[IMP] add 'median' function;

pull/111/head
Sylvain LE GAL 10 years ago
parent
commit
cff4997c51
  1. 2
      web_dashboard_tile/__openerp__.py
  2. BIN
      web_dashboard_tile/static/src/img/avg.png
  3. BIN
      web_dashboard_tile/static/src/img/median.png
  4. 15
      web_dashboard_tile/tile.py

2
web_dashboard_tile/__openerp__.py

@ -47,7 +47,7 @@ and add them as short cut.
the current user doesn't have access to the given model); the current user doesn't have access to the given model);
* The tile displays items count of a given model restricted to a given domain; * The tile displays items count of a given model restricted to a given domain;
* Optionnaly, the tile can display the result of a function of a field; * Optionnaly, the tile can display the result of a function of a field;
* Function is one of sum/avg/min/max;
* Function is one of sum/avg/min/max/median;
* Field must be integer or float; * Field must be integer or float;
Screenshot: Screenshot:

BIN
web_dashboard_tile/static/src/img/avg.png

Before

Width: 24  |  Height: 24  |  Size: 287 B

After

Width: 24  |  Height: 24  |  Size: 340 B

BIN
web_dashboard_tile/static/src/img/median.png

After

Width: 24  |  Height: 24  |  Size: 287 B

15
web_dashboard_tile/tile.py

@ -31,6 +31,14 @@ class tile(orm.Model):
_name = 'tile.tile' _name = 'tile.tile'
_order = 'sequence, name' _order = 'sequence, name'
def median(self, aList):
# https://docs.python.org/3/library/statistics.html#statistics.median
# TODO : refactor, using statistics.median when Odoo will be available
# in Python 3.4
even = (0 if len(aList) % 2 else 1) + 1
half = (len(aList) - 1) / 2
return sum(sorted(aList)[half:half + even]) / float(even)
def _get_tile_info(self, cr, uid, ids, fields, args, context=None): def _get_tile_info(self, cr, uid, ids, fields, args, context=None):
ima_obj = self.pool['ir.model.access'] ima_obj = self.pool['ir.model.access']
res = {} res = {}
@ -72,6 +80,9 @@ class tile(orm.Model):
elif r.field_function == 'avg': elif r.field_function == 'avg':
value = sum(vals) / len(vals) value = sum(vals) / len(vals)
helper = _("Average value of '%s'" % desc) helper = _("Average value of '%s'" % desc)
elif r.field_function == 'median':
value = self.median(vals)
helper = _("Median value of '%s'" % desc)
res[r.id].update({ res[r.id].update({
'computed_value': value, 'computed_value': value,
'helper': helper, 'helper': helper,
@ -111,7 +122,9 @@ class tile(orm.Model):
('min', 'Minimum'), ('min', 'Minimum'),
('max', 'Maximum'), ('max', 'Maximum'),
('sum', 'Sum'), ('sum', 'Sum'),
('avg', 'Average')], 'Function'),
('avg', 'Average'),
('median', 'Median'),
], 'Function'),
'field_id': fields.many2one( 'field_id': fields.many2one(
'ir.model.fields', 'Field', 'ir.model.fields', 'Field',
domain="[('model_id', '=', model_id)," domain="[('model_id', '=', model_id),"

Loading…
Cancel
Save