waze-logs 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- analysis.py +91 -0
- cli.py +1219 -0
- collector.py +193 -0
- collector_europe.py +312 -0
- collector_worldwide.py +532 -0
- database.py +176 -0
- waze_client.py +234 -0
- waze_logs-1.0.0.dist-info/METADATA +411 -0
- waze_logs-1.0.0.dist-info/RECORD +15 -0
- waze_logs-1.0.0.dist-info/WHEEL +5 -0
- waze_logs-1.0.0.dist-info/entry_points.txt +2 -0
- waze_logs-1.0.0.dist-info/licenses/LICENSE +21 -0
- waze_logs-1.0.0.dist-info/top_level.txt +8 -0
- web/app.py +536 -0
- web/templates/index.html +1241 -0
analysis.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# analysis.py
|
|
2
|
+
from typing import Dict, Any, List, Optional
|
|
3
|
+
from database import Database
|
|
4
|
+
|
|
5
|
+
def get_stats(db: Database) -> Dict[str, Any]:
|
|
6
|
+
"""Get summary statistics from the database."""
|
|
7
|
+
total = db.execute("SELECT COUNT(*) FROM events").fetchone()[0]
|
|
8
|
+
unique_users = db.execute("SELECT COUNT(DISTINCT username) FROM events").fetchone()[0]
|
|
9
|
+
|
|
10
|
+
# By type
|
|
11
|
+
type_rows = db.execute(
|
|
12
|
+
"SELECT report_type, COUNT(*) as count FROM events GROUP BY report_type"
|
|
13
|
+
).fetchall()
|
|
14
|
+
by_type = {row["report_type"]: row["count"] for row in type_rows}
|
|
15
|
+
|
|
16
|
+
# Time range
|
|
17
|
+
time_range = db.execute(
|
|
18
|
+
"SELECT MIN(timestamp_utc) as first, MAX(timestamp_utc) as last FROM events"
|
|
19
|
+
).fetchone()
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
"total_events": total,
|
|
23
|
+
"unique_users": unique_users,
|
|
24
|
+
"by_type": by_type,
|
|
25
|
+
"first_event": time_range["first"],
|
|
26
|
+
"last_event": time_range["last"]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def get_recent_events(db: Database, limit: int = 20) -> List[Dict[str, Any]]:
|
|
30
|
+
"""Get most recent events."""
|
|
31
|
+
rows = db.execute(
|
|
32
|
+
"SELECT * FROM events ORDER BY timestamp_ms DESC LIMIT ?",
|
|
33
|
+
(limit,)
|
|
34
|
+
).fetchall()
|
|
35
|
+
return [dict(row) for row in rows]
|
|
36
|
+
|
|
37
|
+
def get_user_events(db: Database, username: str) -> List[Dict[str, Any]]:
|
|
38
|
+
"""Get all events from a specific user."""
|
|
39
|
+
rows = db.execute(
|
|
40
|
+
"SELECT * FROM events WHERE username = ? ORDER BY timestamp_ms",
|
|
41
|
+
(username,)
|
|
42
|
+
).fetchall()
|
|
43
|
+
return [dict(row) for row in rows]
|
|
44
|
+
|
|
45
|
+
def get_users_summary(db: Database, limit: int = 50) -> List[Dict[str, Any]]:
|
|
46
|
+
"""Get summary of users with event counts."""
|
|
47
|
+
rows = db.execute("""
|
|
48
|
+
SELECT
|
|
49
|
+
username,
|
|
50
|
+
COUNT(*) as event_count,
|
|
51
|
+
MIN(timestamp_utc) as first_seen,
|
|
52
|
+
MAX(timestamp_utc) as last_seen
|
|
53
|
+
FROM events
|
|
54
|
+
GROUP BY username
|
|
55
|
+
ORDER BY event_count DESC
|
|
56
|
+
LIMIT ?
|
|
57
|
+
""", (limit,)).fetchall()
|
|
58
|
+
return [dict(row) for row in rows]
|
|
59
|
+
|
|
60
|
+
def get_user_profile(db: Database, username: str) -> Optional[Dict[str, Any]]:
|
|
61
|
+
"""Get detailed profile for a user."""
|
|
62
|
+
events = get_user_events(db, username)
|
|
63
|
+
if not events:
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
# Basic stats
|
|
67
|
+
event_count = len(events)
|
|
68
|
+
first_seen = events[0]["timestamp_utc"]
|
|
69
|
+
last_seen = events[-1]["timestamp_utc"]
|
|
70
|
+
|
|
71
|
+
# Type breakdown
|
|
72
|
+
type_counts = {}
|
|
73
|
+
for e in events:
|
|
74
|
+
t = e["report_type"]
|
|
75
|
+
type_counts[t] = type_counts.get(t, 0) + 1
|
|
76
|
+
|
|
77
|
+
# Location analysis (simple centroid)
|
|
78
|
+
lats = [e["latitude"] for e in events]
|
|
79
|
+
lons = [e["longitude"] for e in events]
|
|
80
|
+
center_lat = sum(lats) / len(lats)
|
|
81
|
+
center_lon = sum(lons) / len(lons)
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
"username": username,
|
|
85
|
+
"event_count": event_count,
|
|
86
|
+
"first_seen": first_seen,
|
|
87
|
+
"last_seen": last_seen,
|
|
88
|
+
"type_breakdown": type_counts,
|
|
89
|
+
"center_location": {"lat": center_lat, "lon": center_lon},
|
|
90
|
+
"events": events
|
|
91
|
+
}
|