diff --git a/server/src/uds/migrations/0043_auto_20220704_2120.py b/server/src/uds/migrations/0043_auto_20220704_2120.py index b79df815a..fb8407398 100644 --- a/server/src/uds/migrations/0043_auto_20220704_2120.py +++ b/server/src/uds/migrations/0043_auto_20220704_2120.py @@ -2,6 +2,7 @@ from django.db import migrations, models import django.db.models.deletion +import uds.models.stats_counters class Migration(migrations.Migration): @@ -38,6 +39,11 @@ class Migration(migrations.Migration): name='mfa', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='authenticators', to='uds.mfa'), ), + migrations.AddField( + model_name='statscounters', + name='interval_type', + field=models.SmallIntegerField(db_index=True, default=uds.models.stats_counters.StatsCounters.CounterIntervalType['NONE']), + ), migrations.RemoveIndex( model_name='statscounters', name='uds_stats_c_owner_t_db894d_idx', diff --git a/server/src/uds/models/stats_counters.py b/server/src/uds/models/stats_counters.py index 5ac9493f4..4174c64b8 100644 --- a/server/src/uds/models/stats_counters.py +++ b/server/src/uds/models/stats_counters.py @@ -31,7 +31,7 @@ .. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com """ import typing -import types +import enum import datetime import logging @@ -49,11 +49,19 @@ class StatsCounters(models.Model): """ Statistics about counters (number of users at a given time, number of services at a time, whatever...) """ + # Valid intervals types for counters data + class CounterIntervalType(enum.IntEnum): + NONE = 0 + MINUTE = 1 + HOUR = 2 + DAY = 3 + WEEK = 4 owner_id = models.IntegerField(db_index=True, default=0) owner_type = models.SmallIntegerField(db_index=True, default=0) counter_type = models.SmallIntegerField(db_index=True, default=0) stamp = models.IntegerField(db_index=True, default=0) + interval_type = models.SmallIntegerField(db_index=True, default=CounterIntervalType.NONE) value = models.IntegerField(db_index=True, default=0) # "fake" declarations for type checking