1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/royalpack/stars/api_cvstats_latest.py

19 lines
524 B
Python
Raw Normal View History

2020-04-27 13:33:31 +00:00
import royalnet.utils as ru
2020-06-26 14:13:11 +00:00
import royalnet.constellation.api as rca
2020-04-27 13:33:31 +00:00
from ..tables import Cvstats
2020-06-26 14:13:11 +00:00
class ApiCvstatsLatestStar(rca.ApiStar):
2020-04-27 13:33:31 +00:00
path = "/api/cvstats/latest/v1"
tags = ["cvstats"]
2020-06-26 14:13:11 +00:00
@rca.magic
async def get(self, data: rca.ApiData) -> ru.JSON:
2020-06-22 17:27:11 +00:00
"""Get the latest 500 cvstats recorded."""
2020-04-27 13:33:31 +00:00
CvstatsT = self.alchemy.get(Cvstats)
cvstats = data.session.query(CvstatsT).order_by(CvstatsT.timestamp.desc()).limit(500).all()
return list(map(lambda c: c.json(), cvstats))