Newer
Older
from pint import UnitRegistry
from datetime import datetime, timedelta
def __init__(self, pk: bytes, p: float, ppw: float, extime: datetime):
self.ureg = None
self.Q_ = None
self.pubicKey: bytes = pk
self.timestamp: int = time.time_ns()
self.executiontime: datetime = extime
self.power = p
self.pricePerWatt = ppw # this is in EUR, no new cryptocurrency should be created for this
def set_ureg(self, ureg: UnitRegistry) -> None:
self.ureg = ureg
self.Q_ = ureg.Quantity
self.power = self.Q_(self.power, ureg.watt)
def activate(self) -> None:
self.__isActive = True
def getActive(self) -> bool:
return self.__isActive
def is_min_now(self) -> bool:
now = datetime.now()
# Calculate the first second of the current minute
start_of_minute = datetime(now.year, now.month, now.day, now.hour, now.minute, 0)
start_of_minute_unix = int(start_of_minute.timestamp())
# Calculate the last second of the current minute
end_of_minute = start_of_minute + timedelta(seconds=59)
end_of_minute_unix = int(end_of_minute.timestamp())
if start_of_minute_unix <= self.executiontime.timestamp() <= end_of_minute_unix:
return True
else:
return False
def is_min_next(self) -> bool:
now = datetime.now()
# Calculate the first second of the next minute
start_of_minute = datetime(now.year, now.month, now.day, now.hour, now.minute, 0)
start_of_minute += timedelta(minutes=1)
start_of_minute_unix = int(start_of_minute.timestamp())
# Calculate the last second of the next minute
end_of_minute = start_of_minute + timedelta(seconds=59)
end_of_minute_unix = int(end_of_minute.timestamp())
if start_of_minute_unix <= self.executiontime.timestamp() <= end_of_minute_unix:
return False
def is_old(self) -> bool:
now = datetime.now()
return self.executiontime.timestamp() < int(now.timestamp())