From 01885cdedc32315db0e2f0553422ba860268b130 Mon Sep 17 00:00:00 2001 From: rht Date: Wed, 22 Nov 2017 06:15:46 +0000 Subject: [PATCH] analytics: Use Python 3 syntax for typing (final). --- analytics/lib/fixtures.py | 9 +++++---- analytics/management/commands/populate_analytics_db.py | 8 ++++---- analytics/tests/test_counts.py | 6 +++--- analytics/views.py | 9 ++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/analytics/lib/fixtures.py b/analytics/lib/fixtures.py index 8b90403865..bd24940416 100644 --- a/analytics/lib/fixtures.py +++ b/analytics/lib/fixtures.py @@ -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. diff --git a/analytics/management/commands/populate_analytics_db.py b/analytics/management/commands/populate_analytics_db.py index b415430d47..81d5ea3fb2 100644 --- a/analytics/management/commands/populate_analytics_db.py +++ b/analytics/management/commands/populate_analytics_db.py @@ -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, diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.py index 14608b8b88..61b01038b1 100644 --- a/analytics/tests/test_counts.py +++ b/analytics/tests/test_counts.py @@ -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) diff --git a/analytics/views.py b/analytics/views.py index 421ea38f14..f4e3fe9efb 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -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]