'Evaluate the expression and return a new sample if successful.'

def _calculate(self, resource_id):

    ns_dict = dict(((m, s.as_dict()) for (m, s) in six.iteritems(self.cache[resource_id])))
    ns = transformer.Namespace(ns_dict)
    try:
        new_volume = eval(self.expr_escaped, {}, ns)
        if math.isnan(new_volume):
            raise ArithmeticError(_('Expression    evaluated    to    a    NaN    value!'))
        reference_sample = self.cache[resource_id][self.reference_meter]
        return sample.Sample(name=self.target.get('name', reference_sample.name), unit=self.target.get('unit', reference_sample.unit), type=self.target.get('type', reference_sample.type), volume=float(new_volume), user_id=reference_sample.user_id, project_id=reference_sample.project_id, resource_id=reference_sample.resource_id, timestamp=self.latest_timestamp, resource_metadata=reference_sample.resource_metadata)
    except Exception as e:
        LOG.warning(_('Unable    to    evaluate    expression    %(expr)s:    %(exc)s'), {'expr': self.expr, 'exc': e})
