diff --git a/server/src/uds/core/managers/stats.py b/server/src/uds/core/managers/stats.py index 11a259ec..30c1e615 100644 --- a/server/src/uds/core/managers/stats.py +++ b/server/src/uds/core/managers/stats.py @@ -103,7 +103,8 @@ class StatsManager: ownerIds: typing.Union[typing.Iterable[int], int], since: datetime.datetime, to: datetime.datetime, - max_intervals: int, + interval: typing.Optional[int], + max_intervals: typing.Optional[int], limit: typing.Optional[int], use_max: bool = False ) -> typing.Iterable: @@ -132,6 +133,7 @@ class StatsManager: owner_id=ownerIds, since=sinceInt, to=toInt, + interval=interval, max_intervals=max_intervals, limit=limit, use_max=use_max diff --git a/server/src/uds/core/util/config.py b/server/src/uds/core/util/config.py index 9a848f76..1cc2a575 100644 --- a/server/src/uds/core/util/config.py +++ b/server/src/uds/core/util/config.py @@ -77,7 +77,6 @@ class Config: self._default = cryptoManager().encrypt(default) self._data: typing.Optional[str] = None - def get(self, force: bool = False) -> str: # Ensures DB contains configuration values # From Django 1.7, DB can only be accessed AFTER all apps are initialized, curious at least.. :) diff --git a/server/src/uds/core/util/stats/counters.py b/server/src/uds/core/util/stats/counters.py index d16ac0c5..458bdb87 100644 --- a/server/src/uds/core/util/stats/counters.py +++ b/server/src/uds/core/util/stats/counters.py @@ -90,7 +90,6 @@ def getCounters(obj: typing.Any, counterType: int, **kwargs) -> typing.Generator """ since = kwargs.get('since') or NEVER to = kwargs.get('to') or datetime.datetime.now() - max_intervals = kwargs.get('max_intervals') or 1000 limit = kwargs.get('limit') use_max = kwargs.get('use_max', False) type_ = type(obj) @@ -112,7 +111,7 @@ def getCounters(obj: typing.Any, counterType: int, **kwargs) -> typing.Generator else: owner_ids = None - for i in statsManager().getCounters(__transDict[type(obj)], counterType, owner_ids, since, to, max_intervals, limit, use_max): + for i in statsManager().getCounters(__transDict[type(obj)], counterType, owner_ids, since, to, kwargs.get('interval'), kwargs.get('max_intervals'), limit, use_max): val = (datetime.datetime.fromtimestamp(i.stamp), i.value) yield val @@ -128,7 +127,7 @@ def _initializeData() -> None: Hides data from global var space """ - from uds.models import Provider, Service, ServicePool, Authenticator + from uds.models import Provider, Service, ServicePool, Authenticator # pylint: disable=import-outside-toplevel __caWrite.update({ CT_LOAD: (Provider,), diff --git a/server/src/uds/models/stats_counters.py b/server/src/uds/models/stats_counters.py index a08d834e..67245e0b 100644 --- a/server/src/uds/models/stats_counters.py +++ b/server/src/uds/models/stats_counters.py @@ -92,15 +92,15 @@ class StatsCounters(models.Model): since = int(since) if since else NEVER_UNIX to = int(to) if to else getSqlDatetimeAsUnix() - interval = 600 # By default, group items in ten minutes interval (600 seconds) + interval = int(kwargs.get('interval') or '600') # By default, group items in ten minutes interval (600 seconds) - elements = kwargs.get('elements', 0) + max_intervals = kwargs.get('max_intervals') limit = kwargs.get('limit') - if elements: + if max_intervals: # Protect against division by "elements-1" a few lines below - elements = int(elements) if int(elements) > 1 else 2 + max_intervals = int(max_intervals) if int(max_intervals) > 1 else 2 if owner_id is None: q = StatsCounters.objects.filter(stamp__gte=since, stamp__lte=to) @@ -115,10 +115,10 @@ class StatsCounters(models.Model): else: q = q.filter(owner_type=owner_type) - if q.count() > elements: + if q.count() > max_intervals: first = q.order_by('stamp')[0].stamp last = q.order_by('stamp').reverse()[0].stamp - interval = int((last - first) / (elements - 1)) + interval = int((last - first) / (max_intervals - 1)) stampValue = '{ceil}(stamp/{interval})'.format(ceil=getSqlFnc('CEIL'), interval=interval) filt += ' AND stamp>={since} AND stamp<={to} GROUP BY {stampValue} ORDER BY stamp'.format(