49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
from dataclasses import dataclass, fields
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
@dataclass
|
|
class Strategy():
|
|
id: str
|
|
createdAt: str
|
|
enabled: bool
|
|
fulfilled: bool
|
|
|
|
@classmethod
|
|
def get_table_name(cls):
|
|
return cls.__name__
|
|
|
|
@classmethod
|
|
def get_route_prefix(cls):
|
|
return "/strategies/" + cls.__name__.lower()
|
|
|
|
@classmethod
|
|
def get_template_prefix(cls):
|
|
return "/strategies"
|
|
|
|
@staticmethod
|
|
def get_computed_properties():
|
|
return ["id", "createdAt"]
|
|
|
|
@staticmethod
|
|
def compute_properties():
|
|
return {
|
|
"createdAt": datetime.utcnow().isoformat() + "Z"
|
|
}
|
|
|
|
@classmethod
|
|
def get_order(cls):
|
|
return [field.name for field in fields(cls)]
|
|
|
|
@classmethod
|
|
def format(cls, fields):
|
|
for key, value in fields.items():
|
|
if key in cls.get_formatters():
|
|
fields[key] = cls.get_formatters()[key](value)
|
|
return fields
|
|
|
|
@staticmethod
|
|
def get_formatters():
|
|
return {
|
|
"createdAt": lambda str: datetime.fromisoformat(str).strftime('%Y-%m-%d %H:%M')
|
|
} |