Skip to content

Commit 73f1aec

Browse files
committed
added metrics
1 parent 86a9466 commit 73f1aec

7 files changed

Lines changed: 47 additions & 1 deletion

File tree

admin/base/settings/defaults.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
CSRF_COOKIE_HTTPONLY = False
4141

4242
ALLOWED_HOSTS = [
43-
'.osf.io'
43+
'.osf.io',
44+
'localhost'
4445
]
4546

4647
AUTH_PASSWORD_VALIDATORS = [

api/metrics/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def get(self, request, *args, **kwargs):
273273
'user_summary': reports.UserSummaryReport,
274274
'spam_summary': reports.SpamSummaryReport,
275275
'new_user_domains': reports.NewUserDomainReport,
276+
'notification_summary': reports.NotificationSummaryReport
276277
}
277278

278279

osf/management/commands/metrics_backfill_summaries.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
institution_summary
1313
user_summary
1414
node_summary
15+
notification_summary
1516
1617
"""
1718
import csv
@@ -28,6 +29,7 @@
2829
PreprintSummaryReport,
2930
# StorageAddonUsage,
3031
UserSummaryReport,
32+
NotificationSummaryReport
3133
)
3234

3335

@@ -361,6 +363,12 @@ def _map_user_summary(row):
361363
'unconfirmed': int(row['status.unconfirmed'] or 0),
362364
}
363365

366+
def _map_notification_summary(row):
367+
return {
368+
'notifications_count': int(row['notification_subscriptions_count'] or 0),
369+
'users_count': int(row['notification_subscriptions_users_count'] or 0),
370+
}
371+
364372
SUMMARIES = {
365373
'download_count': {
366374
'mapper': _map_download_count,
@@ -386,6 +394,10 @@ def _map_user_summary(row):
386394
'mapper': _map_user_summary,
387395
'class': UserSummaryReport,
388396
},
397+
'notification_summary': {
398+
'mapper': _map_notification_summary,
399+
'class': NotificationSummaryReport,
400+
}
389401
}
390402

391403
def _timestamp_to_dt(timestamp):

osf/metrics/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
PreprintSummaryReport,
2222
StorageAddonUsage,
2323
UserSummaryReport,
24+
NotificationSummaryReport,
2425
)
2526

2627
DAILY_REPORTS = (
@@ -43,4 +44,5 @@
4344
'PreprintDownload',
4445
'RegistriesModerationMetrics',
4546
'UserInstitutionProjectCounts',
47+
'NotificationSummaryReport',
4648
)

osf/metrics/reporters/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .user_count import UserCountReporter
1515
from .spam_count import SpamCountReporter
1616
from .private_spam_metrics import PrivateSpamMetricsReporter
17+
from .notification_count import NotificationCountReporter
1718

1819

1920
class AllDailyReporters(enum.Enum):
@@ -34,3 +35,4 @@ class AllMonthlyReporters(enum.Enum):
3435
INSTITUTIONAL_SUMMARY = InstitutionalSummaryMonthlyReporter
3536
ITEM_USAGE = PublicItemUsageReporter
3637
PRIVATE_SPAM_METRICS = PrivateSpamMetricsReporter
38+
NOTIFICATIONS_COUNT = NotificationCountReporter
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from osf.metrics.reports import (
2+
MonthlyReport,
3+
NotificationSummaryReport,
4+
)
5+
from osf.models.notification_subscription import NotificationSubscription
6+
7+
class NotificationCountReporter(MonthlyReport):
8+
report_name = 'Notification Metrics'
9+
10+
def report(self):
11+
target_month = self.yearmonth.month_start()
12+
next_month = self.yearmonth.month_end()
13+
14+
report = NotificationSummaryReport(
15+
report_yearmonth=str(self.yearmonth),
16+
notification_subscriptions_count=NotificationSubscription.objects.filter(
17+
created__gt=target_month, created__lt=next_month
18+
).distinct().count(),
19+
notification_subscriptions_users_count=NotificationSubscription.objects.filter(
20+
created__gt=target_month, created__lt=next_month
21+
).values('user').distinct().count(),
22+
)
23+
return [report]

osf/metrics/reports.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,8 @@ class PrivateSpamMetricsReport(MonthlyReport):
345345
preprint_oopspam_hammed = metrics.Integer()
346346
preprint_akismet_flagged = metrics.Integer()
347347
preprint_akismet_hammed = metrics.Integer()
348+
349+
350+
class NotificationSummaryReport(MonthlyReport):
351+
notification_subscriptions_count = metrics.Integer()
352+
notification_subscriptions_users_count = metrics.Integer()

0 commit comments

Comments
 (0)