From fd7ee9207ba3ace3d1172b0472750d3e2d84d322 Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Mon, 26 Aug 2024 18:27:45 +0200 Subject: [PATCH] processors: allow filtering out robots/machines --- invenio_stats/processors.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/invenio_stats/processors.py b/invenio_stats/processors.py index 8174a5b..83e7ad8 100644 --- a/invenio_stats/processors.py +++ b/invenio_stats/processors.py @@ -88,8 +88,8 @@ def anonymize_user(doc): return doc -def flag_robots(doc): - """Flag events which are created by robots. +def flag_robots(doc, exclude=False): + """Flag and filter events which are created by robots. The list of robots is defined by the `COUNTER-robots Python package `_ , which follows the @@ -99,11 +99,13 @@ def flag_robots(doc): `_. """ doc["is_robot"] = "user_agent" in doc and is_robot(doc["user_agent"]) + if exclude and doc["is_robot"]: + return None return doc -def flag_machines(doc): - """Flag events which are created by machines. +def flag_machines(doc, exclude=False): + """Flag and filter events which are created by machines. The list of machines is defined by the `COUNTER-robots Python package `_ , which follows the @@ -114,6 +116,8 @@ def flag_machines(doc): """ doc["is_machine"] = "user_agent" in doc and is_machine(doc["user_agent"]) + if exclude and doc["is_machine"]: + return None return doc