diff --git a/analytics.py b/analytics.py index 63408af..8835ff9 100644 --- a/analytics.py +++ b/analytics.py @@ -185,11 +185,22 @@ def dashboard(): # Initialize GeoIP2 reader once for efficiency reader = geoip2.database.Reader('GeoLite2-City.mmdb') - location_data = [] + location_data = {} for ip, count in ip_rows: country, city = lookup_location(ip, reader) - location_data.append(dict(count=count, country=country, city=city)) + key = (country, city) + if key in location_data: + location_data[key] += count + else: + location_data[key] = count reader.close() + + # Convert the dictionary to a list of dictionaries + location_data = [ + dict(country=key[0], city=key[1], count=value) + for key, value in location_data.items() + ] + # Sort by count in descending order and take the top 20 location_data.sort(key=lambda x: x['count'], reverse=True) location_data = location_data[:20] diff --git a/app.py b/app.py index 5f41507..f7fba05 100755 --- a/app.py +++ b/app.py @@ -324,10 +324,10 @@ def query_recent_connections(): rows = a.return_file_access() connections = [ { - 'timestamp': row[0], + 'timestamp': datetime.strptime(row[0], '%Y-%m-%dT%H:%M:%S.%f').strftime('%d.%m.%Y %H:%M:%S'), + 'full_path': row[1], 'ip_address': row[2], - 'user_agent': row[3], - 'referrer': row[4] + 'user_agent': row[3] } for row in rows ] @@ -365,8 +365,7 @@ def handle_request_initial_data(): 'timestamp': row[0], 'full_path': row[1], 'ip_address': row[2], - 'user_agent': row[3], - 'referrer': row[4] + 'user_agent': row[3] } for row in rows ] diff --git a/templates/connections.html b/templates/connections.html index 488273c..9c3a016 100644 --- a/templates/connections.html +++ b/templates/connections.html @@ -26,7 +26,7 @@
-

Downloads in den letzten 10 Minute

+

Initiale downloads in den letzten 10 Minute

App Meine Links @@ -40,7 +40,7 @@ Timestamp IP Address User Agent - Referrer + File Path @@ -70,7 +70,7 @@ ${record.timestamp} ${record.ip_address} ${record.user_agent} - ${record.referrer} + ${record.full_path} `; tbody.appendChild(row); });