From 16aabe6197b14d0aa056f29b94a976cf9c352281 Mon Sep 17 00:00:00 2001 From: abram axel booth Date: Fri, 6 Sep 2024 08:39:54 -0400 Subject: [PATCH] respond to review --- osf/metrics/reporters/institutional_users.py | 8 +++++++- .../reporters/test_institutional_users_reporter.py | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/osf/metrics/reporters/institutional_users.py b/osf/metrics/reporters/institutional_users.py index 9e585a61ce55..0a0598172e01 100644 --- a/osf/metrics/reporters/institutional_users.py +++ b/osf/metrics/reporters/institutional_users.py @@ -16,9 +16,15 @@ class InstitutionalUsersReporter(MonthlyReporter): + '''build an InstitutionalUserReport for each institution-user affiliation + + built for the institution dashboard at ://osf.example/institutions//dashboard/, + which offers institutional admins insight into how people at their institution are + using osf, based on their explicitly-affiliated osf objects + ''' def report(self, yearmonth: YearMonth): _before_datetime = yearmonth.next_month() - for _institution in osfdb.Institution.objects.all(): + for _institution in osfdb.Institution.objects.filter(created__lt=_before_datetime): _user_qs = _institution.get_institution_users().filter(created__lt=_before_datetime) for _user in _user_qs.iterator(chunk_size=_CHUNK_SIZE): _helper = _InstiUserReportHelper(_institution, _user, yearmonth, _before_datetime) diff --git a/osf_tests/metrics/reporters/test_institutional_users_reporter.py b/osf_tests/metrics/reporters/test_institutional_users_reporter.py index 4f5a1799228c..6af191cc6695 100644 --- a/osf_tests/metrics/reporters/test_institutional_users_reporter.py +++ b/osf_tests/metrics/reporters/test_institutional_users_reporter.py @@ -59,14 +59,11 @@ def _assert_report_matches_setup(self, report: InstitutionalUserReport, setup: _ self.assertEqual(report.month_last_login, YearMonth.from_date(setup.user.date_last_login)) self.assertEqual(report.account_creation_date, YearMonth.from_date(setup.user.created)) self.assertEqual(report.orcid_id, setup.orcid_id) - # counts: + # counts (NOTE: report.public_file_count and report.storage_byte_count tested separately) self.assertEqual(report.public_project_count, setup.public_project_count) self.assertEqual(report.private_project_count, setup.private_project_count) self.assertEqual(report.public_registration_count, setup.public_registration_count) self.assertEqual(report.embargoed_registration_count, setup.embargoed_registration_count) - # NOTE: currently untested due to the annoyance involved: - # self.assertEqual(report.public_file_count, ...) - # self.assertEqual(report.storage_byte_count, ...) if _can_affiliate_preprints(): self.assertEqual(report.published_preprint_count, setup.published_preprint_count) else: @@ -142,10 +139,13 @@ def test_several_users(self): _setup = _setup_by_userid[_actual_report.user_id] self._assert_report_matches_setup(_actual_report, _setup) -# helper class for test-case setup + @dataclasses.dataclass class _InstiUserSetup: - '''oof, so many things to set up, gross''' + '''helper class to simplify database setup for a test-case + + (note: public_file_count and storage_byte_count set up separately) + ''' public_project_count: int private_project_count: int public_registration_count: int