From 180bae3a1b5b9c1f4f91e7e1d8112ab7873e7d02 Mon Sep 17 00:00:00 2001 From: "Matthias@Dell" Date: Thu, 18 May 2023 10:59:18 +0200 Subject: [PATCH] fixed request count statement --- regina/data_visualization/history.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/regina/data_visualization/history.py b/regina/data_visualization/history.py index 414540d..223f799 100644 --- a/regina/data_visualization/history.py +++ b/regina/data_visualization/history.py @@ -12,10 +12,19 @@ def get_visitor_count_between(db: Database, timestamps: tuple[int, int], only_hu {'AND v.is_human = 1' if only_human else ''}""")[0][0] def get_request_count_between(db: Database, timestamps: tuple[int, int], only_human=False): - return db(f"""SELECT COUNT(r.request_id) - FROM request AS r, visitor AS v - WHERE r.time BETWEEN {timestamps[0]} AND {timestamps[1]} - {'AND v.is_human = 1' if only_human else ''}""")[0][0] + if only_human: + return db(f"""SELECT COUNT(r.request_id) + FROM request AS r + JOIN ( + SELECT visitor_id + FROM visitor + {'WHERE is_human = 1' if only_human else ''} + ) AS v ON v.visitor_id = r.visitor_id + WHERE r.time BETWEEN {timestamps[0]} AND {timestamps[1]}""")[0][0] + else: + return db(f"""SELECT COUNT(*) + FROM request + WHERE time BETWEEN {timestamps[0]} AND {timestamps[1]}""")[0][0] def get_new_visitor_count_between(db: Database, timestamps: tuple[int, int]):