Skip to content

Conversation

@JakobMiesner
Copy link
Contributor

@JakobMiesner JakobMiesner commented Nov 7, 2025

tests are failing because of dependency on this PR

@JakobMiesner JakobMiesner moved this to In review 🔍 in Sprint Q4/2025 Nov 7, 2025

if creation_date and start_date:
waiting_time = (start_date - creation_date).days
stats["waiting_time"] = waiting_time if waiting_time >= 0 else None
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it better to return 0 than None?
If we want to distinguish self-checkout from normal loans, this won't be enough (since a normal loan can be retrieved on the same day).

Copy link
Contributor Author

@JakobMiesner JakobMiesner Nov 12, 2025

Choose a reason for hiding this comment

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

I just wanted to make sure there are no negative values, which would skew the statistics. Like when doing a sum over the waiting time and there is one loan where the start_date was manually set before the creation_date I don't think it should influence the waiting time statistic. But it might be good to have a discussion about how to handle such cases?

Regarding distinguishing self-checkout and normal loans: one can filter with the q parameter for the delivery option.

description="Each group_by item must be a dict with 'field' key"
)

_validate_os_field_name(grouping["field"])
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to have an allow list instead of a regexp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would surely be possible, but might limit in how the endpoint can be used and it requires more work from our side to keep track of all possible fields.
The histogram will be implemented for multiple record types and adding+maintaining an allow list might be tedious.
Also the endpoint is behind the backoffice permission, so I do not think it is too critical?

Comment on lines +65 to +77
actions = [action for action in self.actionsiter()]
res = search.helpers.bulk(self.client, actions, stats_only=True, chunk_size=50)
Copy link
Member

Choose a reason for hiding this comment

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

Could you maybe clarify what this part does?

Copy link
Contributor Author

@JakobMiesner JakobMiesner Nov 13, 2025

Choose a reason for hiding this comment

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

I added a comment. Hope that makes it more clear

@ptamarit ptamarit moved this from In review 🔍 to In progress in Sprint Q4/2025 Nov 7, 2025
@ptamarit ptamarit requested review from ptamarit and removed request for ptamarit November 7, 2025 14:23
@JakobMiesner JakobMiesner force-pushed the feature/stats/loan-stats branch 2 times, most recently from 5a988e2 to 6bce595 Compare November 13, 2025 09:57

# Document availability during loan request
stat_events_index_name = "events-stats-loan-transitions"
if current_search_client.indices.exists(index=stat_events_index_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to fail rather than silently not index things if this conditional statatement is not fulfiled. ping @ntarocco WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for context: the check was added because if there is no event at the moment a loan is indexed, there will be no events index and the loan indexer will throw an error in the lines below the if, leading to not/wrongly indexed loans.
I could manually create the index in our systems during deploy and add it to the release notes that the stats index needs to be created for the system to work. But then the setup script should also create the index for new systems.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, if it is required before running this code (weird, shouldn't it be created automatically if not existing?), then I would fail instead.

try:
parsed_args = schema.load(request.args.to_dict())
except ValidationError as e:
raise InvalidParameterError(description=e.messages)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this returning json error in REST?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is. InvalidParameterException inherits from class RESTException.

* the endpoint returns a histogram for loans where requested metrics are grouped by and aggregated
* extend the loans with a new stats object
* the stats object contains `waiting_time`, `loan_duration` and `available_items_during_request`
@JakobMiesner JakobMiesner force-pushed the feature/stats/loan-stats branch from 6bce595 to b82b815 Compare November 18, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

4 participants