Fix interval comparisons for Python 3
This commit is contained in:
parent
1928caa1d7
commit
5da7e6558e
|
@ -60,11 +60,19 @@ cdef class Interval:
|
|||
return ("[" + timestamp_to_string(self.start) +
|
||||
" -> " + timestamp_to_string(self.end) + ")")
|
||||
|
||||
def __cmp__(self, Interval other):
|
||||
"""Compare two intervals. If non-equal, order by start then end"""
|
||||
def cmp(a, b):
|
||||
return (a > b) - (a < b)
|
||||
return cmp(self.start, other.start) or cmp(self.end, other.end)
|
||||
# Compare two intervals. If non-equal, order by start then end
|
||||
def __lt__(self, Interval other):
|
||||
return (self.start, self.end) < (other.start, other.end)
|
||||
def __gt__(self, Interval other):
|
||||
return (self.start, self.end) > (other.start, other.end)
|
||||
def __le__(self, Interval other):
|
||||
return (self.start, self.end) <= (other.start, other.end)
|
||||
def __le__(self, Interval other):
|
||||
return (self.start, self.end) >= (other.start, other.end)
|
||||
def __eq__(self, Interval other):
|
||||
return (self.start, self.end) == (other.start, other.end)
|
||||
def __ne__(self, Interval other):
|
||||
return (self.start, self.end) != (other.start, other.end)
|
||||
|
||||
cpdef intersects(self, Interval other):
|
||||
"""Return True if two Interval objects intersect"""
|
||||
|
|
|
@ -39,9 +39,19 @@ class Interval:
|
|||
return ("[ " + nilmdb.utils.time.timestamp_to_human(self.start) +
|
||||
" -> " + nilmdb.utils.time.timestamp_to_human(self.end) + " ]")
|
||||
|
||||
def __cmp__(self, other):
|
||||
"""Compare two intervals. If non-equal, order by start then end"""
|
||||
return cmp(self.start, other.start) or cmp(self.end, other.end)
|
||||
# Compare two intervals. If non-equal, order by start then end
|
||||
def __lt__(self, other):
|
||||
return (self.start, self.end) < (other.start, other.end)
|
||||
def __gt__(self, other):
|
||||
return (self.start, self.end) > (other.start, other.end)
|
||||
def __le__(self, other):
|
||||
return (self.start, self.end) <= (other.start, other.end)
|
||||
def __le__(self, other):
|
||||
return (self.start, self.end) >= (other.start, other.end)
|
||||
def __eq__(self, other):
|
||||
return (self.start, self.end) == (other.start, other.end)
|
||||
def __ne__(self, other):
|
||||
return (self.start, self.end) != (other.start, other.end)
|
||||
|
||||
def intersects(self, other):
|
||||
"""Return True if two Interval objects intersect"""
|
||||
|
|
|
@ -428,4 +428,6 @@ class TestIntervalSpeed:
|
|||
speed / (j*math.log(j))) # should be constant
|
||||
speeds[j] = speed
|
||||
yappi.stop()
|
||||
yappi.print_stats(sort_type=yappi.SORTTYPE_TTOT, limit=10)
|
||||
stats = yappi.get_func_stats()
|
||||
stats.sort("ttot")
|
||||
stats.print_all()
|
||||
|
|
Loading…
Reference in New Issue
Block a user