Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3555 added total overall activity column to user activity export #952

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions classification/views/search_view_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ReportDataRow(ExportRow):
allele_counts: int
gene_symbols_counts: int
classification_counts: int
overall_activity: int

@export_column(label="Date")
def date_column(self) -> date:
Expand All @@ -46,6 +47,10 @@ def gene_symbols_viewed_column(self) -> int:
def classifications_viewed_column(self) -> int:
return self.classification_counts

@export_column(label="Overall Activity")
def overall_activity_column(self) -> int:
return self.overall_activity


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

metrics_definitions = [
('variantopedia:search', 'search_count', ~Q(args__search="")),
('variantopedia:view_allele', 'allele_count'),
('genes:view_gene_symbol', 'gene_symbol_count', ~Q(args__gene_symbol="")),
('classification:view_classification', 'classification_count')
('classification:view_classification', 'classification_count'),
('', 'overall_activity'),
]

ve: ViewEvent
for view_name, key, *extra_filters in metrics_definitions:
metric_data = ViewEvent.objects.filter(
created__gte=start_of_time_period,
view_name=view_name
).exclude(user__in=excluded_users)
if view_name == '':
metric_data = ViewEvent.objects.filter(
created__gte=start_of_time_period
).exclude(user__in=excluded_users)
else:
metric_data = ViewEvent.objects.filter(
created__gte=start_of_time_period,
view_name=view_name
).exclude(user__in=excluded_users)

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

while current_date <= today:
data = report_data.get(current_date, {'users': set(), 'search_count': 0, 'allele_count': 0,
'gene_symbol_count': 0, 'classification_count': 0})
'gene_symbol_count': 0, 'classification_count': 0,
'overall_activity': 0})
user_list = len(data['users'])
searches = data['search_count']
allele_count = data['allele_count']
gene_symbol_count = data['gene_symbol_count']
classification_count = data['classification_count']
overall_activity = data['overall_activity']
yield ReportDataRow(date=current_date, user=user_list, search_counts=searches,
allele_counts=allele_count, gene_symbols_counts=gene_symbol_count,
classification_counts=classification_count)
classification_counts=classification_count,
overall_activity=overall_activity)
current_date += timedelta(days=(1 if interval == 1 else 7))


Expand Down
Loading