Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Use indexes in go_system_stats management command and bring back uniq…
Browse files Browse the repository at this point in the history
…ue address counts.
  • Loading branch information
jerith committed Feb 3, 2015
1 parent 3dedf06 commit 21fcb98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
19 changes: 9 additions & 10 deletions go/base/management/commands/go_system_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ def handle_command_conversation_types_by_month(self, *args, **options):
writer.writerow(row)

def _increment_msg_stats(self, conv, stats):
batch_key = conv.batch.key
mdb = conv.mdb
cache = mdb.cache
inbound_uniques = cache.count_from_addrs(batch_key)
outbound_uniques = cache.count_to_addrs(batch_key)
inbound_stats = conv.mdb.batch_inbound_stats(conv.batch.key)
outbound_stats = conv.mdb.batch_outbound_stats(conv.batch.key)
stats["conversations_started"] += 1
stats["inbound_message_count"] += mdb.batch_inbound_count(batch_key)
stats["outbound_message_count"] += mdb.batch_outbound_count(batch_key)
stats["inbound_uniques"] += inbound_uniques
stats["outbound_uniques"] += outbound_uniques
stats["total_uniques"] += max(inbound_uniques, outbound_uniques)
stats["inbound_message_count"] += inbound_stats['total']
stats["outbound_message_count"] += outbound_stats['total']
stats["inbound_uniques"] += inbound_stats['unique_addresses']
stats["outbound_uniques"] += outbound_stats['unique_addresses']
stats["total_uniques"] += max(
inbound_stats['unique_addresses'],
outbound_stats['unique_addresses'])

def handle_command_message_counts_by_month(self, *args, **options):
month_stats = {}
Expand Down
7 changes: 3 additions & 4 deletions go/base/tests/test_go_system_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ def test_message_counts_by_month(self):

cmd = self.run_command(command=["message_counts_by_month"])

# TODO fix once we support uniques properly again
self.assert_csv_output(cmd, [
"date,conversations_started,"
"inbound_message_count,outbound_message_count,"
"inbound_uniques,outbound_uniques,total_uniques",
"09/01/2013,1,3,6,0,0,0",
"11/01/2013,3,2,2,0,0,0",
"12/01/2013,2,4,6,0,0,0",
"09/01/2013,1,3,6,1,2,2",
"11/01/2013,3,2,2,2,2,2",
"12/01/2013,2,4,6,2,6,6",
])

def test_custom_date_format(self):
Expand Down

0 comments on commit 21fcb98

Please sign in to comment.