From f9f72c3c1ac402620948db6d89af7ec4cb3967b1 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 27 Apr 2020 15:33:31 +0200 Subject: [PATCH] publish: 5.7.8 --- pyproject.toml | 2 +- royalpack/stars/__init__.py | 2 ++ royalpack/stars/api_cvstats_latest.py | 21 +++++++++++++++++++++ royalpack/tables/cvstats.py | 13 +++++++++++++ royalpack/version.py | 2 +- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 royalpack/stars/api_cvstats_latest.py diff --git a/pyproject.toml b/pyproject.toml index 0e7a8fd1..7dafe867 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.7.7" + version = "5.7.8" description = "A Royalnet command pack for the Royal Games community" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalpack/stars/__init__.py b/royalpack/stars/__init__.py index db781e92..dc65f004 100644 --- a/royalpack/stars/__init__.py +++ b/royalpack/stars/__init__.py @@ -13,6 +13,7 @@ from .api_diario_random import ApiDiarioRandomStar from .api_polls_create import ApiPollsCreate from .api_polls_get import ApiPollsGet from .api_polls_list import ApiPollsList +from .api_cvstats_latest import ApiCvstatsLatestStar # Enter the PageStars of your Pack here! available_page_stars = [ @@ -30,6 +31,7 @@ available_page_stars = [ ApiPollsCreate, ApiPollsGet, ApiPollsList, + ApiCvstatsLatestStar, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/stars/api_cvstats_latest.py b/royalpack/stars/api_cvstats_latest.py new file mode 100644 index 00000000..a2530339 --- /dev/null +++ b/royalpack/stars/api_cvstats_latest.py @@ -0,0 +1,21 @@ +import royalnet.utils as ru +from royalnet.backpack.tables import * +from royalnet.constellation.api import * +from ..tables import Cvstats + + +class ApiCvstatsLatestStar(ApiStar): + path = "/api/cvstats/latest/v1" + + methods = ["GET"] + + summary = "Get the latest 500 cvstats." + + tags = ["cvstats"] + + async def api(self, data: ApiData) -> ru.JSON: + 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)) diff --git a/royalpack/tables/cvstats.py b/royalpack/tables/cvstats.py index f669347b..1165d3bc 100644 --- a/royalpack/tables/cvstats.py +++ b/royalpack/tables/cvstats.py @@ -45,3 +45,16 @@ class Cvstats: @declared_attr def users_total(self): return Column(Integer) + + def json(self): + return { + "timestamp": self.timestamp.isoformat(), + "users_total": self.users_total, + "members_total": self.members_total, + "users_online": self.users_online, + "members_online": self.members_online, + "users_connected": self.users_connected, + "members_connected": self.members_connected, + "users_playing": self.users_playing, + "members_playing": self.members_playing, + } \ No newline at end of file diff --git a/royalpack/version.py b/royalpack/version.py index 9728ff9b..7534cdb9 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.7.7" +semantic = "5.7.8"