def humanize_attrs(cls, obj): humanized_attrs = {} for attr in cls.DATETIME_ATTRIBUTES: humanized_attrs[attr] = humanize_timesince(getattr(obj, attr)) for attr in cls.PERCENT_ATTRIBUTES: humanized_attrs[attr] = to_percentage(getattr(obj, attr), cls.ROUNDING) for attr in cls.MEM_SIZE_ATTRIBUTES: humanized_attrs[attr] = to_unit_memory(getattr(obj, attr)) return humanized_attrs
def humanize_attrs(key, value, rounding=2): if key in [ "created_at", "updated_at", "started_at", "finished_at", "last_update_time", "last_transition_time", ]: return humanize_timesince(value) if key in ["cpu_percentage"]: return to_percentage(value, rounding) if key in ["memory_free", "memory_used", "memory_total"]: return to_unit_memory(value) return value