Skip to content

Commit

Permalink
respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Sep 6, 2024
1 parent e7dd750 commit 34cbc9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion osf/metrics/reporters/institutional_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@


class InstitutionalUsersReporter(MonthlyReporter):
'''build an InstitutionalUserReport for each institution-user affiliation
built for the institution dashboard at ://osf.example/institutions/<id>/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)
Expand Down
12 changes: 6 additions & 6 deletions osf_tests/metrics/reporters/test_institutional_users_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 34cbc9a

Please sign in to comment.