update analytics
This commit is contained in:
parent
0e50f519ff
commit
86daea355f
15
analytics.py
15
analytics.py
@ -185,11 +185,22 @@ def dashboard():
|
|||||||
|
|
||||||
# Initialize GeoIP2 reader once for efficiency
|
# Initialize GeoIP2 reader once for efficiency
|
||||||
reader = geoip2.database.Reader('GeoLite2-City.mmdb')
|
reader = geoip2.database.Reader('GeoLite2-City.mmdb')
|
||||||
location_data = []
|
location_data = {}
|
||||||
for ip, count in ip_rows:
|
for ip, count in ip_rows:
|
||||||
country, city = lookup_location(ip, reader)
|
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()
|
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
|
# Sort by count in descending order and take the top 20
|
||||||
location_data.sort(key=lambda x: x['count'], reverse=True)
|
location_data.sort(key=lambda x: x['count'], reverse=True)
|
||||||
location_data = location_data[:20]
|
location_data = location_data[:20]
|
||||||
|
|||||||
9
app.py
9
app.py
@ -324,10 +324,10 @@ def query_recent_connections():
|
|||||||
rows = a.return_file_access()
|
rows = a.return_file_access()
|
||||||
connections = [
|
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],
|
'ip_address': row[2],
|
||||||
'user_agent': row[3],
|
'user_agent': row[3]
|
||||||
'referrer': row[4]
|
|
||||||
}
|
}
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
@ -365,8 +365,7 @@ def handle_request_initial_data():
|
|||||||
'timestamp': row[0],
|
'timestamp': row[0],
|
||||||
'full_path': row[1],
|
'full_path': row[1],
|
||||||
'ip_address': row[2],
|
'ip_address': row[2],
|
||||||
'user_agent': row[3],
|
'user_agent': row[3]
|
||||||
'referrer': row[4]
|
|
||||||
}
|
}
|
||||||
for row in rows
|
for row in rows
|
||||||
]
|
]
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<h1 class="mb-4">Downloads in den letzten 10 Minute</h1>
|
<h1 class="mb-4">Initiale downloads in den letzten 10 Minute</h1>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<a href="{{ url_for('index') }}" class="btn btn-primary">App</a>
|
<a href="{{ url_for('index') }}" class="btn btn-primary">App</a>
|
||||||
<a href="{{ url_for('mylinks') }}" class="btn btn-primary">Meine Links</a>
|
<a href="{{ url_for('mylinks') }}" class="btn btn-primary">Meine Links</a>
|
||||||
@ -40,7 +40,7 @@
|
|||||||
<th>Timestamp</th>
|
<th>Timestamp</th>
|
||||||
<th>IP Address</th>
|
<th>IP Address</th>
|
||||||
<th>User Agent</th>
|
<th>User Agent</th>
|
||||||
<th>Referrer</th>
|
<th>File Path</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="connectionsTableBody">
|
<tbody id="connectionsTableBody">
|
||||||
@ -70,7 +70,7 @@
|
|||||||
<td>${record.timestamp}</td>
|
<td>${record.timestamp}</td>
|
||||||
<td>${record.ip_address}</td>
|
<td>${record.ip_address}</td>
|
||||||
<td>${record.user_agent}</td>
|
<td>${record.user_agent}</td>
|
||||||
<td>${record.referrer}</td>
|
<td>${record.full_path}</td>
|
||||||
`;
|
`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user