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

[ENG-6165] monthly institutional-users metrics report #10722

Merged

Conversation

aaxelb
Copy link
Contributor

@aaxelb aaxelb commented Aug 27, 2024

Purpose

compute counts on a monthly basis for each user with an institutional affiliation

Changes

  • add osf.metrics.reports.InstitutionalUserReport
  • add osf.metrics.reporters.InstitutionalUsersReporter

QA Notes

Please make verification statements inspired by your code and what your code touches.

  • Verify
  • Verify

What are the areas of risk?

Any concerns/considerations/questions that development raised?

Documentation

Side Effects

Ticket

@aaxelb aaxelb marked this pull request as ready for review September 3, 2024 13:57
@aaxelb aaxelb changed the title [wip][ENG-6165] monthly institutional-users metrics report [ENG-6165] monthly institutional-users metrics report Sep 3, 2024
@aaxelb aaxelb force-pushed the eng-6165 branch 3 times, most recently from fd9be78 to 7fdc6ea Compare September 5, 2024 18:29
Copy link
Contributor

@Johnetordoff Johnetordoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some mild observations, but a really solid piece of engineering. I'm ready to merge it. But @mfraezz should probably look at it and get the benchmarking confirmed.

_CHUNK_SIZE = 500


class InstitutionalUsersReporter(MonthlyReporter):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: docstring here could how this report can be used, maybe warn people changes could effect dashboard page.

department_name=(_affiliation.sso_department or None),
month_last_login=YearMonth.from_date(self.user.date_last_login),
account_creation_date=YearMonth.from_date(self.user.created),
orcid_id=self.user.get_verified_external_id('ORCID', verified_only=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No unverified ORCID's ? I think that's a correct choice. Good to remember in case individual users see they aren't counted and complain, more of a Product concern, but good to agree on it with Product.


def _public_project_queryset(self):
return self._node_queryset().filter(
type='osf.node', # `type` field from TypedModel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Good comments for each function, but it would be nice to have a docstring on the class listing these out.


def _published_preprint_queryset(self):
if not hasattr(osfdb.Preprint, 'affiliated_institutions'):
return osfdb.Preprint.objects.none() # HACK: preprints affiliation project still in-progress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if I was going to be a real stickler I would say this should match the creator affiliation numbers to match current SHARE, but that's really minor and probably won't confuse anyone. NBD

cls._user_setup_with_nothing = _InstiUserSetup(0, 0, 0, 0, 0, cls._institution, cls._now)
cls._user_setup_with_ones = _InstiUserSetup(1, 1, 1, 1, 1, cls._institution, cls._now)
cls._user_setup_with_stuff = _InstiUserSetup(
2, 3, 5, 3, 2, cls._institution, cls._now,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel like it's more readable with keyword argument for these fiddly test numbers

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't fully understand this comment, because there's other tests that test for these. Be clear it's the annoyance is just in the test set-up.

# helper class for test-case setup
@dataclasses.dataclass
class _InstiUserSetup:
'''oof, so many things to set up, gross'''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd reiterate any business logic here, like I'd say preprints should be based on can_view, or any opinionated stuff, but NBD.

@aaxelb aaxelb merged commit 4552e4f into CenterForOpenScience:feature/insti-dash-improv Sep 9, 2024
6 checks passed
@aaxelb aaxelb deleted the eng-6165 branch September 9, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants