Skip to content

Commit 654b5f2

Browse files
committed
cumulative preprint counts
1 parent 5749868 commit 654b5f2

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

osf/metrics/reporters/public_item_usage.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,24 @@ def _fill_report_counts(self, report, osf_obj):
170170
and not waffle.switch_is_active(osf.features.COUNTEDUSAGE_UNIFIED_METRICS_2024) # type: ignore[attr-defined]
171171
):
172172
# note: no session-count info in preprint metrics
173-
report.view_count = self._preprint_views(osf_obj)
174-
report.download_count = self._preprint_downloads(osf_obj)
173+
report.view_count = PreprintView.get_count_for_preprint(
174+
preprint=osf_obj,
175+
after=self.yearmonth.month_start(),
176+
before=self.yearmonth.month_end(),
177+
)
178+
report.download_count = PreprintDownload.get_count_for_preprint(
179+
preprint=osf_obj,
180+
after=self.yearmonth.month_start(),
181+
before=self.yearmonth.month_end(),
182+
)
183+
report.cumulative_view_count = PreprintView.get_count_for_preprint(
184+
preprint=osf_obj,
185+
before=self.yearmonth.month_end(),
186+
)
187+
report.cumulative_download_count = PreprintDownload.get_count_for_preprint(
188+
preprint=osf_obj,
189+
before=self.yearmonth.month_end(),
190+
)
175191
else:
176192
(
177193
report.view_count,
@@ -263,22 +279,6 @@ def _countedusage_download_counts(self, osf_obj, cumulative: bool = False) -> tu
263279
)
264280
return (_download_count, _download_session_count)
265281

266-
def _preprint_views(self, preprint: osfdb.Preprint) -> int:
267-
'''aggregate views on each preprint'''
268-
return PreprintView.get_count_for_preprint(
269-
preprint=preprint,
270-
after=self.yearmonth.month_start(),
271-
before=self.yearmonth.month_end(),
272-
)
273-
274-
def _preprint_downloads(self, preprint: osfdb.Preprint) -> int:
275-
'''aggregate downloads on each preprint'''
276-
return PreprintDownload.get_count_for_preprint(
277-
preprint=preprint,
278-
after=self.yearmonth.month_start(),
279-
before=self.yearmonth.month_end(),
280-
)
281-
282282

283283
def _is_item_public(osfid_referent) -> bool:
284284
if isinstance(osfid_referent, osfdb.Preprint):

0 commit comments

Comments
 (0)