From 0a3b0a01f704b519bc44e6ca33ba5b833ff93244 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 23 Mar 2024 22:58:48 +0100 Subject: fix chart --- src/db_handler.py | 3 +-- src/ssh_node5_net.py | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/db_handler.py b/src/db_handler.py index 033b11a..1c271d6 100644 --- a/src/db_handler.py +++ b/src/db_handler.py @@ -64,8 +64,7 @@ SELECT count(la.id) as total_count, date_trunc('hour', la.timestamp) as date, cn FROM login_attempt la JOIN connection cn on cn.id = la.connection GROUP BY date_trunc('hour', la.timestamp), cn.ip -ORDER BY date_trunc('hour', la.timestamp) DESC -LIMIT 48; +ORDER BY date_trunc('hour', la.timestamp) DESC; ; """) histogram = cur.fetchall() diff --git a/src/ssh_node5_net.py b/src/ssh_node5_net.py index d2c38c9..57754e4 100644 --- a/src/ssh_node5_net.py +++ b/src/ssh_node5_net.py @@ -66,11 +66,10 @@ def index(): histogram = db_handler.get_histogram_detailed() all_dates = sorted(list({d['date'] for d in histogram})) by_ip = {} - for d in histogram: - if d['ip'] not in by_ip: - by_ip[d['ip']] = list(range(len(all_dates))) - for date in all_dates: - by_ip[d['ip']][all_dates.index(d['date'])] = (d['total_count'] if date == d['date'] else 0) + for data in histogram: + if data['ip'] not in by_ip: + by_ip[data['ip']] = [0] * len(all_dates) + by_ip[data['ip']][all_dates.index(data['date'])] = data['total_count'] histogram_chartjs = json.dumps([{ 'label': str(ip), -- cgit v1.2.3