class Metric(object): def __init__(self, id, context, type, info=None, values=None): context = context.copy() context['id'] = id context['type'] = type self.context = context self.info = info self.values = ValueSet(context['type']) if values is not None: self.add_values(values) @property def id(self): return self.context['id'] @property def type(self): return self.context['type'] def add_value(self, raw_value, info=None): self.values.append(Value(raw_value, info)) def add_values(self, values): for raw_value, info in values: self.add_value(raw_value, info) def __str__(self): return self.__unicode__().encode('utf-8') def __unicode__(self): return self.__repr__() def __repr__(self): return u'<Metric id={} context={} info={} values=[{}]>'.format(self.id, self.context, self.info, self.values) def serialize(self): return { 'context': self.context, 'info': self.info, 'values': [ value.serialize() for value in self.values ] } @staticmethod def unserialize(data): return Metric( data['context']['id'], data['context'], data['context']['type'], data['info'], [ (value_data['value'], value_data['info']) for value_data in data['values'] ])
def __init__(self, id, context, type, info=None, values=None): context = context.copy() context['id'] = id context['type'] = type self.context = context self.info = info self.values = ValueSet(context['type']) if values is not None: self.add_values(values)