-
Notifications
You must be signed in to change notification settings - Fork 25
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
stats: add tests #3462
Conversation
5dc0adf
to
d444952
Compare
974c368
to
589aa36
Compare
589aa36
to
b1fce89
Compare
tests/ui/stats/test_stats_pricing.py
Outdated
|
||
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.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number
_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} |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before
def _get_all_libraries(self): | ||
"""Get all libraries in the system.""" | ||
return list(LibrariesSearch().source(['pid', 'name', 'organisation']) | ||
.scan()) |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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
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() |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
0dab6d8
to
d0637c4
Compare
d0637c4
to
ab7fceb
Compare
* 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]>
ab7fceb
to
47f0dfd
Compare
Co-Authored-by: Johnny Mariéthoz [email protected]
Co-Authored-by: Bertrand Zuchuat [email protected]
Why are you opening this PR?
Dependencies
My PR depends on the following
rero-ils-ui
's PR(s):How to test?