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

stats: add tests #3462

Merged
merged 1 commit into from
Sep 25, 2023
Merged

stats: add tests #3462

merged 1 commit into from
Sep 25, 2023

Conversation

jma
Copy link
Contributor

@jma jma commented Sep 19, 2023

  • Splits the classes to compute statistics into several files.
  • Fixes some spelling.
  • Renames abstract class which is not abstract.
  • Removes useless parameters in the statics methods.
  • Get the location names using only one es query.
  • Creates a loan search query used for several statistics.
  • Fixes delete items statistics.
  • Adds tests for statistics.
  • Fixes some test fixtures.
  • Adds a type filter to the operation logs search to avoid unwanted documents.

Co-Authored-by: Johnny Mariéthoz [email protected]
Co-Authored-by: Bertrand Zuchuat [email protected]

Why are you opening this PR?

  • Which task/US does it implement?
  • Which issue does it fix?

Dependencies

My PR depends on the following rero-ils-ui's PR(s):

  • rero/rero-ils-ui#

How to test?

  • What command should I have to run to test your PR?
  • What should I test through the UI?

@github-actions github-actions bot added the f: statistics Related to the usage statistics either for pricing or for the libaries reports label Sep 19, 2023
@jma jma force-pushed the maj-stats-add-tests branch 5 times, most recently from 5dc0adf to d444952 Compare September 19, 2023 13:26
@github-actions github-actions bot added f: circulation Concerns the circulation interface or backend f: notifications f: activity-logs Everything around logging user or system activities labels Sep 19, 2023
@jma jma force-pushed the maj-stats-add-tests branch 8 times, most recently from 974c368 to 589aa36 Compare September 20, 2023 12:10
@jma jma marked this pull request as ready for review September 20, 2023 12:10
@jma jma marked this pull request as draft September 20, 2023 12:13
@jma jma force-pushed the maj-stats-add-tests branch from 589aa36 to b1fce89 Compare September 20, 2023 12:24
@jma jma marked this pull request as ready for review September 20, 2023 12:24
@jma jma changed the base branch from staging to US-2422-stats September 20, 2023 12:40

def test_stats_pricing_number_of_new_items(
stat_for_pricing, item_lib_martigny):
"""Test the umber of new created items during the specified timeframe."""
Copy link
Contributor

Choose a reason for hiding this comment

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

number

Comment on lines 50 to 55
_from = f'{self.to_date.year}-{self.to_date.month:02d}-01T00:00:00'
_to = self.to_date.format(fmt='YYYY-MM-DDT23:59:59')
self.date_range = {'gte': _from, 'lte': _to}
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems not necessary because it's entirely based on self.to_date. If to_date change, you need to change date_range too.

Comment on lines 56 to 70
def _get_locations_pid(self, library_pid):
"""Locations pid for given library.

:param library_pid: string - the library to filter with
:return: list of pid locations
:rtype: list
"""
locations = LocationsSearch()\
.filter('term', library__pid=library_pid).source('pid').scan()
return [location.pid for location in locations]

def _get_locations_code_name(self, location_pids):
"""Location code and name.

:param location_pid: string - the location to filter with
:return: concatenated code and name of location
:rtype: string
"""
location_search = LocationsSearch()\
.filter('terms', pid=location_pids)\
.source(['code', 'name', 'pid'])
res = {}
for hit in location_search.scan():
res[hit.pid] = f'{hit.code} - {hit.name}'
return res
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be methods from Location module not Stats module

_from = f'{self.to_date.year}-{self.to_date.month:02d}-01T00:00:00'
_to = self.to_date.format(fmt='YYYY-MM-DDT23:59:59')
self.date_range = {'gte': _from, 'lte': _to}
self.libraries = self._get_all_libraries()
Copy link
Contributor

Choose a reason for hiding this comment

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

useless

_from = (self.to_date - relativedelta(
months=self.months_delta)).format(fmt='YYYY-MM-DDT00:00:00')
_to = self.to_date.format(fmt='YYYY-MM-DDT23:59:59')
self.date_range = {'gte': _from, 'lte': _to}
Copy link
Contributor

Choose a reason for hiding this comment

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

same as before

Comment on lines 54 to 57
def _get_all_libraries(self):
"""Get all libraries in the system."""
return list(LibrariesSearch().source(['pid', 'name', 'organisation'])
.scan())
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be part of Library module, not Stats

Comment on lines 59 to 68
def _get_loan_op_search(self, triggers):
"""Get the operation logs base es search.

:param triggers: list[str] - loan triggers value to filter
:return: an elasticsearch dsl search query
"""
return RecordsSearch(index=LoanOperationLog.index_name)\
.filter('range', date=self.date_range)\
.filter('term', record__type='loan')\
.filter('terms', loan__trigger=triggers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, should be part of OperationLog module

Comment on lines 136 to 146
def number_of_documents(self, library_pid):
"""Number of documents linked to my library.

point in time
:param library_pid: string - the library to filter with
:return: the number of matched documents
:rtype: integer
"""
# can be done using the facet
return DocumentsSearch().filter(
'term', holdings__organisation__library_pid=library_pid).count()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be specific method of DocumentSearch class ?

return DocumentsSearch().filter(
'term', holdings__organisation__library_pid=library_pid).count()

def number_of_libraries(self, organisation_pid):
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@jma jma force-pushed the maj-stats-add-tests branch 5 times, most recently from 0dab6d8 to d0637c4 Compare September 21, 2023 11:48
@jma jma force-pushed the maj-stats-add-tests branch from d0637c4 to ab7fceb Compare September 25, 2023 05:37
* Splits the classes to compute statistics into several files.
* Fixes some spelling.
* Renames abstract class which is not abstract.
* Removes useless parameters in the statics methods.
* Get the location names using only one es query.
* Creates a loan search query used for several statistics.
* Fixes delete items statistics.
* Adds tests for statistics.
* Fixes some test fixtures.
* Adds a type filter to the operation logs search to avoid unwanted documents.
* Closes: rero#3435.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
Co-Authored-by: Bertrand Zuchuat <[email protected]>
@jma jma force-pushed the maj-stats-add-tests branch from ab7fceb to 47f0dfd Compare September 25, 2023 07:53
@jma jma changed the base branch from US-2422-stats to staging September 25, 2023 11:38
@jma jma merged commit 99bdf77 into rero:staging Sep 25, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: activity-logs Everything around logging user or system activities f: circulation Concerns the circulation interface or backend f: notifications f: statistics Related to the usage statistics either for pricing or for the libaries reports
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants