mirror of https://github.com/zulip/zulip.git
analytics: Use Python 3 syntax for typing (final).
This commit is contained in:
parent
6c286b5eb6
commit
01885cdedc
|
@ -4,10 +4,11 @@ from typing import List
|
||||||
|
|
||||||
from analytics.lib.counts import CountStat
|
from analytics.lib.counts import CountStat
|
||||||
|
|
||||||
def generate_time_series_data(days=100, business_hours_base=10, non_business_hours_base=10,
|
def generate_time_series_data(days: int=100, business_hours_base: float=10,
|
||||||
growth=1, autocorrelation=0, spikiness=1, holiday_rate=0,
|
non_business_hours_base: float=10, growth: float=1,
|
||||||
frequency=CountStat.DAY, partial_sum=False, random_seed=26):
|
autocorrelation: float=0, spikiness: float=1,
|
||||||
# type: (int, float, float, float, float, float, float, str, bool, int) -> List[int]
|
holiday_rate: float=0, frequency: str=CountStat.DAY,
|
||||||
|
partial_sum: bool=False, random_seed: int=26) -> List[int]:
|
||||||
"""
|
"""
|
||||||
Generate semi-realistic looking time series data for testing analytics graphs.
|
Generate semi-realistic looking time series data for testing analytics graphs.
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,10 @@ class Command(BaseCommand):
|
||||||
event_time=user.date_joined)
|
event_time=user.date_joined)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def generate_fixture_data(self, stat, business_hours_base, non_business_hours_base,
|
def generate_fixture_data(self, stat: CountStat, business_hours_base: float,
|
||||||
growth, autocorrelation, spikiness, holiday_rate=0,
|
non_business_hours_base: float, growth: float,
|
||||||
partial_sum=False):
|
autocorrelation: float, spikiness: float,
|
||||||
# type: (CountStat, float, float, float, float, float, float, bool) -> List[int]
|
holiday_rate: float=0, partial_sum: bool=False) -> List[int]:
|
||||||
self.random_seed += 1
|
self.random_seed += 1
|
||||||
return generate_time_series_data(
|
return generate_time_series_data(
|
||||||
days=self.DAYS_OF_DATA, business_hours_base=business_hours_base,
|
days=self.DAYS_OF_DATA, business_hours_base=business_hours_base,
|
||||||
|
|
|
@ -89,9 +89,9 @@ 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, value, property=None, subgroup=None,
|
def assertCountEquals(self, table: Type[BaseCount], value: int, property: Optional[Text]=None,
|
||||||
end_time=TIME_ZERO, realm=None, **kwargs):
|
subgroup: Optional[Text]=None, end_time: datetime=TIME_ZERO,
|
||||||
# type: (Type[BaseCount], int, Optional[Text], Optional[Text], datetime, Optional[Realm], **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
|
||||||
queryset = table.objects.filter(property=property, end_time=end_time).filter(**kwargs)
|
queryset = table.objects.filter(property=property, end_time=end_time).filter(**kwargs)
|
||||||
|
|
|
@ -43,11 +43,10 @@ def stats(request: HttpRequest) -> HttpResponse:
|
||||||
context=dict(realm_name = request.user.realm.name))
|
context=dict(realm_name = request.user.realm.name))
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def get_chart_data(request, user_profile, chart_name=REQ(),
|
def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name: Text=REQ(),
|
||||||
min_length=REQ(converter=to_non_negative_int, default=None),
|
min_length: Optional[int]=REQ(converter=to_non_negative_int, default=None),
|
||||||
start=REQ(converter=to_utc_datetime, default=None),
|
start: Optional[datetime]=REQ(converter=to_utc_datetime, default=None),
|
||||||
end=REQ(converter=to_utc_datetime, default=None)):
|
end: Optional[datetime]=REQ(converter=to_utc_datetime, default=None)) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, Text, Optional[int], Optional[datetime], Optional[datetime]) -> HttpResponse
|
|
||||||
if chart_name == 'number_of_humans':
|
if chart_name == 'number_of_humans':
|
||||||
stat = COUNT_STATS['realm_active_humans::day']
|
stat = COUNT_STATS['realm_active_humans::day']
|
||||||
tables = [RealmCount]
|
tables = [RealmCount]
|
||||||
|
|
Loading…
Reference in New Issue