mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
analytics: Change use of typing.Text to str.
This commit is contained in:
committed by
Tim Abbott
parent
fc6833e46a
commit
5adf983c3c
@@ -3,7 +3,7 @@ from collections import OrderedDict, defaultdict
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, Dict, List, \
|
from typing import Any, Callable, Dict, List, \
|
||||||
Optional, Text, Tuple, Type, Union
|
Optional, Tuple, Type, Union
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import connection, models
|
from django.db import connection, models
|
||||||
@@ -48,7 +48,7 @@ class CountStat:
|
|||||||
else: # frequency == CountStat.DAY
|
else: # frequency == CountStat.DAY
|
||||||
self.interval = timedelta(days=1)
|
self.interval = timedelta(days=1)
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<CountStat: %s>" % (self.property,)
|
return "<CountStat: %s>" % (self.property,)
|
||||||
|
|
||||||
class LoggingCountStat(CountStat):
|
class LoggingCountStat(CountStat):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, List, Mapping, Optional, Text, Type, Union
|
from typing import Any, Dict, List, Mapping, Optional, Type, Union
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
@@ -20,8 +20,8 @@ class Command(BaseCommand):
|
|||||||
DAYS_OF_DATA = 100
|
DAYS_OF_DATA = 100
|
||||||
random_seed = 26
|
random_seed = 26
|
||||||
|
|
||||||
def create_user(self, email: Text,
|
def create_user(self, email: str,
|
||||||
full_name: Text,
|
full_name: str,
|
||||||
is_staff: bool,
|
is_staff: bool,
|
||||||
date_joined: datetime,
|
date_joined: datetime,
|
||||||
realm: Realm) -> UserProfile:
|
realm: Realm) -> UserProfile:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Any, Dict, Optional, Text, Tuple, Union
|
from typing import Any, Dict, Optional, Tuple, Union
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ from zerver.lib.timestamp import floor_to_day
|
|||||||
from zerver.models import Realm, Recipient, Stream, UserProfile
|
from zerver.models import Realm, Recipient, Stream, UserProfile
|
||||||
|
|
||||||
class FillState(models.Model):
|
class FillState(models.Model):
|
||||||
property = models.CharField(max_length=40, unique=True) # type: Text
|
property = models.CharField(max_length=40, unique=True) # type: str
|
||||||
end_time = models.DateTimeField() # type: datetime.datetime
|
end_time = models.DateTimeField() # type: datetime.datetime
|
||||||
|
|
||||||
# Valid states are {DONE, STARTED}
|
# Valid states are {DONE, STARTED}
|
||||||
@@ -17,7 +17,7 @@ class FillState(models.Model):
|
|||||||
|
|
||||||
last_modified = models.DateTimeField(auto_now=True) # type: datetime.datetime
|
last_modified = models.DateTimeField(auto_now=True) # type: datetime.datetime
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<FillState: %s %s %s>" % (self.property, self.end_time, self.state)
|
return "<FillState: %s %s %s>" % (self.property, self.end_time, self.state)
|
||||||
|
|
||||||
# The earliest/starting end_time in FillState
|
# The earliest/starting end_time in FillState
|
||||||
@@ -36,17 +36,17 @@ def last_successful_fill(property: str) -> Optional[datetime.datetime]:
|
|||||||
|
|
||||||
# would only ever make entries here by hand
|
# would only ever make entries here by hand
|
||||||
class Anomaly(models.Model):
|
class Anomaly(models.Model):
|
||||||
info = models.CharField(max_length=1000) # type: Text
|
info = models.CharField(max_length=1000) # type: str
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<Anomaly: %s... %s>" % (self.info, self.id)
|
return "<Anomaly: %s... %s>" % (self.info, self.id)
|
||||||
|
|
||||||
class BaseCount(models.Model):
|
class BaseCount(models.Model):
|
||||||
# Note: When inheriting from BaseCount, you may want to rearrange
|
# Note: When inheriting from BaseCount, you may want to rearrange
|
||||||
# the order of the columns in the migration to make sure they
|
# the order of the columns in the migration to make sure they
|
||||||
# match how you'd like the table to be arranged.
|
# match how you'd like the table to be arranged.
|
||||||
property = models.CharField(max_length=32) # type: Text
|
property = models.CharField(max_length=32) # type: str
|
||||||
subgroup = models.CharField(max_length=16, null=True) # type: Optional[Text]
|
subgroup = models.CharField(max_length=16, null=True) # type: Optional[str]
|
||||||
end_time = models.DateTimeField() # type: datetime.datetime
|
end_time = models.DateTimeField() # type: datetime.datetime
|
||||||
value = models.BigIntegerField() # type: int
|
value = models.BigIntegerField() # type: int
|
||||||
anomaly = models.ForeignKey(Anomaly, on_delete=models.SET_NULL, null=True) # type: Optional[Anomaly]
|
anomaly = models.ForeignKey(Anomaly, on_delete=models.SET_NULL, null=True) # type: Optional[Anomaly]
|
||||||
@@ -59,7 +59,7 @@ class InstallationCount(BaseCount):
|
|||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("property", "subgroup", "end_time")
|
unique_together = ("property", "subgroup", "end_time")
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<InstallationCount: %s %s %s>" % (self.property, self.subgroup, self.value)
|
return "<InstallationCount: %s %s %s>" % (self.property, self.subgroup, self.value)
|
||||||
|
|
||||||
class RealmCount(BaseCount):
|
class RealmCount(BaseCount):
|
||||||
@@ -69,7 +69,7 @@ class RealmCount(BaseCount):
|
|||||||
unique_together = ("realm", "property", "subgroup", "end_time")
|
unique_together = ("realm", "property", "subgroup", "end_time")
|
||||||
index_together = ["property", "end_time"]
|
index_together = ["property", "end_time"]
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<RealmCount: %s %s %s %s>" % (self.realm, self.property, self.subgroup, self.value)
|
return "<RealmCount: %s %s %s %s>" % (self.realm, self.property, self.subgroup, self.value)
|
||||||
|
|
||||||
class UserCount(BaseCount):
|
class UserCount(BaseCount):
|
||||||
@@ -82,7 +82,7 @@ class UserCount(BaseCount):
|
|||||||
# aggregating from users to realms
|
# aggregating from users to realms
|
||||||
index_together = ["property", "realm", "end_time"]
|
index_together = ["property", "realm", "end_time"]
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<UserCount: %s %s %s %s>" % (self.user, self.property, self.subgroup, self.value)
|
return "<UserCount: %s %s %s %s>" % (self.user, self.property, self.subgroup, self.value)
|
||||||
|
|
||||||
class StreamCount(BaseCount):
|
class StreamCount(BaseCount):
|
||||||
@@ -95,6 +95,6 @@ class StreamCount(BaseCount):
|
|||||||
# aggregating from streams to realms
|
# aggregating from streams to realms
|
||||||
index_together = ["property", "realm", "end_time"]
|
index_together = ["property", "realm", "end_time"]
|
||||||
|
|
||||||
def __str__(self) -> Text:
|
def __str__(self) -> str:
|
||||||
return "<StreamCount: %s %s %s %s %s>" % (
|
return "<StreamCount: %s %s %s %s %s>" % (
|
||||||
self.stream, self.property, self.subgroup, self.value, self.id)
|
self.stream, self.property, self.subgroup, self.value, self.id)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, List, Optional, Text, Tuple, Type, Union
|
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
@@ -91,8 +91,8 @@ class AnalyticsTestCase(TestCase):
|
|||||||
return Message.objects.create(**kwargs)
|
return Message.objects.create(**kwargs)
|
||||||
|
|
||||||
# kwargs should only ever be a UserProfile or Stream.
|
# kwargs should only ever be a UserProfile or Stream.
|
||||||
def assertCountEquals(self, table: Type[BaseCount], value: int, property: Optional[Text]=None,
|
def assertCountEquals(self, table: Type[BaseCount], value: int, property: Optional[str]=None,
|
||||||
subgroup: Optional[Text]=None, end_time: datetime=TIME_ZERO,
|
subgroup: Optional[str]=None, end_time: datetime=TIME_ZERO,
|
||||||
realm: Optional[Realm]=None, **kwargs: models.Model) -> None:
|
realm: Optional[Realm]=None, **kwargs: models.Model) -> None:
|
||||||
if property is None:
|
if property is None:
|
||||||
property = self.current_property
|
property = self.current_property
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import time
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Callable, Dict, List, \
|
from typing import Any, Callable, Dict, List, \
|
||||||
Optional, Set, Text, Tuple, Type, Union
|
Optional, Set, Tuple, Type, Union
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -74,7 +74,7 @@ def get_chart_data_for_realm(request: HttpRequest, user_profile: UserProfile,
|
|||||||
return get_chart_data(request=request, user_profile=user_profile, realm=realm, **kwargs)
|
return get_chart_data(request=request, user_profile=user_profile, realm=realm, **kwargs)
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name: Text=REQ(),
|
def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name: str=REQ(),
|
||||||
min_length: Optional[int]=REQ(converter=to_non_negative_int, default=None),
|
min_length: Optional[int]=REQ(converter=to_non_negative_int, default=None),
|
||||||
start: Optional[datetime]=REQ(converter=to_utc_datetime, default=None),
|
start: Optional[datetime]=REQ(converter=to_utc_datetime, default=None),
|
||||||
end: Optional[datetime]=REQ(converter=to_utc_datetime, default=None),
|
end: Optional[datetime]=REQ(converter=to_utc_datetime, default=None),
|
||||||
@@ -1013,7 +1013,7 @@ def user_activity_summary_table(user_summary: Dict[str, Dict[str, Any]]) -> str:
|
|||||||
return make_table(title, cols, rows)
|
return make_table(title, cols, rows)
|
||||||
|
|
||||||
def realm_user_summary_table(all_records: List[QuerySet],
|
def realm_user_summary_table(all_records: List[QuerySet],
|
||||||
admin_emails: Set[Text]) -> Tuple[Dict[str, Dict[str, Any]], str]:
|
admin_emails: Set[str]) -> Tuple[Dict[str, Dict[str, Any]], str]:
|
||||||
user_records = {}
|
user_records = {}
|
||||||
|
|
||||||
def by_email(record: QuerySet) -> str:
|
def by_email(record: QuerySet) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user