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
|
||||
|
||||
def generate_time_series_data(days=100, business_hours_base=10, non_business_hours_base=10,
|
||||
growth=1, autocorrelation=0, spikiness=1, holiday_rate=0,
|
||||
frequency=CountStat.DAY, partial_sum=False, random_seed=26):
|
||||
# type: (int, float, float, float, float, float, float, str, bool, int) -> List[int]
|
||||
def generate_time_series_data(days: int=100, business_hours_base: float=10,
|
||||
non_business_hours_base: float=10, growth: float=1,
|
||||
autocorrelation: float=0, spikiness: float=1,
|
||||
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.
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ class Command(BaseCommand):
|
|||
event_time=user.date_joined)
|
||||
return user
|
||||
|
||||
def generate_fixture_data(self, stat, business_hours_base, non_business_hours_base,
|
||||
growth, autocorrelation, spikiness, holiday_rate=0,
|
||||
partial_sum=False):
|
||||
# type: (CountStat, float, float, float, float, float, float, bool) -> List[int]
|
||||
def generate_fixture_data(self, stat: CountStat, business_hours_base: float,
|
||||
non_business_hours_base: float, growth: float,
|
||||
autocorrelation: float, spikiness: float,
|
||||
holiday_rate: float=0, partial_sum: bool=False) -> List[int]:
|
||||
self.random_seed += 1
|
||||
return generate_time_series_data(
|
||||
days=self.DAYS_OF_DATA, business_hours_base=business_hours_base,
|
||||
|
|
|
@ -89,9 +89,9 @@ class AnalyticsTestCase(TestCase):
|
|||
return Message.objects.create(**kwargs)
|
||||
|
||||
# kwargs should only ever be a UserProfile or Stream.
|
||||
def assertCountEquals(self, table, value, property=None, subgroup=None,
|
||||
end_time=TIME_ZERO, realm=None, **kwargs):
|
||||
# type: (Type[BaseCount], int, Optional[Text], Optional[Text], datetime, Optional[Realm], **models.Model) -> None
|
||||
def assertCountEquals(self, table: Type[BaseCount], value: int, property: Optional[Text]=None,
|
||||
subgroup: Optional[Text]=None, end_time: datetime=TIME_ZERO,
|
||||
realm: Optional[Realm]=None, **kwargs: models.Model) -> None:
|
||||
if property is None:
|
||||
property = self.current_property
|
||||
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))
|
||||
|
||||
@has_request_variables
|
||||
def get_chart_data(request, user_profile, chart_name=REQ(),
|
||||
min_length=REQ(converter=to_non_negative_int, default=None),
|
||||
start=REQ(converter=to_utc_datetime, default=None),
|
||||
end=REQ(converter=to_utc_datetime, default=None)):
|
||||
# type: (HttpRequest, UserProfile, Text, Optional[int], Optional[datetime], Optional[datetime]) -> HttpResponse
|
||||
def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name: Text=REQ(),
|
||||
min_length: Optional[int]=REQ(converter=to_non_negative_int, default=None),
|
||||
start: Optional[datetime]=REQ(converter=to_utc_datetime, default=None),
|
||||
end: Optional[datetime]=REQ(converter=to_utc_datetime, default=None)) -> HttpResponse:
|
||||
if chart_name == 'number_of_humans':
|
||||
stat = COUNT_STATS['realm_active_humans::day']
|
||||
tables = [RealmCount]
|
||||
|
|
Loading…
Reference in New Issue