51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from time import time
|
|
from nullptr.util import *
|
|
from .base import Base
|
|
|
|
size_names = ['SMALL','MODERATE','LARGE']
|
|
|
|
class Survey(Base):
|
|
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
|
|
|
|
@classmethod
|
|
def ext(cls):
|
|
return 'svy'
|
|
|
|
def is_expired(self):
|
|
return time() > self.expires or self.exhausted
|
|
|
|
def waypoint(self):
|
|
p = self.symbol.split('-')
|
|
return '-'.join(p[:3])
|
|
|
|
def api_dict(self):
|
|
return {
|
|
'signature': self.symbol,
|
|
'symbol': self.waypoint,
|
|
'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
|