From e06d7f926833d6fba19e57cb2211696e0bdbc6ad Mon Sep 17 00:00:00 2001 From: user Date: Sat, 23 Mar 2024 18:52:37 +0100 Subject: add login attempts chart --- src/db_handler.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/db_handler.py') diff --git a/src/db_handler.py b/src/db_handler.py index 7766da1..d607aee 100644 --- a/src/db_handler.py +++ b/src/db_handler.py @@ -54,3 +54,18 @@ LIMIT 1; password = cur.fetchone()['password'] return password + + +def get_histogram() -> str: + with psycopg.connect(**db_con_params, row_factory=psycopg.rows.dict_row) as conn: + with conn.cursor() as cur: + cur.execute(""" +SELECT count(id) as total_count, date_trunc('hour', timestamp) as date +FROM login_attempt +GROUP BY date_trunc('hour', timestamp) +ORDER BY date_trunc('hour', timestamp) +LIMIT 48 +; + """) + histogram = cur.fetchall() + return histogram -- cgit v1.2.3