1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2025-02-17 10:53:57 +00:00
royalnet/utils/dirty.py

33 lines
769 B
Python
Raw Normal View History

2018-12-18 17:34:34 +01:00
class Dirty:
def __init__(self, initial_value):
self.initial_value = initial_value
self.value = initial_value
def is_clean(self):
return self.initial_value == self.value
def is_dirty(self):
return not self.is_clean()
def __bool__(self):
return self.is_dirty()
2019-01-23 15:00:30 +01:00
class DirtyDelta(Dirty):
@property
def delta(self):
2019-03-01 17:45:23 +01:00
if self.initial_value is None:
initial_value = 0
else:
initial_value = self.initial_value
if self.value is None:
value = 0
else:
value = self.value
2019-03-05 10:03:43 +01:00
return abs(value - initial_value)
2019-01-23 15:00:30 +01:00
2019-03-05 10:03:43 +01:00
def delta_string(self):
if self.delta > 0:
return f"+{self.delta}"
return self.delta