|
9 | 9 | import http |
10 | 10 | import typing |
11 | 11 |
|
| 12 | +from pydantic import BaseModel |
| 13 | +import pydantic |
| 14 | + |
12 | 15 | from .base import SimvueObject |
13 | 16 | from simvue.api.request import get as sv_get, get_json_from_response |
14 | 17 | from simvue.api.url import URL |
15 | 18 |
|
16 | 19 | __all__ = ["Stats"] |
17 | 20 |
|
18 | 21 |
|
| 22 | +class UserStatistics(BaseModel): |
| 23 | + """Interface to per-user statistics output.""" |
| 24 | + |
| 25 | + runs: pydantic.NonNegativeInt |
| 26 | + alerts: pydantic.NonNegativeInt |
| 27 | + tags: pydantic.NonNegativeInt |
| 28 | + files: pydantic.NonNegativeInt |
| 29 | + volume: pydantic.NonNegativeInt |
| 30 | + events: pydantic.NonNegativeInt |
| 31 | + metrics: pydantic.NonNegativeInt |
| 32 | + |
| 33 | + |
19 | 34 | class Stats(SimvueObject): |
20 | 35 | """Class for accessing Server statistics.""" |
21 | 36 |
|
| 37 | + _single: bool = True |
| 38 | + _tenant: str | None = None |
| 39 | + |
22 | 40 | def __init__(self) -> None: |
23 | 41 | """Initialise a statistics query object.""" |
24 | 42 | self.runs = RunStatistics(self) |
@@ -122,15 +140,23 @@ def _get_visibility(self) -> dict[str, bool | list[str]]: |
122 | 140 | return {} |
123 | 141 |
|
124 | 142 | def to_dict(self) -> dict[str, typing.Any]: |
125 | | - """Dictionary form of statistics. |
| 143 | + """Dictionary form of current user statistics. |
126 | 144 |
|
127 | 145 | Returns |
128 | 146 | ------- |
129 | | - doct[str, Any] |
| 147 | + dict[str, Any] |
130 | 148 | statistics data as dictionary |
131 | 149 | """ |
132 | 150 | return {"runs": self._get_run_stats()} |
133 | 151 |
|
| 152 | + def admin_stats(self, *, tenant: str | None = None) -> dict[str, dict[str, int]]: |
| 153 | + return { |
| 154 | + name: UserStatistics(**entry) |
| 155 | + for name, entry in self._get( |
| 156 | + single=False, **({"tenant": tenant} if tenant else {}) |
| 157 | + ).items() |
| 158 | + } |
| 159 | + |
134 | 160 | def commit(self) -> None: |
135 | 161 | """Does nothing, no data sendable to server.""" |
136 | 162 | pass |
|
0 commit comments