0ptr/nullptr/models/survey.py

51 lines
1.3 KiB
Python
Raw Normal View History

2023-06-17 18:18:14 +00:00
from time import time
from nullptr.util import *
2023-07-10 17:25:01 +00:00
from .base import Base
2023-06-17 18:18:14 +00:00
size_names = ['SMALL','MODERATE','LARGE']
2023-07-10 17:25:01 +00:00
class Survey(Base):
2023-06-17 18:18:14 +00:00
identifier = 'signature'
def define(self):
self.type: str = ''
self.deposits: list[str] = []
self.size: int = 0
self.expires: int = 0
self.expires_str: str = ''
self.exhausted: bool = False
2023-06-17 18:18:14 +00:00
@classmethod
def ext(cls):
return 'svy'
2023-06-17 18:18:14 +00:00
def is_expired(self):
return time() > self.expires or self.exhausted
def waypoint(self):
p = self.symbol.split('-')
return '-'.join(p[:3])
2023-06-17 18:18:14 +00:00
def api_dict(self):
return {
'signature': self.symbol,
'symbol': self.waypoint(),
2023-06-17 18:18:14 +00:00
'deposits': [{'symbol': d} for d in self.deposits],
'expiration': self.expires_str,
'size': size_names[self.size]
}
def update(self, d):
sz = must_get(d, 'size')
self.size = size_names.index(sz)
self.deposits = [d['symbol'] for d in must_get(d, 'deposits')]
self.seta('expires',d, 'expiration',parse_timestamp)
self.seta('expires_str',d, 'expiration')
def f(self, detail=1):
result = self.symbol
if detail > 1:
result += ' ' + ','.join(self.deposits)
minutes = max(self.expires - time(), 0) //60
result += ' ' + str(int(minutes)) + 'm'
return result