mirror of https://github.com/zulip/zulip.git
mypy: Fix strict-optional in analytics.
This commit is contained in:
parent
7f43ec05f2
commit
d9b23b39d3
|
@ -143,6 +143,7 @@ def do_fill_count_stat_at_hour(stat, end_time):
|
|||
start_time = end_time - stat.interval
|
||||
if not isinstance(stat, LoggingCountStat):
|
||||
timer = time.time()
|
||||
assert(stat.data_collector.pull_function is not None)
|
||||
rows_added = stat.data_collector.pull_function(stat.property, start_time, end_time)
|
||||
logger.info("%s run pull_function (%dms/%sr)" %
|
||||
(stat.property, (time.time()-timer)*1000, rows_added))
|
||||
|
|
|
@ -17,7 +17,7 @@ from zerver.models import Realm, UserProfile, Stream, Message, Client, \
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from six.moves import zip
|
||||
from typing import Any, Dict, List, Optional, Text, Type, Union
|
||||
from typing import Any, Dict, List, Optional, Text, Type, Union, Mapping
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Populates analytics tables with randomly generated data."""
|
||||
|
@ -60,7 +60,7 @@ class Command(BaseCommand):
|
|||
shylock = self.create_user('shylock@analytics.ds', 'Shylock', True, installation_time, realm)
|
||||
|
||||
def insert_fixture_data(stat, fixture_data, table):
|
||||
# type: (CountStat, Dict[Optional[str], List[int]], Type[BaseCount]) -> None
|
||||
# type: (CountStat, Mapping[Optional[str], List[int]], Type[BaseCount]) -> None
|
||||
end_times = time_range(last_end_time, last_end_time, stat.frequency,
|
||||
len(list(fixture_data.values())[0]))
|
||||
if table == RealmCount:
|
||||
|
@ -76,13 +76,14 @@ class Command(BaseCommand):
|
|||
stat = COUNT_STATS['realm_active_humans::day']
|
||||
realm_data = {
|
||||
None: self.generate_fixture_data(stat, .1, .03, 3, .5, 3, partial_sum=True),
|
||||
} # type: Dict[Optional[str], List[int]]
|
||||
} # type: Mapping[Optional[str], List[int]]
|
||||
insert_fixture_data(stat, realm_data, RealmCount)
|
||||
FillState.objects.create(property=stat.property, end_time=last_end_time,
|
||||
state=FillState.DONE)
|
||||
|
||||
stat = COUNT_STATS['messages_sent:is_bot:hour']
|
||||
user_data = {'false': self.generate_fixture_data(stat, 2, 1, 1.5, .6, 8, holiday_rate=.1)}
|
||||
user_data = {'false': self.generate_fixture_data(
|
||||
stat, 2, 1, 1.5, .6, 8, holiday_rate=.1)} # type: Mapping[Optional[str], List[int]]
|
||||
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)}
|
||||
|
|
|
@ -201,7 +201,7 @@ class TestProcessCountStat(AnalyticsTestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
process_count_stat(stat, installation_epoch() + 65*self.MINUTE)
|
||||
with self.assertRaises(ValueError):
|
||||
process_count_stat(stat, installation_epoch().replace(tzinfo=None) + self.HOUR)
|
||||
process_count_stat(stat, installation_epoch().replace(tzinfo=None) + self.HOUR) # type: ignore # https://github.com/python/typeshed/pull/1347
|
||||
|
||||
# This tests the LoggingCountStat branch of the code in do_delete_counts_at_hour.
|
||||
# It is important that do_delete_counts_at_hour not delete any of the collected
|
||||
|
|
|
@ -19,7 +19,7 @@ import mock
|
|||
import ujson
|
||||
|
||||
from six.moves import range
|
||||
from typing import List, Dict
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
class TestStatsEndpoint(ZulipTestCase):
|
||||
def test_stats(self):
|
||||
|
@ -47,7 +47,7 @@ class TestGetChartData(ZulipTestCase):
|
|||
return [0, 0, i, 0]
|
||||
|
||||
def insert_data(self, stat, realm_subgroups, user_subgroups):
|
||||
# type: (CountStat, List[str], List[str]) -> None
|
||||
# type: (CountStat, List[Optional[str]], List[str]) -> None
|
||||
if stat.frequency == CountStat.HOUR:
|
||||
insert_time = self.end_times_hour[2]
|
||||
fill_time = self.end_times_hour[-1]
|
||||
|
|
|
@ -183,7 +183,7 @@ def rewrite_client_arrays(value_arrays):
|
|||
return mapped_arrays
|
||||
|
||||
def get_time_series_by_subgroup(stat, table, key_id, end_times, subgroup_to_label, include_empty_subgroups):
|
||||
# type: (CountStat, Type[BaseCount], Optional[int], List[datetime], Dict[Optional[str], str], bool) -> Dict[str, List[int]]
|
||||
# type: (CountStat, Type[BaseCount], int, List[datetime], Dict[Optional[str], str], bool) -> Dict[str, List[int]]
|
||||
queryset = table_filtered_to_id(table, key_id).filter(property=stat.property) \
|
||||
.values_list('subgroup', 'end_time', 'value')
|
||||
value_dicts = defaultdict(lambda: defaultdict(int)) # type: Dict[Optional[str], Dict[datetime, int]]
|
||||
|
|
Loading…
Reference in New Issue