numrange.py 943 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. # Range for numeric type
  3. class NumRange(object):
  4. """Class for Generalization hierarchies (Taxonomy Tree).
  5. Store numeric node in instances.
  6. self.sort_value: sorted values, which may help get the normalized width
  7. self.value: node value, e.g. '10,20'
  8. self.support: support (frequency) of all values, dict
  9. self.range: (max-min), used for normalized width
  10. self.cover: leaves nodes of current node
  11. """
  12. def __init__(self, sort_value, support):
  13. self.sort_value = list(sort_value)
  14. self.support = support.copy()
  15. # sometimes the values may be str
  16. self.range = float(sort_value[-1]) - float(sort_value[0])
  17. self.dict = {}
  18. for i, v in enumerate(sort_value):
  19. self.dict[v] = i
  20. self.value = sort_value[0] + ',' + sort_value[-1]
  21. def __len__(self):
  22. """
  23. return |max-min|
  24. """
  25. return self.range