Top Donators / Total

This commit is contained in:
2023-11-18 14:30:34 +01:00
parent ed60cfd72a
commit b8117e07c5
17 changed files with 201 additions and 22 deletions

View File

@@ -8,8 +8,39 @@ class CustomJSONProvider(DefaultJSONProvider):
def default(obj) -> dict :
if isinstance(obj,Payment):
return obj.to_json()
if isinstance(obj,Donator):
return obj.to_json()
return DefaultJSONProvider.default(obj)
class Donator(json.JSONEncoder):
name : str
amount : float
@staticmethod
def top_donator(conn: Connection):
cur = conn.cursor()
cur.execute("""select name, sum(amount) from orders
group by name
LIMIT 5
""")
data = cur.fetchall();
print(data);
if data is not None :
return [Donator(p[0],p[1]) for p in data]
else:
return None
def __init__(self,name,amount) -> None:
self.name = name
self.amount = float(amount/100)
def to_json(self) -> dict :
return { "name" : self.name,
"amount": self.amount
}
class Payment(json.JSONEncoder):
id : int
amount: float
@@ -46,6 +77,7 @@ class Payment(json.JSONEncoder):
return [Payment(p[0],p[1],p[2],p[3]) for p in data]
return None
def __repr__(self) -> str:
return '{} - {}€- {}'.format(self.name,self.amount/100,self.message)
def to_json(self) -> dict: