1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/utils/dirty.py

38 lines
862 B
Python
Raw Normal View History

2018-12-18 16:34:34 +00: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 14:00:30 +00:00
class DirtyDelta(Dirty):
2019-03-07 17:14:10 +00:00
2019-01-23 14:00:30 +00:00
@property
2019-03-07 17:14:10 +00:00
def difference(self):
2019-03-01 16:45:23 +00: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-07 17:14:10 +00:00
return value - initial_value
@property
def delta(self):
return abs(self.difference)
2019-01-23 14:00:30 +00:00
2019-03-07 17:14:10 +00:00
def difference_string(self):
if self.difference > 0:
return f"+{self.difference}"
return self.difference