|
@ -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)," |
|
|