mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
analytics: Include interval in COUNT_STATS property names.
This commit is contained in:
@@ -340,18 +340,21 @@ count_message_by_stream_query = """
|
||||
zerver_count_message_by_stream = ZerverCountQuery(Message, StreamCount, count_message_by_stream_query)
|
||||
|
||||
COUNT_STATS = {
|
||||
'active_users:is_bot': CountStat('active_users:is_bot', zerver_count_user_by_realm,
|
||||
{'is_active': True}, (UserProfile, 'is_bot'), CountStat.DAY, True),
|
||||
'messages_sent': CountStat('messages_sent', zerver_count_message_by_user, {}, None,
|
||||
CountStat.HOUR, False),
|
||||
'messages_sent:is_bot': CountStat('messages_sent:is_bot', zerver_count_message_by_user, {},
|
||||
(UserProfile, 'is_bot'), CountStat.DAY, False),
|
||||
'messages_sent:message_type': CountStat('messages_sent:message_type',
|
||||
zerver_count_message_type_by_user, {},
|
||||
None, CountStat.DAY, False),
|
||||
'messages_sent:client': CountStat('messages_sent:client', zerver_count_message_by_user, {},
|
||||
(Message, 'sending_client_id'), CountStat.DAY, False),
|
||||
'messages_sent_to_stream:is_bot': CountStat('messages_sent_to_stream:is_bot',
|
||||
zerver_count_message_by_stream, {},
|
||||
(UserProfile, 'is_bot'), CountStat.HOUR, False)
|
||||
'active_users:is_bot:day': CountStat(
|
||||
'active_users:is_bot:day', zerver_count_user_by_realm, {'is_active': True},
|
||||
(UserProfile, 'is_bot'), CountStat.DAY, True),
|
||||
'messages_sent:hour': CountStat(
|
||||
'messages_sent:hour', zerver_count_message_by_user, {}, None, CountStat.HOUR, False),
|
||||
'messages_sent:is_bot:day': CountStat(
|
||||
'messages_sent:is_bot:day', zerver_count_message_by_user, {},
|
||||
(UserProfile, 'is_bot'), CountStat.DAY, False),
|
||||
'messages_sent:message_type:day': CountStat(
|
||||
'messages_sent:message_type:day', zerver_count_message_type_by_user, {},
|
||||
None, CountStat.DAY, False),
|
||||
'messages_sent:client:day': CountStat(
|
||||
'messages_sent:client:day', zerver_count_message_by_user, {},
|
||||
(Message, 'sending_client_id'), CountStat.DAY, False),
|
||||
'messages_sent_to_stream:is_bot:hour': CountStat(
|
||||
'messages_sent_to_stream:is_bot', zerver_count_message_by_stream, {},
|
||||
(UserProfile, 'is_bot'), CountStat.HOUR, False)
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ class Command(BaseCommand):
|
||||
interval=stat.interval, value=value, **id_args)
|
||||
for end_time, value in zip(end_times, values) if value != 0])
|
||||
|
||||
stat = COUNT_STATS['active_users:is_bot']
|
||||
stat = COUNT_STATS['active_users:is_bot:day']
|
||||
realm_data = {
|
||||
'false': self.generate_fixture_data(stat, .1, .03, 3, .5, 3),
|
||||
'true': self.generate_fixture_data(stat, .01, 0, 1, 0, 1)
|
||||
} # type: Dict[Optional[str], List[int]]
|
||||
insert_fixture_data(stat, realm_data, RealmCount)
|
||||
|
||||
stat = COUNT_STATS['messages_sent']
|
||||
stat = COUNT_STATS['messages_sent:hour']
|
||||
user_data = {
|
||||
None: self.generate_fixture_data(stat, 2, 1, 1.5, .6, 8, holiday_rate=.1)
|
||||
} # type: Dict[Optional[str], List[int]]
|
||||
@@ -82,14 +82,14 @@ class Command(BaseCommand):
|
||||
realm_data = {None: self.generate_fixture_data(stat, 50, 30, 5, .6, 3)}
|
||||
insert_fixture_data(stat, realm_data, RealmCount)
|
||||
|
||||
stat = COUNT_STATS['messages_sent:is_bot']
|
||||
stat = COUNT_STATS['messages_sent:is_bot:day']
|
||||
user_data = {'false': self.generate_fixture_data(stat, 2, 1, 1.5, .6, 8)}
|
||||
insert_fixture_data(stat, user_data, UserCount)
|
||||
realm_data = {'false': self.generate_fixture_data(stat, 35, 15, 6, .6, 4),
|
||||
'true': self.generate_fixture_data(stat, 15, 15, 3, .4, 2)}
|
||||
insert_fixture_data(stat, realm_data, RealmCount)
|
||||
|
||||
stat = COUNT_STATS['messages_sent:message_type']
|
||||
stat = COUNT_STATS['messages_sent:message_type:day']
|
||||
user_data = {
|
||||
'public_stream': self.generate_fixture_data(stat, 1.5, 1, 3, .6, 8),
|
||||
'private_message': self.generate_fixture_data(stat, .5, .3, 1, .6, 8)}
|
||||
@@ -109,7 +109,7 @@ class Command(BaseCommand):
|
||||
barnowl_ = Client.objects.create(name='barnowl_')
|
||||
plan9_ = Client.objects.create(name='plan9_')
|
||||
|
||||
stat = COUNT_STATS['messages_sent:client']
|
||||
stat = COUNT_STATS['messages_sent:client:day']
|
||||
user_data = {
|
||||
website_.id: self.generate_fixture_data(stat, 2, 1, 1.5, .6, 8),
|
||||
barnowl_.id: self.generate_fixture_data(stat, 0, .3, 1.5, .6, 8)}
|
||||
|
||||
@@ -225,7 +225,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_active_users_by_is_bot(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['active_users:is_bot']
|
||||
stat = COUNT_STATS['active_users:is_bot:day']
|
||||
self.current_property = stat.property
|
||||
|
||||
# To be included
|
||||
@@ -248,7 +248,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_messages_sent(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['messages_sent']
|
||||
stat = COUNT_STATS['messages_sent:hour']
|
||||
self.current_property = stat.property
|
||||
|
||||
# Nothing in this query should be bot-related
|
||||
@@ -274,7 +274,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_messages_sent_by_is_bot(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['messages_sent:is_bot']
|
||||
stat = COUNT_STATS['messages_sent:is_bot:day']
|
||||
self.current_property = stat.property
|
||||
|
||||
bot = self.create_user(is_bot=True)
|
||||
@@ -303,7 +303,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_messages_sent_by_message_type(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['messages_sent:message_type']
|
||||
stat = COUNT_STATS['messages_sent:message_type:day']
|
||||
self.current_property = stat.property
|
||||
|
||||
# Nothing currently in this stat that is bot related, but so many of
|
||||
@@ -363,7 +363,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_messages_sent_to_recipients_with_same_id(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['messages_sent:message_type']
|
||||
stat = COUNT_STATS['messages_sent:message_type:day']
|
||||
self.current_property = stat.property
|
||||
|
||||
user = self.create_user(id=1000)
|
||||
@@ -382,7 +382,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_messages_sent_by_client(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['messages_sent:client']
|
||||
stat = COUNT_STATS['messages_sent:client:day']
|
||||
self.current_property = stat.property
|
||||
|
||||
user1 = self.create_user(is_bot=True)
|
||||
@@ -418,7 +418,7 @@ class TestCountStats(AnalyticsTestCase):
|
||||
|
||||
def test_messages_sent_to_stream_by_is_bot(self):
|
||||
# type: () -> None
|
||||
stat = COUNT_STATS['messages_sent_to_stream:is_bot']
|
||||
stat = COUNT_STATS['messages_sent_to_stream:is_bot:hour']
|
||||
self.current_property = stat.property
|
||||
|
||||
bot = self.create_user(is_bot=True)
|
||||
|
||||
@@ -105,7 +105,7 @@ def get_totals_by_subgroup(property, table, key_id):
|
||||
|
||||
def get_number_of_humans(realm, start, end, min_length=None):
|
||||
# type: (Realm, datetime, datetime, Optional[int]) -> Dict[str, Any]
|
||||
stat = COUNT_STATS['active_users:is_bot']
|
||||
stat = COUNT_STATS['active_users:is_bot:day']
|
||||
end_times, values = get_time_series_by_subgroup(
|
||||
stat, RealmCount, realm.id, ['false'], start, end, min_length)
|
||||
return {'end_times': end_times, 'humans': values['false'],
|
||||
@@ -113,7 +113,7 @@ def get_number_of_humans(realm, start, end, min_length=None):
|
||||
|
||||
def get_messages_sent_by_humans_and_bots(realm, start, end, min_length=None):
|
||||
# type: (Realm, datetime, datetime, Optional[int]) -> Dict[str, Any]
|
||||
stat = COUNT_STATS['messages_sent:is_bot']
|
||||
stat = COUNT_STATS['messages_sent:is_bot:day']
|
||||
end_times, values = get_time_series_by_subgroup(
|
||||
stat, RealmCount, realm.id, ['false', 'true'], start, end, min_length)
|
||||
return {'end_times': end_times, 'humans': values['false'], 'bots': values['true'],
|
||||
@@ -121,7 +121,7 @@ def get_messages_sent_by_humans_and_bots(realm, start, end, min_length=None):
|
||||
|
||||
def get_messages_sent_by_message_type(user):
|
||||
# type: (UserProfile) -> Dict[str, List[Any]]
|
||||
property = 'messages_sent:message_type'
|
||||
property = 'messages_sent:message_type:day'
|
||||
user_data = get_totals_by_subgroup(property, UserCount, user.id)
|
||||
realm_data = get_totals_by_subgroup(property, RealmCount, user.realm.id)
|
||||
message_types = ['public_stream', 'private_stream', 'private_message']
|
||||
@@ -131,7 +131,7 @@ def get_messages_sent_by_message_type(user):
|
||||
|
||||
def get_messages_sent_by_client(user):
|
||||
# type: (UserProfile) -> Dict[str, List[Any]]
|
||||
property = 'messages_sent:client'
|
||||
property = 'messages_sent:client:day'
|
||||
user_data = get_totals_by_subgroup(property, UserCount, user.id)
|
||||
realm_data = get_totals_by_subgroup(property, RealmCount, user.realm.id)
|
||||
client_ids = sorted(realm_data.keys())
|
||||
|
||||
Reference in New Issue
Block a user