Skip to content

Commit faa9ab3

Browse files
#3555 added total overall activity column to user activity export (#952)
1 parent 0dd2bb1 commit faa9ab3

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

classification/views/search_view_metrics.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ReportDataRow(ExportRow):
2121
allele_counts: int
2222
gene_symbols_counts: int
2323
classification_counts: int
24+
overall_activity: int
2425

2526
@export_column(label="Date")
2627
def date_column(self) -> date:
@@ -46,6 +47,10 @@ def gene_symbols_viewed_column(self) -> int:
4647
def classifications_viewed_column(self) -> int:
4748
return self.classification_counts
4849

50+
@export_column(label="Overall Activity")
51+
def overall_activity_column(self) -> int:
52+
return self.overall_activity
53+
4954

5055
def week_start_date(freq: datetime.date) -> datetime.date:
5156
return freq - timedelta(days=date.weekday(freq))
@@ -56,23 +61,30 @@ def stream_report_rows(interval) -> Iterator[ReportDataRow]:
5661
start_of_time_period = datetime.now() - timedelta(days=365)
5762
start_of_time_period = start_of_time_period.date()
5863
report_data = defaultdict(lambda: {'users': set(), 'search_count': 0, 'allele_count': 0,
59-
'gene_symbol_count': 0, 'classification_count': 0})
64+
'gene_symbol_count': 0, 'classification_count': 0,
65+
'overall_activity': 0})
6066
excluded_users = User.objects.filter(
6167
Q(is_superuser=True) | Q(groups__name__in={'variantgrid/tester', 'variantgrid/bot'}))
6268

6369
metrics_definitions = [
6470
('variantopedia:search', 'search_count', ~Q(args__search="")),
6571
('variantopedia:view_allele', 'allele_count'),
6672
('genes:view_gene_symbol', 'gene_symbol_count', ~Q(args__gene_symbol="")),
67-
('classification:view_classification', 'classification_count')
73+
('classification:view_classification', 'classification_count'),
74+
('', 'overall_activity'),
6875
]
6976

7077
ve: ViewEvent
7178
for view_name, key, *extra_filters in metrics_definitions:
72-
metric_data = ViewEvent.objects.filter(
73-
created__gte=start_of_time_period,
74-
view_name=view_name
75-
).exclude(user__in=excluded_users)
79+
if view_name == '':
80+
metric_data = ViewEvent.objects.filter(
81+
created__gte=start_of_time_period
82+
).exclude(user__in=excluded_users)
83+
else:
84+
metric_data = ViewEvent.objects.filter(
85+
created__gte=start_of_time_period,
86+
view_name=view_name
87+
).exclude(user__in=excluded_users)
7688

7789
if extra_filters:
7890
metric_data = metric_data.filter(*extra_filters)
@@ -92,15 +104,18 @@ def stream_report_rows(interval) -> Iterator[ReportDataRow]:
92104

93105
while current_date <= today:
94106
data = report_data.get(current_date, {'users': set(), 'search_count': 0, 'allele_count': 0,
95-
'gene_symbol_count': 0, 'classification_count': 0})
107+
'gene_symbol_count': 0, 'classification_count': 0,
108+
'overall_activity': 0})
96109
user_list = len(data['users'])
97110
searches = data['search_count']
98111
allele_count = data['allele_count']
99112
gene_symbol_count = data['gene_symbol_count']
100113
classification_count = data['classification_count']
114+
overall_activity = data['overall_activity']
101115
yield ReportDataRow(date=current_date, user=user_list, search_counts=searches,
102116
allele_counts=allele_count, gene_symbols_counts=gene_symbol_count,
103-
classification_counts=classification_count)
117+
classification_counts=classification_count,
118+
overall_activity=overall_activity)
104119
current_date += timedelta(days=(1 if interval == 1 else 7))
105120

106121

0 commit comments

Comments
 (0)